Reply to topic

Creating a matrix with empty column using insertBack

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...

 
Reply to topic

Bookmarks



Who is online

Registered users: ab4bd, Baidu [Spider], BeS, Bing [Bot], Exabot [Bot], GeekQuack, ggael, ghevan, Google [Bot], google01103, igorm, jensreuterberg, kainz.a, maarten, mmistretta, Nuc!eoN, orbmiser, plfiorini, scummos, searchfgold6789, SecretCode, Steve T, TheraHedwig, Uri_Herrera, vblazquez, Yahoo [Bot]