Inner Iterator Incorrect for Row Major Sparse Matrices
Submitted by PCAdkins
Assigned to Nobody
Link to original bugzilla bug (#718)
Version: 3.2
Description
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 <iostream>
#include <Eigen/Dense>
#include <Eigen/Sparse>
using namespace Eigen;
using namespace std;
int main()
{
SparseMatrix<float,RowMajor> A(5,5);
A.insert(0,0)=1;
for (int k = 0; k<A.outerSize(); ++k)
for (SparseMatrix<float>::InnerIterator it(A,k); it; ++it)
std::cout<<it.value()<<std::endl;
SparseMatrix<float,ColMajor> B(5,5);
B.insert(0,0)=1;
for (int k = 0; k<B.outerSize(); ++k)
for (SparseMatrix<float>::InnerIterator it(B,k); it; ++it)
std::cout<<it.value()<<std::endl;
}