For 1D resizing, the Eigen documentation suggests I use the following method to resize an array:
using Eigen;
MatrixXf X(2,2) << 1,2,3,4;
Map<RowVectorXf> v1(X.data(), X.size());
Except I have a templated vector, and can't use RowVectorXf
using Eigen;
template<class num>
void my_func(){
Matrix<num,Dynamic,Dynamic> X(2,2) << 1,2,3,4;
Map<Matrix<num,Dynamic,Dynamic>> unraveled(X.data(),X.size());
}
The example above fails with the following message:
error: static assertion faild: YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX
How do I obtain a flat view of an eigen matrix in a templated function?
The issue is that the Map is 2D and not 1D as you really want:
Map<Matrix<num,Dynamic,1>> unraveled(X.data(),X.size());
Then now it's a vector operation on your original X matrix.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.