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

How do I multiply a sparse matrix by a dense matrix in Eigen

Tags: None
(comma "," separated)
lgUser
Registered Member
Posts
1
Karma
0
I am trying to multiply a sparse matrix by a dense one:

#include <Eigen/Dense>
#include <Eigen/Sparse>

using namespace Eigen;

int main()
{
SparseMatrix<double> s;
s.resize(3,3);
MatrixXf d(3,3);

MatrixXf d2(3,3);

// gives an error
s*d;

// doesn't give an error
d*d2;
}

This MWE compiles perfectly without s*d, but with s*d there are many template errors... Any ideas how to do that?

Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
you are mixing float and double! Either use MatrixXd or a SparseMatrix<float> to ensure compatible scalar types. You can also explicitly cast to a given scalar type using d.cast<double>(), e.g.:

s * d.cast<double>()


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]