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

Eigen (3.1.0) Operations with SparseMatrix

Tags: None
(comma "," separated)
sgollamu
Registered Member
Posts
8
Karma
0
OS
I am an Eigen newbie, and am trying to play with sparse matrices and vectors. The following expression does not compile with Eigen 3.1.0: sv.dot(SM*sv), where sv is a sparse vector and SM is a sparse matrix.

I get the following error:
./Eigen/src/SparseCore/SparseDot.h:66: error: no type named ‘InnerIterator’ in ‘class Eigen::SparseSparseProduct<const Eigen::SparseMatrix<double, 0, int>&, const Eigen::SparseVector<double, 0, int>&>’

Can someone please let me know what went wrong? Also, SM is a self-adjoint matrix (fully specified). Is there a way to use this infromation for speed-up or better numerical accuracy of the result? The compiler does not like the use of selfadjointView<>() in this case.

Thanks!
sgollamu
Registered Member
Posts
8
Karma
0
OS
Turns out that SM*sv does not compile either: I get this error -

./Eigen/src/SparseCore/SparseMatrixBase.h:282: error: no type named ‘InnerIterator’ in ‘class Eigen::SparseSparseProduct<const Eigen::SparseMatrix<double, 0, int>&, const Eigen::SparseVector<double, 0, int>&>’

SM is SparseMatrix<double> and sv is SparseVector<double>.
sgollamu
Registered Member
Posts
8
Karma
0
OS
More info on the same...

/* my code ********************/
SparseMatrix<double> M(4,4);
SparseVector<double> v(4);

// insert values into M and v... (M is symmetric)

cout << "M*v = " << M*v; // does not compile
SparseVector<double> u = M*v; // compiles, but fails assertion at runtime
SparseMatrix<double> U = M*v; // compiles and runs ok
double s = v.transpose()*M*v; // does not compile
double r = (v.transpose()*M*v).coeff(0,0); // does not compile
SparseMatrix<double> vMv = v.transpose()*M*v; // compiles and runs ok
double t = vMv.coeff(0,0); // compiles and runs ok
/******************************/

Can someone please help me with the above compilation and runtime failures. And is vMv -> t the best way to compute v'*M*v? Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I'm looking at it.
In the meantime you can use a one column SparseMatrix instead of a SparseVector.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
ok, the SparseVector<double> r = M * v; is fixed now. Same for v.dot(M*v), and u = M * v; For the other expression, you have to evaluate the product to get access to coeff:


double s = (v.transpose()*M*v).eval().coeff(0,0);


v.transpose()*M*v returns a 1x1 dense matrix.
sgollamu
Registered Member
Posts
8
Karma
0
OS
Awesome, thanks! Great job with eigen, love using it!
sgollamu
Registered Member
Posts
8
Karma
0
OS
Now a truly newbie question: how do I download the fixed code?
Andre
Registered Member
Posts
90
Karma
1
Eigen uses bitbucket. Here is the link: https://bitbucket.org/eigen/eigen/overview

You can use mercurial to clone the repository (hg clone https://bitbucket.org/eigen/eigen) or use the get source link on the page. You can also follow the changes here: https://bitbucket.org/eigen/eigen/changesets


'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett

'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger


Bookmarks



Who is online

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