This bugzilla service is closed. All entries have been migrated to
Bug 611 - Multiplying sparse matrix with vector as diagonal matrix from the left
Summary: Multiplying sparse matrix with vector as diagonal matrix from the left
Alias: None
Product: Eigen
Classification: Unclassified
Component: Sparse (show other bugs)
Version: 3.2
Hardware: All All
: Normal Unknown
Assignee: Nobody
Depends on:
Blocks: 3.2
  Show dependency treegraph
Reported: 2013-06-11 10:34 UTC by Sabrina
Modified: 2019-12-04 12:22 UTC (History)
3 users (show)

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
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();


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
Changeset:   742a401329e6
User:        ggael
Date:        2013-07-05 22:42:46
Summary:     Fix bug 611: diag * sparse * diag
Comment 7 Nobody 2019-12-04 12:22:42 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

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