Registered Member
|
Hello there,
I was wandering what is the fasted way to fill a sparse matrix in eigen v3.1. At the moment I am using what I believe to be the easiest way and not particularly the fasted, using insert():
This almost takes 2 minutes to fill. Is there a faster way of doing this? For example is there a way to access and set directly the internal elements of the sparse matrix representation such as the values vector or inner/outer indices. To be more clear,in Matlab it is possible to construct a sparse matrix by specifying 3 vector-arrays(values,column-indices,row-indices) and this takes less than a second. Many Thanks |
Registered Member
|
It's faster if you can call reserve() with a good estimate of the number of non-zero entries per row, see the tutorial at http://eigen.tuxfamily.org/dox-devel/Tu ... rseFilling and the documentation of reserve() at http://eigen.tuxfamily.org/dox-devel/cl ... 38c6bd67d4 . I think the class MappedSparseMatrix allows you to construct a sparse matrix from three arrays, but I'm not sure; the (sparse) documentation is at http://eigen.tuxfamily.org/dox-devel/cl ... atrix.html .
|
Registered Member
|
Thanks for your reply,
Calling reserve does not seem to make any difference but I"ll take a look at the MappedSparseMatrix class. From a first glance it seems to be exactly what I am looking for. Cheers |
Registered Member
|
Having tested the reserve function it really seems to make a difference. The problem was that I had miscalculated the estimated nonzero terms. It takes 2 milliseconds now:D
Thanks |
Registered Member
|
Hi there,
lliman, would it be possible to let me know how you solved the problem? would it be possible to pass me the sample code using reserve? I would be grateful. the bests. |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]