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.
indeed, the overload has been written before SparseMatrix supported the "un-compressed" mode.
Fixed: devel: https://bitbucket.org/eigen/eigen/commits/634dab7c40d0/ 3.2: https://bitbucket.org/eigen/eigen/commits/3eaa91e440bc/
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com'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: https://gitlab.com/libeigen/eigen/issues/1238.