Registered Member
|
Hi,
I have asked a similar question two months ago in this forum, but I didn't exactly understand the answer...so here is a bit easier formulation: I construct my symmetric SparseMatrix row-by-row (col-by-col) basically in the following way:
Is this the right way to insert these vectors into my matrix? Does it go more efficiently? Does one also have direct access to the Matrix' underlying data, so that I could avoid the copy step? Thanks in advance, David |
Registered Member
|
push
its really important for me, and according to my tests, it is the insertion step in the above code snippet that slows it down drastically. what is the right way to do it? best, David |
Registered Member
|
You can speed your code up by calling reserve(). See the section "Filling a sparse matrix" of the tutorial at http://eigen.tuxfamily.org/dox-devel/Tu ... parse.html .
As I understand it, you can access the data with M.innerIndexPtr(), M.innerNonZeroPtr(), M.outerIndexPtr() and M.valuePtr(). These point to the arrays mentioned in the section "Sparse matrix representation" in the same tutorial page. |
Registered Member
|
Thank you for the answer.
I already knew from the tutorial that I should call reserve(). The problem is that I have only a single vector at a time and no idea about the nonzeros of any later vectors. So, can I call reserve for each row/column anew? Maybe starting with a vector that contains only the size of the first row/column and else only zeros, then with this vector where the second zero is replaced by the size of the second row/column, then with the same vector where the third zero is replaced by the size of the third row/column and so on? Best, David |
Moderator
|
cannot you have an upper bound on the nnz per column or rows ?
Another solution would be to use a RowMajor matrix, and use a non documented insertion procedure: for(int j...) { M.startVec(j); for(i) M.insertBack(j,i) = val; } M.finalize(); until we add the possibility to fill a matrix from a raw list of triplet (i,j,val)... |
Registered Member
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]