I tried to iterate over nonzero elements of a row with a large sparse matrix, for example, as shown below:
Eigen::SparseMatrix<double,Eigen::RowMajor> Test(2, 3);
Test.insert(0, 1) = 34;
Test.insert(1, 2) = 56;
for (int k = 0; k < Test.outerSize(); ++k){
for (Eigen::SparseMatrix<double>::InnerIterator it(Test, k); it; ++it){
cout << it.row() <<"\t";
cout << it.col() << "\t";
cout << it.value() << endl;
}
}
but I do not see the correct values. Instead, I see random values for it.row (), a value of 1 for it.col (), and some random value for it.value (), as shown below:
-17891602 1 -2.65698e+303
Changing RowMajor to ColumnMajor makes the code work as expected.
I'm not sure what went wrong for the main part of the line? Can someone please let me know what I'm missing here?
Thanks in advance
source
share