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

Free the memory taken by a sparse matrix

Tags: None
(comma "," separated)
eigenUser123
Registered Member
Posts
10
Karma
0
Hello,
Is it possible to free the memory used by a sparse matrix without erasing the object itself ?
I tried to resize the matrix to a small size, but the memory used is still the same as if it was very big.

I have a second question: I have a weird bug when filling a list of triplet to build a sparse matrix. I checked that my triplet has good row and column number, as well as the value of the entry. But the command tripletList.push back makes the program to crash. Any thoughts on what I did wrong ?

EDIT: the program crash when the list reaches a fixed number of around 17 000 000. I don't understand. I tried to create a bigger list outside of my main program and it worked fine. I am guessing a memory bug, though I have plenty of memory left.
EDIT2: I found something that seems to solve the memory problem, I use tripletList.reserve(N) which allows space for N triplets. Since I know N in advance, it seems to work just fine.
EDIT3: I know, too many edits. I looked at the SparseMatrix.h file, in the resize function. You use m_data.clear(). This seems to erase data but not free the memory allocated. Then I looked at CompressedStorage.h. The function MySparseMatrix.data().resize(N) does reallocate memory but only if N is larger than the current size. So it seems currently there is no way to free the space used by a sparse matrix without removing it. The only way would be to modify the aforementioned function, but I don't want to do it myself since I have no idea what it could do later.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Sorry for late reply, mat.data().squeeze() will do the job (after a mat.resize(0,0) of a mat.setZero()).

(https://bitbucket.org/eigen/eigen/commits/3a2f0bd530f7/)


Bookmarks



Who is online

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