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

matrix/vector product of SparseMatrix and SparseVector

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

my compiler (g++ (Debian 4.3.2-1) 4.3.2) is not able to compile the following program:
Code: Select all
#include<Eigen/Sparse>

using namespace Eigen;

int main() {
SparseVector<double,RowMajor> a(10);
SparseVector<double,RowMajor> b(10);
SparseMatrix<double,RowMajor> m(10,10);
a = m * b;
return 1;
}



g++ test.cpp -I/usr/local/include/eigen2
/usr/local/include/eigen2/Eigen/src/Sparse/SparseMatrixBase.h: In member function ‘Derived& Eigen::SparseMatrixBase<Derived>::operator=(const Eigen::SparseMatrixBase<OtherDerived>&) [with OtherDerived = Eigen::SparseProduct<const Eigen::SparseMatrix<double, 1>&, const Eigen::SparseVector<double, 1>&, 3>, Derived = Eigen::SparseVector<double, 1>]’:
/usr/local/include/eigen2/Eigen/src/Sparse/SparseVector.h:242: instantiated from ‘Eigen::SparseVector<_Scalar, _Flags>& Eigen::SparseVector<_Scalar, _Flags>::operator=(const Eigen::SparseMatrixBase<OtherDerived>&) [with OtherDerived = Eigen::SparseProduct<const Eigen::SparseMatrix<double, 1>&, const Eigen::SparseVector<double, 1>&, 3>, _Scalar = double, int _Flags = 1]’
test.cpp:9: instantiated from here
/usr/local/include/eigen2/Eigen/src/Sparse/SparseMatrixBase.h:199: error: no type named ‘InnerIterator’ in ‘class Eigen::SparseProduct<const Eigen::SparseMatrix<double, 1>&, const Eigen::SparseVector<double, 1>&, 3>’


Is calculating the product of a SparseMatrix and a SparseVector not possible?


- wette
duetosymmetry
Registered Member
Posts
18
Karma
0
Interestingly enough, I can make a slight modification and make this compile:

Code: Select all
#include<Eigen/Sparse>

using namespace Eigen;

int main() {
SparseMatrix<double,RowMajor> a(10,1);
SparseVector<double,RowMajor> b(10);
SparseMatrix<double,RowMajor> m(10,10);
a = m * b;
return 0;
}


It looks like SparseMatrix has an operator=(SparseProduct<,>), but SparseVector does not.

I'd agree that for completeness, one would like to be able to write sparsevector = sparseproduct.

It may be the case that the product won't be sparse, though. But the programmer should know ahead of time if the product is sparse and choose the storage appropriately.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
indeed, the pb was a missing overload of operator= in SparseVector, should work now in the devel branch (I did not check though....)


Bookmarks



Who is online

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