I am using Eigen::SPQR
module to solve a least-squares problem Ax = b
, and I am getting an error complaining about rows mismatch at the solve step. In general my code consists of initializing A using triplets, b using bracket operators and then computing QR decomposition and finally solving.
Eigen::SparseMatrix<double> A;
// Fill A using triplets
Eigen::VectorXd b(A.rows());
// Fill b using square bracket operator b[i] = ...
Eigen::SPQR< Eigen::SparseMatrix < double > > QR(A);
Eigen::VectorXd X = QR.solve(b); // Line giving error.
Vector b was created with size equal to A.rows()
so I am sure it is correct. However, when I check the function QR.rows()
it returns the value of A.cols()
. Is this some kind of bug? I checked that Eigen::SparseQR
solves it without errors but it is a lot slower, so I would like to use the SuiteSparse
module instead. Any ideas?