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

Alter arrays of SparseMatrix

Tags: None
(comma "," separated)
janjansen
Registered Member
Posts
1
Karma
0

Alter arrays of SparseMatrix

Wed Jun 05, 2013 3:29 pm
In my code it would be incredibly useful if I could just alter the arrays of the SparseMatrix class, to do so I use valuePtr, innerIndexPtr and outerIndexPtr. Let's say I remove a row or column from the matrix, or complete change the pattern. How can I let the SparseMatrix class update itself such that all member variables are set correctly and all member functions (rows, cols, etc.) return correct results? I don't mind changing the header files here and there if that's absolutely necessary.

My best alternative is to use the MappedSparseMatrix class, but I'd rather have Eigen handle the associated memory.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Alter arrays of SparseMatrix

Wed Jun 05, 2013 11:20 pm
use .resizeNonZeros() to resize the values and innerIndex arrays, then you can use these *Ptr() functions to adjust the content of these arrays, and at the end you can call .conservativeResize() to set the final rows and cols values without loosing your modifications. Make sure it is in compressed mode before starting such cooking, or also consider updating the content of innerSizePtr() in uncompressed mode.
Slaedr
Registered Member
Posts
2
Karma
0

Re: Alter arrays of SparseMatrix

Fri Feb 26, 2016 12:46 am
I am trying to initialize a Eigen::SparseMatrix A by using malloc like this
Code: Select all
A.valuePtr() = static_cast<T*>(std::malloc(nnz*sizeof(T)));
A.innerIndexPtr() = static_cast<int*>(std::malloc(nnz*sizeof(int)));

but I get the error
Code: Select all
error: lvalue required as left operand of assignment

for both statements.

Can anyone help me with this?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Slaedr
Registered Member
Posts
2
Karma
0

Re: Alter arrays of SparseMatrix

Thu Mar 03, 2016 10:08 pm
Yep, I was the one who asked that, thanks. I used MappedSparseMatrix ultimately, and managed to get it to work; I'm quite happy with the results.


Bookmarks



Who is online

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