Sapiens
Sapiens

Reputation: 1901

Cast Eigen::MatrixXd to Eigen::MatrixXf

I am using Eigen on a C++ program.

I wonder if there is a way to cast from Eigen::MatrixXd to Eigen::MatrixXf.
static_cast <Eigen::MatrixXf> doesn't seem to work and neither A.cast<MatrixXf> (this is the cast method from Eigen).

Any solution for this type of cast?

Upvotes: 63

Views: 63120

Answers (1)

Gluttton
Gluttton

Reputation: 5958

Try this:

Eigen::MatrixXd d;                       // Matrix of doubles.
Eigen::MatrixXf f = d.cast <float> ();   // Matrix of floats.

Upvotes: 108

Related Questions