且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Eigen和std :: vector

更新时间:2023-11-26 13:44:16

Eigen使用连续内存, std :: vector 然而,外部 std :: vector 包含 std :: vector< std :: complex< double> > ,每个都指向一组不同的复数(并且可以是不同的长度)。因此,std矩阵不是连续的。你可以做的是将数据复制到Eigen矩阵,有多种方法。最简单的是循环 i j ,更好的选项是

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);