typecasting Eigen::VectorXd to std::vector

Manish picture Manish · Sep 29, 2014 · Viewed 29.7k times · Source

Their are many links to go the other way round but I am unable to find to get a std::vector from a Eigen::Matrix or Eigen::VectorXd in my specific case.

Answer

ggael picture ggael · Sep 29, 2014

You cannot typecast, but you can easily copy the data:

VectorXd v1;
v1 = ...;
vector<double> v2;
v2.resize(v1.size());
VectorXd::Map(&v2[0], v1.size()) = v1;