Eigen and std::vector

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

Leave a Comment