New user self-registration is disabled due to spam. Please email eigen-core-team @ if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 1238 - SparseMatrix::sum incorrect
Summary: SparseMatrix::sum incorrect
Alias: None
Product: Eigen
Classification: Unclassified
Component: Sparse (show other bugs)
Version: 3.2
Hardware: x86 - 64-bit Linux
: Normal Wrong Result
Assignee: Nobody
Depends on:
Reported: 2016-05-30 20:35 UTC by Matt Shannon
Modified: 2016-05-31 09:00 UTC (History)
2 users (show)


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.