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

Sparse matrix matrix best practices

Tags: None
(comma "," separated)
pamparana
Registered Member
Posts
18
Karma
0

Sparse matrix matrix best practices

Wed May 20, 2020 11:38 am
Currently, I am initializing a sparse matrix as follows:


Code: Select all
Eigen::SparseMatrix<float> A;
A.resize(pixels*3, pixels*3);



My question is that would this actually allocate the full memory (i.e. pixels * pixels * 9 elements)?

Now I have a scenario where I know before hand how many non-zero elements would be in the sparse matrix. In this case, should I be using `reserve` rather than `resize`?

Second, I am currently using `setFromTriplets` to fill the matrix as a batch but this also seems to be very memory intensive. if I want to reduce memory footprint, would using `insert(i,j)` after calling `reserve` or `resize` be a better idea?
jensw
Registered Member
Posts
8
Karma
0
Typically constructing the matrix from triplets is best.

From my reading of https://gitlab.com/libeigen/eigen/-/blo ... seMatrix.h your code does not allocate the whole matrix but just the column or row index (according to storage order) array.


Bookmarks



Who is online

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