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

How to get reserved size of a sparse matrix ? (nzmax)

Tags: None
(comma "," separated)
nelsons
Registered Member
Posts
23
Karma
0
in octave, I can do:

I = [1 2 3];
J = [3 1 2];
V = [32 42 53];
sp = sparse(I, J, V, 5, 4, 10)
size(sp)
nnz(sp) returns 3
nzmax(sp) returns 10

With Eigen, I can use 'reserve' but how to get this value after ?
I found a method allocatedSize() but how to have access to this method ?

Eigen::SparseMatrix<double, 0, signedIndexType> *spmat = ...
spmat->reserve(10)

How to get reserved value ?


Thanks
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
It's undocumented, but you can do:

Code: Select all
spmat.data().allocatedSize()
nelsons
Registered Member
Posts
23
Karma
0
Exposed code:
I = [1 2 3];
J = [3 1 2];
V = [32 42 53];
sp = sparse(I, J, V, 5, 4, 10)
size(sp)
nnz(sp)
nzmax(sp)

spmat allocated with :
Eigen::SparseMatrix<T, 0, signedIndexType> *spmat = nullptr;
spmat = new Eigen::SparseMatrix<T, 0, signedIndexType>(maxrow, maxcol);
spmat ->conservativeResize(maxrow, maxcol);
spmat ->finalize();
spmat ->makeCompressed();

after:

int nnz = 10;
spmat->reserve(nnz);
spmat->finalize();
spmat->makeCompressed();
int nzmax = spmat->data().allocatedSize();

nzmax equals to 13 and not 10 as expected.

"How to get 10 ?"

I modified my code as:

spmat->reserve(nnz);
spmat->finalize();
spmat->makeCompressed();
spmat->data().squeeze()


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]