Eigen and std::vector

前端 未结 1 889
忘掉有多难
忘掉有多难 2020-11-27 08:27

I have a matrix, which is given as:

std::vector>> A;

And I want to map that to the Eigen

相关标签:
1条回答
  • 2020-11-27 09:02

    Eigen uses contiguous memory, as does std::vector. However, the outer std::vector contains a contiguous set of std::vector<std::complex<double> >, each pointing to a different set of complex numbers (and can be different lengths). Therefore, the std "matrix" is not contiguous. What you can do is copy the data to the Eigen matrix, there are multiple ways of doing that. The simplest would be to loop over i and j, with a better option being something like

    Eigen::MatrixXcd mat(rows, cols);
    for(int i = 0; i < cols; i++)
        mat.col(i) = Eigen::Map<Eigen::VectorXcd> (A[i].data(), rows);
    
    0 讨论(0)
提交回复
热议问题