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

Squaring a sparse matrix in Eigen

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

Squaring a sparse matrix in Eigen

Mon Nov 24, 2014 12:20 pm
I have an Eigen square matrix defined as follows:

Code: Select all
Eigen::SparseMatrix<float> SpMat;
SpMat m(a, a);
...
Code to fill the matrix.


Now, I want to compute the square of the matrix. In Matlab speak this could be done with
Code: Select all
sparse_mat^2


In Eigen, I guess I can do something like:

Code: Select all
SpMat squared = m * m;


My question is whether this is the preferred way to do it and more importantly, would the resulting matrix also be sparse and if the full dense matrix is stored somewhere along the way?

Many thanks,
Luca
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Yes, doing SpMat squared = m * m; is the best way. The result will still be sparse (usually a bit less) and of course the sparsity of m will be exploited. No dense matrix will be created along the way.
pamparana
Registered Member
Posts
18
Karma
0
Thank you so much. I was using pruned() but it seemed that was really making it worst.


Bookmarks



Who is online

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