New user self-registration is currently disabled. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 1238 - SparseMatrix::sum incorrect
SparseMatrix::sum incorrect
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Sparse
3.2
x86 - 64-bit Linux
: Normal Wrong Result
Assigned To: Nobody
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-05-30 20:35 UTC by Matt Shannon
Modified: 2016-05-31 09:00 UTC (History)
2 users (show)



Attachments

Description Matt Shannon 2016-05-30 20:35:43 UTC
The specialized sum routine used by SparseMatrix is incorrect, and appears to access uninitialized values. To reproduce:

int main() {
  for (int i = 0; i < 100; ++i) {
    Eigen::SparseMatrix<float> mat(10, 10);
    mat.coeffRef(0, 2) = 1.0;
    mat.coeffRef(2, 3) = 1.0;
    mat.coeffRef(9, 9) = 1.0;
    if (mat.sum() != 3) {
      return 1;
    }
  }
  return 0;
}

You may need to increase the upper loop limit to reproduce. If I remove SparseMatrix::sum (which a comment states is "Overloaded for performance") and use the implementation from SparseMatrixBase::sum instead then everything works fine.
Comment 1 Gael Guennebaud 2016-05-31 08:47:40 UTC
indeed, the overload has been written before SparseMatrix supported the "un-compressed" mode.

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