user2165656
user2165656

Reputation: 455

How to convert sparse matrix to dense matrix in Eigen

Is there some easy and fast way to convert a sparse matrix to a dense matrix of doubles?

Because my SparseMatrix is not sparse any more, but became dense after some matrix products.

Another question I have: The Eigen library has excellent performance, how is this possible? I don't understand why, because there are only header files, no compiled source.

Upvotes: 20

Views: 17586

Answers (1)

ggael
ggael

Reputation: 29265

Let's declare two matrices:

SparseMatrix<double> spMat;
MatrixXd dMat;

Sparse to dense:

dMat = MatrixXd(spMat);

Dense to sparse:

spMat = dMat.sparseView();

Upvotes: 47

Related Questions