c++eigensvdbad-alloc

Bad alloc exception thrown when using SVD from Eigen library


In my application, I want to obtain the left singular vectors from a given data matrix with double entries, which is given in the code as

Eigen::MatrixXd m;

and has dimensions 45 x 904140. Now I use the constructor for the SVD decomposition in the Eigen library as below

Eigen::BDCSVD<Eigen::MatrixXd> svd(m, Eigen::ComputeFullU | Eigen::ComputeFullV);

and there, a bad alloc exception is thrown, more precisely:

Unhandled exception at 0x00007FFA058850D8: Microsoft C++ exception: std::bad_alloc at memory location

Solution

  • The error std::bad_alloc usually means there is not enough memory to complete your task.

    You might not be able to compute the matrix that requires a 904140 x 904140 on your machine.