How to multiply a sparse matrix by a dense martix with eigen?

I am trying to multiply a sparse matrix by a dense matrix in Eigen in C++ (the dimensions of course match). The following doesn't seem to work.

Here is a MWE:

  #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
 }

EDIT: The page here suggests that it should work smoothly, yet it doesn't... http://eigen.tuxfamily.org/dox/group__TutorialSparse.html

Answers


Your problem is is not sparse-dense, but rather mixed types, Xhich isn't allowed. Your sparse matrix is of type double while the dense matrices are of type float (MatrixXF). Change MatrixXf to MatrixXd (or cast to double) and it works fine.


Need Your Help

Direct2d command analog to OpenGL's SwapBuffers?

delphi delphi-2010 c++builder direct2d c++builder-2010

What is Direct2d command analog to OpenGl's SwapBuffers? I am using this in a VCL environment such as Delphi and CPP Builder. Thanks

Properly formatted multiplication table

python string algorithm python-3.x formatting

How would I make a multiplication table that's organized into a neat table? My current code is: