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

Multiplication of symmetric dense and sparse matrix

Tags: None
(comma "," separated)
aboriskin
Registered Member
Posts
1
Karma
0
I am a newcomer to eigen library and probably miss something. I have 2 matrixes

1. Eigen::SparseMatrix<double> sp; //sparse matrix
2. Eigen::MatrixXd dm; //symmetric positive dense matrix,

I need to compute new matrix

Eigen::MatrixXd<double> dm2 ;
dm2 = dm * sp.transpose();

In my dense matrix I store elements only in upper part, so I try to make this computation as

dm2 = dm.selfadjointView<Eigen::Upper> * sp.transpose();

But this cause compilation error in MVS2015

error C3867: 'Eigen::MatrixBase<Derived>::selfadjointView': non-standard syntax; use '&' to create a pointer to member
2> with
2> [
2> Derived=Eigen::Matrix<double,-1,-1,0,-1,-1>
2> ]
error C2678: binary '*': no operator found which takes a left-hand operand of type 'overloaded-function' (or there is no acceptable conversion)
2> d:\_________git\ashley\external\eigen\eigen\src\plugins\commoncwiseunaryops.h(76): note: could be 'const Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<double>,const Derived> Eigen::MatrixBase<Derived>::operator *(const double &,const Eigen::MatrixBase<Derived> &)' [found using argument-dependent lookup]
2> with
2> [
2> Derived=Eigen::Matrix<double,-1,1,0,-1,1>
2> ]


What I am doing wrong?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This is not supported. You can multiplay a symmetric-sparse-matrix with a dense one but not the inverse. The reason is that a sparse matrix is expected to be huge (typically 100000^2 and more) and so multiplying with a dense matrix of same size is quite unlikely, and so not a priority.

You can workaround by completing the symmetric dense matrix:

A.triangularView<Lower>() = A.transpose().triangularView<Lower>();

before doing the sparse-dense product. Performance-wise, a dedicated product implementation won't be faster (unless the sparse matrix is extremely sparse with empty rows/columns.


Bookmarks



Who is online

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