This bugzilla service is closed. All entries have been migrated to
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: 2019-12-04 15:53 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.
Comment 3 Nobody 2019-12-04 15:53:21 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

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