Copy data from std::vector to Eigen's MatrixXd in C++ -
eigen linear algebra library in c++. have data (double type) in std::vector (datavector in code below) type array. try copy row-wise using following code still giving results column-wise.
map<matrixxd, rowmajor> mymatrix(datavector.data(), m, n);
am doing correct syntax here?
no. matrixxd
object has defined row/column major. see example below.
#include <eigen/core> #include <iostream> #include <vector> using std::cout; using std::endl; int main(int argc, char *argv[]) { std::vector<int> dat(4); int = 0; dat[i] = + 1; i++; dat[i] = + 1; i++; dat[i] = + 1; i++; dat[i] = + 1; typedef eigen::matrix<int, -1, -1, eigen::colmajor> cm; eigen::map<cm> m1(dat.data(), 2, 2); cout << m1 << endl << endl; typedef eigen::matrix<int, -1, -1, eigen::rowmajor> rm; eigen::map<rm> m2(dat.data(), 2, 2); cout << m2 << endl << endl; return 0; }
outputs:
1 3 2 4 1 2 3 4
Comments
Post a Comment