Re: [eigen] Converting a sparse symmetric matrix to a (nonsymmetric) dense one

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Indeed, there is no "sparse-selfadjoint to dense" direct conversion implemented. This would require a special path as there is no iterator over all non-zeros of the symmetric sparse matrix. So the easiest is probably something like:

  dense = sparse.triangularView<Upper>();
  dense += sparse.transpose().triangularView<StrictlyLower>();

The first ".triangularView<Upper>()" can be omitted if only the upper triangular part is stored. And best perf is:

  for (int k=0; k<sparse.outerSize(); ++k)
    for (SparseMatrix<double>::InnerIterator it(sparse,k); it; ++it)
      dense(it.row(),it.col()) = dense(it.col(),it.row()) = it.value();

gael


On Thu, Mar 3, 2016 at 11:47 AM, Cedric Doucet <cedric.doucet@xxxxxxxx> wrote:

Hello,

I would like to know how to convert a symmetric matrix into a dense one whose storage is unsymmetric.

For the moment, I perform the converison like this:

        MatrixXd Id = MatrixXd::Identity(n, p);
        MatrixXd dense_matrix = sparse_matrix.selfadjointView<Upper>() * Id;

But I guess it it not optimal.

I would prefer to perform a real conversion, following something like that:

    MatrixXd dense_matrix = MatrixXd(sparse_matrix.selfadjointView<Upper>());

but this syntax does not seem to be correct.

What is the best way to do it?

Thanks!



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/