This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Creating a matrix with empty column using insertBack

Tags: None
(comma "," separated)
igorp
Registered Member
Posts
2
Karma
0
Hello,

I encountered a weird behaviour when insertBack() is used to create a matrix with empty column. To make it easy to explain, suppose I would like to create a matrix:
1 0 0
0 0 0
0 0 1

I've implemented:
Eigen::SparseMatrix<Real,Eigen::RowMajor> M;
M.startVec(0);
M.insertBack(0,0) = 1.0;
M.startVec(2);
M.insertBack(2,2) = 1.0;
M.finalize();
cout << M;

and got:
1 0 0
0 0 0
1 0 0

Printing out the vectors (innerIndices,values) and outerIndices respectively, I get:
(0,1) (2,0) (0,0)
0 1 0

Creating the same matrix from triplets or using insert(i,j): I get the correct matrix:
1 0 0
0 0 0
0 0 1
and printing the internal structures gives me:
(0,1) (2,1) (1,0)
0 1 1

Do you think there is a problem with insertBack or it just can't be used with matrices having an empty column?

Thanks a lot

Igor
igorp
Registered Member
Posts
2
Karma
0
The solution is to add insertBack also for the row with no elements:

Eigen::SparseMatrix<Real,Eigen::RowMajor> M;
M.startVec(0);
M.insertBack(0,0) = 1.0;
M.startVec(1);
M.startVec(2);
M.insertBack(2,2) = 1.0;
M.finalize();

Sorry for bothering you guys...


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]