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

Matrix creation, re-use

Tags: None
(comma "," separated)
kmanuele
Registered Member
Posts
7
Karma
0

Matrix creation, re-use

Tue Nov 10, 2015 9:37 pm
very newbie questions:

We create a sparse matrix:

SparseMatrix<double> sm;

don't know the size until later, and it will change, so:

sm.resize(N,N); does this simply set the matrix dimensions, but no memory allocation?

then, assume we would have no more than 5 elements per column

sm.reserve(5*N); this is what allocates internal memory, right?

load the matrix with sm.setFromTriplets(...)

next, we use our matrix for some solutions, then we want to reuse the matrix with new values, so:

sm.resize(M,M); what does this do to the values already in the matrix, and the memory allocation?

do we need to reserve memory again, if it hasn't changed?
sm.reserve(5*N); same question -- what about existing values?

next, load the matrix with new values sm.setFromTriplets(...);

at this point, is it certain that the matrix contains only new values, and no old values?

thanks in advance for any responses

Kevin
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Matrix creation, re-use  Topic is solved

Wed Nov 11, 2015 8:12 pm
Currently, calling reserve before setFromTriplets is counter productive because setFromTriplets does it for you. And yes, setFromTriplets replace the entire content of the matrix. Same for resize(), which turns the matrix as an empty matrix.
kmanuele
Registered Member
Posts
7
Karma
0

Re: Matrix creation, re-use

Thu Nov 12, 2015 3:55 pm
great!

thanks

Kevin


Bookmarks



Who is online

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