Cast Eigen::MatrixXd to Eigen::MatrixXf

C++

C++ Problem Overview


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?

C++ Solutions


Solution 1 - C++

Try this:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSapiensView Question on Stackoverflow
Solution 1 - C++GlutttonView Answer on Stackoverflow