LeastSquaresConjugateGradient does handle row-major sparse matrices properly
Submitted by Bailin Deng
Assigned to Nobody
Link to original bugzilla bug (#1423)
Version: 3.3 (current stable)
Description
Created attachment 786
Codes that reproduce the error.
When using LeastSquaresConjugateGradient for row-major sparse matrices with more rows than columns, Eigen crashes at the following function in Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h:
LeastSquareDiagonalPreconditioner& factorize(const MatType& mat)
{
// Compute the inverse squared-norm of each column of mat
m_invdiag.resize(mat.cols());
for(Index j=0; j<mat.outerSize(); ++j)
{
RealScalar sum = mat.innerVector(j).squaredNorm();
if(sum>0)
m_invdiag(j) = RealScalar(1)/sum;
else
m_invdiag(j) = RealScalar(1);
}
Base::m_isInitialized = true;
return *this;
}
Here the dimension of m_invdiag is the number of columns, but mat.outerSize() is the number of rows, resulting in out-of-bound access of m_invdiag in the loop.
Attachment 786, "Codes that reproduce the error.":
LSCG.cpp