This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Initialize VectorXd with better Kungfu than this?

Tags: None
(comma "," separated)
bravegag
Registered Member
Posts
52
Karma
0
Hello,

I have a class that takes in the constructor a VectorXd. An instance of this class is contained in another class i.e.
Code: Select all
class A {
public:
 A(const VectorXd&)
};
class B {
public:
 inline B() : a_(VectorXd::Zero(10)) { // <<<<<<< here I need to initialize a VectorXd to size 10 with value 0.2
   // too late here
 }
private:
 A a_;
};


How can I initialize the VectorXd in "one go" to a given size and constant value? the only way I have found is using the following Kungfu:
Code: Select all
 inline B() : a_(Eigen::Map<VectorXd>(&(std::vector<double>(10, 0.2))[0], 10)) {


Is there a simpler way?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
tip: search for the word "Constant" in the search tool bar of the documentation page: http://eigen.tuxfamily.org/dox/ (top-right corner)... ;)


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]