GoingMyWay
GoingMyWay

Reputation: 17468

How to define a VectorXd array in Eigen

I want to define a VectorXd array in Eigen, the following are my code

void function(VectorXd * b, ...)
{
    [snippet]
    vector<VectorXd(b->rows())> xs(max_iter+1);
    [snippet]
}

So, I want to define an array whose length is max_iter+1 and every element in the array is a 3X1 VectorXd.

But when it was compiled, it returned the following error:

/path/to/solutions.h:187: error: invalid type in declaration before '(' token
     vector<VectorXd(b->rows())> xs(max_iter+1);
                                  ^
/path/to/solutions.h:187: error: 'b' cannot appear in a constant-expression
     vector<VectorXd(b->rows())> xs(max_iter+1);
                     ^

What shoud I do to fix these bugs? Thank you!

Upvotes: 2

Views: 1201

Answers (1)

kangshiyin
kangshiyin

Reputation: 9781

When you work on std::vector of int, you use

std::vector<int> xs(size, init_value);

Similarly, it should be something like this when you work on std::vector of VectorXd.

std::vector<VectorXd> xs(max_iter+1, VectorXd(b->rows()));

It has to be a type name between < >, but you use an object VectorXd(b->rows()).

Upvotes: 2

Related Questions