Bug 611 - Multiplying sparse matrix with vector as diagonal matrix from the left
Multiplying sparse matrix with vector as diagonal matrix from the left
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Sparse
3.2
All All
: Normal Unknown
Assigned To: Nobody
:
Depends on:
Blocks: 3.2
  Show dependency treegraph
 
Reported: 2013-06-11 10:34 UTC by Sabrina
Modified: 2013-07-05 23:23 UTC (History)
3 users (show)



Attachments
Test for multiplying a vector as diagonal with a sparse matrix. (190 bytes, text/x-c++src)
2013-06-11 10:34 UTC, Sabrina
no flags Details

Description Sabrina 2013-06-11 10:34:09 UTC
Created attachment 344 [details]
Test for multiplying a vector as diagonal with a sparse matrix.

Dear Eigen developers,

when trying to multiply a vector as diagonal matrix with a sparse matrix from the left the code does not compile, while multiplying it from the right works. 
The same code works when a dense matrix is considered.
Comment 1 Gael Guennebaud 2013-06-28 16:23:07 UTC
Works with a DiagonalMatrix:

DiagonalMatrix<double,Eigen::Dynamic>(d.asDiagonal()) * A

I'm investigating why it doesn't with a DiagonalWrapper.
Comment 2 Gael Guennebaud 2013-06-28 17:11:26 UTC
https://bitbucket.org/eigen/eigen/commits/2b1e3e6f9e2b/
Changeset:   2b1e3e6f9e2b
User:        ggael
Date:        2013-06-28 17:10:53
Summary:     Fix bug 611: fix const qualifier in cwiseProduct(sparse,dense) and SparseDiagonalProduct::InnerIterator
Comment 3 Kolja Brix 2013-07-01 09:16:14 UTC
Dear Gael,

thank you for your patch! I can confirm that both

SparseMatrix<double> A2=DiagonalMatrix<double,Eigen::Dynamic>(d.asDiagonal()) * A;

and the short version

SparseMatrix<double> A2=d.asDiagonal()*A;

are working now.


Unfortunately, this does not yet fix the problem, because

SparseMatrix<double> A3=d.asDiagonal()*A*d.asDiagonal();

and

SparseMatrix<double> A3=DiagonalMatrix<double,Eigen::Dynamic>(d.asDiagonal()) * A * DiagonalMatrix<double,Eigen::Dynamic>(d.asDiagonal());

still do not compile. The error message in both cases is 

Eigen/src/SparseCore/SparseCwiseUnaryOp.h:30:62: error: no type named 'ReverseInnerIterator' in 'Eigen::CwiseUnaryOpImpl<Eigen::internal::scalar_multiple_op<double>, const Eigen::SparseDiagonalProduct<Eigen::DiagonalMatrix<double, -0x00000000000000001>, Eigen::SparseMatrix<double> >, Eigen::Sparse>::_MatrixTypeNested {aka const class Eigen::SparseDiagonalProduct<Eigen::DiagonalMatrix<double, -0x00000000000000001>, Eigen::SparseMatrix<double> >}'

Could you please have a look at the problem again?

Thank you in advance!
Comment 4 Christoph Hertzberg 2013-07-01 14:08:43 UTC
re-opened because original bug still exists.
(Inefficient) work-around is to add an (...).eval() around one of the products.
Comment 5 Gael Guennebaud 2013-07-01 14:37:46 UTC
Another workaround: A.cwiseProduct(d*d.transpose())
Comment 6 Gael Guennebaud 2013-07-05 23:23:55 UTC
https://bitbucket.org/eigen/eigen/commits/742a401329e6/
Changeset:   742a401329e6
User:        ggael
Date:        2013-07-05 22:42:46
Summary:     Fix bug 611: diag * sparse * diag

Note You need to log in before you can comment on or make changes to this bug.