This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 718 - Inner Iterator Incorrect for Row Major Sparse Matrices
Inner Iterator Incorrect for Row Major Sparse Matrices
 Status: RESOLVED FIXED None Eigen Unclassified Sparse (show other bugs) 3.2 All All Normal major Nobody 3.3 Show dependency tree / graph

 Reported: 2013-12-19 03:22 UTC by PCAdkins 2019-12-04 12:53 UTC (History) 2 users (show) chtz gael.guennebaud

Attachments

 PCAdkins 2013-12-19 03:22:39 UTC In the following code, I declare and initialize a 5x5 sparse matrix and set the (0,0) value to 1; matrix A is row major, matrix B is column major. I run over the outer index and through the inner iterator in each case identically. However, when I run the code - with matrix B, I get a "1" printed out - as expected; with matrix A I get an absurd number. I encountered this while trying to implement a mean calculation for a sparse matrix. Here's a bit of sample code to demonstrate the problem as discussed above. Yes, I know some of the header stuff is unnecessary; I just nabbed it from another demo I was working on: #include #include #include using namespace Eigen; using namespace std; int main() { SparseMatrix A(5,5); A.insert(0,0)=1; for (int k = 0; k::InnerIterator it(A,k); it; ++it) std::cout< B(5,5); B.insert(0,0)=1; for (int k = 0; k::InnerIterator it(B,k); it; ++it) std::cout< SparseMatrix A(5,5); > > A.insert(0,0)=1; > > for (int k = 0; k for (SparseMatrix::InnerIterator it(A,k); it; ++it) > std::cout<::InnerIterator. I guess what happens is that A is converted to a temporary ColMajor matrix which gets invalid before it.value() is called. We should catch that somehow, maybe by adding a constructor for invalid types which results in a static assertion. I assume things like the following won't work properly, either: typedef SparseMatrix Sparse; Sparse A, B; // initialize somehow Sparse::InnerIterator(A+B, 0); // Iterator to a temporary Gael Guennebaud 2014-10-20 14:08:00 UTC This has been fixed a few weeks ago for SparseMatrix: https://bitbucket.org/eigen/eigen/commits/afd3e37726ef and for SparseVector: https://bitbucket.org/eigen/eigen/commits/4a1386d13502/ Nobody 2019-12-04 12:53:26 UTC -- 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/718.

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