New user self-registration is currently disabled. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 1423 - LeastSquaresConjugateGradient does handle row-major sparse matrices properly
LeastSquaresConjugateGradient does handle row-major sparse matrices properly
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Sparse
3.3 (current stable)
All All
: Normal Crash
Assigned To: Nobody
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2017-04-25 22:52 UTC by Bailin Deng
Modified: 2017-06-08 13:07 UTC (History)
2 users (show)



Attachments
Codes that reproduce the error. (1.43 KB, text/x-csrc)
2017-04-25 22:52 UTC, Bailin Deng
no flags Details

Description Bailin Deng 2017-04-25 22:52:50 UTC
Created attachment 786 [details]
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.
Comment 1 Gael Guennebaud 2017-06-08 13:07:22 UTC
Thank you for the report, fixed:

https://bitbucket.org/eigen/eigen/commits/45a5c5dde931/ (devel)
https://bitbucket.org/eigen/eigen/commits/9688211a9ef2/ (3.3)

Note You need to log in before you can comment on or make changes to this bug.