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

Very simple question

Tags: None
(comma "," separated)
CountChocula
Registered Member
Posts
4
Karma
0

Very simple question

Wed Mar 12, 2014 3:56 pm
How do I add sparse and dense matrices? I tried it and it doesnt work :(

Code: Select all
   
        Eigen::MatrixXcd cmat, cmat2;
   Eigen::SparseMatrix<double> smat;

   cmat2 = cmat + smat;


The above does not compile T_T
jitseniesen
Registered Member
Posts
204
Karma
2

Re: Very simple question

Thu Mar 13, 2014 9:10 am
One issue is that you are mixing complex and real matrices. But even if all matrices are real, the operation sparse matrix + dense matrix does not seem to compile, though http://eigen.tuxfamily.org/dox/group__T ... tml#title5 says that it should. This looks like a bug to me.

In the meantime, you can convert the sparse matrix to a dense matrix with .toDense(). Explicitly, the following should work:
Code: Select all
Eigen::MatrixXcd cmat, cmat2;
Eigen::SparseMatrix<double> smat;
cmat2 = smat..toDense().cast<std::complex<double> >() + cmat1;


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]