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

Creating sparse matrix from blocks

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

Creating sparse matrix from blocks

Mon Oct 03, 2016 3:15 pm
Hi there everyone.

I know that one cannot yet fill a sparse matrix through direct block insertion.

So, I'm thinking that there must be some way to get the intendend block elements values and respective indices, associate them with a triplets list and them finally inserting them into a sparse matrix.

Does anyone know a efficient way to do this, or any other kind of fast operations that allow the creation of a sparse matrix given a set of sparse submatrices?

Maybe iterating thorugh the sparse matrix like the below code, and then creating a triplet list is the most efficient currently available set of operations?

Code: Select all
SparseMatrix<double> mat(rows,cols);
for (int k=0; k<mat.outerSize(); ++k)
  for (SparseMatrix<double>::InnerIterator it(mat,k); it; ++it)
  {
    it.value();
    it.row();   // row index
    it.col();   // col index (here it is equal to k)
    it.index(); // inner index, here it is equal to it.row()
  }


Thank you.

Best regards,
André
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Indeed, currently users have to do their own cooking for that kind of operations. Filling a big triplet list is definitely the easiest and safest way.
andresilva
Registered Member
Posts
4
Karma
0
OS
ggael wrote:Indeed, currently users have to do their own cooking for that kind of operations. Filling a big triplet list is definitely the easiest and safest way.


In fact, this kind of "user-made" solution has got me thinking more closely to thie actual problem and I was actually able to significantly reduce the needed computational time, with comparison to a previous solution that I had implemented with a different linear algebra library.

Just to clarify one more aspect, I'll be needing this kind of sparse matrix filling scheme for a given number of iterations. So, between each of the iterations, I'll have to "clean" a given number of sparse matrices, which were created from triplets (batch insertion).

Any advice about the fastest and safest way to clear a sparse matrix in eigen? SparseMatrix.setZero()?

Thank you,
André


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]