My question is how to initialize an eigen Matrix, but NOT this way:
matrix << 1,0,1,0,
1,0,1,0,
1,0,1,0,
>
I used iterators to collect the data in a vector and then initialize the matrix. The conversion to the vector seem to be the time-consuming part of the method, which approximately has the same speed as the solutions above. Ideas on how to improve this would be interesting.
template
using Tmat = Eigen::Matrix;
Tmat txt_to_mat(std::string path, int rows, int cols)
{
std::ifstream fstr(path.c_str());
std::vector data_vec = std::vector{
std::istream_iterator(fstr),
std::istream_iterator()
};
Tmat mat(rows, cols);
for(int i=0; i