![]() Registered Member ![]()
|
Hello everyone,
I do have a strange problem concerning SparseMatrix Iterators. I declare a SparseMatrix as: Eigen::SparseMatrix<double, 1> Matrix = function_which_generates_matrix(); for(int k = 0; k < Matrix.outerSize(); k++) { for(Eigen::SparseMatrix<double>::InnerIterator it(Matrix,k); it; ++it) { std::cout << it.row() << "\t" << it.col() << std::endl; } } This returns something like: 0 0 1 0 2 0 etc. While I would have expected: 0 0 0 1 0 2 etc. or something similar. The strange thing is, this doesn't change at all when I change Eigen::SparseMatrix<double, 1> = function_which_generates_matrix(); to Eigen::SparseMatrix<double, 0> = function_which_generates_matrix(); or (and here I am not sure whether automatic conversion between storage schemes works in any way) Eigen::SparseMatrix<double, 0> = function_which_generates_matrix().transpose(); However Eigen::SparseMatrix<double, 0> = function_which_generates_matrix().transpose(); results in: 560912 0 0 0 -50243 0 etc. so this obviously points to some memory access problems. Do you have any ideas where these problems might come from? |
![]() Moderator ![]()
|
Look at this line:
for(Eigen::SparseMatrix<double>::InnerIterator it(Matrix,k); it; ++it) the SparseMatrix type does not match the type of 'Matrix', therefore 'Matrix' is copied into a column major matrix when passed to the iterator. |
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]