C++ 将自己的::MatrixXd 转换为自己的::MatrixXf
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24764031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cast Eigen::MatrixXd to Eigen::MatrixXf
提问by Sapiens
I am using Eigenon a C++ program.
我在 C++ 程序上使用Eigen。
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).
我想知道是否有办法从Eigen::MatrixXd
to投射Eigen::MatrixXf
。static_cast <Eigen::MatrixXf>
似乎不起作用,也不起作用A.cast<MatrixXf>
(这是 Eigen 的强制转换方法)。
Any solution for this type of cast?
这种类型的演员有什么解决方案吗?
回答by Gluttton
Try this:
尝试这个:
Eigen::MatrixXd d; // Matrix of doubles.
Eigen::MatrixXf f = d.cast <float> (); // Matrix of floats.