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

Pb switching from DynamicSparseMatrix to SparseMatrix

Tags: None
(comma "," separated)
alexandres
Registered Member
Posts
4
Karma
0
Hi,

First of all great work with Eigen, we began using this library in our company a few years ago, and so far have been very happy with the results.
Now, we recently switched from Eigen 3.0.3 to Eigen 3.2, and noticed the DynamicSparseMatrix is now deprecated and there is a single structure SparseMatrix that
can be either compressed or non compressed. Fine.

The great benefit from the separate structures was to be able to control the compression phase. Now each time you operate on a non compressed sparse matrix, it will be automatically be compressed. For our needs it is a problem, because it dramatically slows down the frequent reinitialization of our matrices.

Typically, we solve non linear equations, and let's say we need to frequently update a sparse matrix A. We used to do this with the old DynamicSparseMatrix format:

Code: Select all
main {
   SparseMatrix<double> A;
   loop{
    A=SomeClass.getUpdatedA();
    ....
  }
}

class SomeClass {
public:
  DynamicSparseMatrix<double>& getUpdatedA() {
    A=Alinear;
    // Add non linear contributions calling 
    loop {
      A.coeffRef(row,col) += someNonLinearContribution;
    }
  } 

private:
// A and A linear are preallocated with enough space to store all our contributions
DynamicSparseMatrix<double> A,
                                                          AlinearPart;
}

This was quite fast, with the new version (replacing DynamicSparse with Sparse), when you call getUpdatedA(), A becomes compressed after the first line, and the addition of the non linear contributions is really slow since we need to reallocate everything each time.
Is there a way to keep a matrix uncompressed ?
Thanks
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You can still use DynamicSparseMatrix from <unsupported/Eigen/SparseExtra>. However, it's non supported... For a cleaner solution I need more details:
- Does the structure of A change? or is it fixed?
- If it changes, is it due to the structure of A_linear? or due to the additional coefficients? or both?
- Does the structure of A_linear change?
alexandres
Registered Member
Posts
4
Karma
0
Good to know, I will maybe stick to the DynamicSparse format, unless you come up with a better solution.

The structure of A and A_linear is fixed. We need a constant pattern for our sparse matrices, so we stamp zero terms in the sparse matrix if needed to preserve the structure.
alexandres
Registered Member
Posts
4
Karma
0
One more thing, the structure of A and Alinear is fixed, but A and Alinear have a different structure.
alexandres
Registered Member
Posts
4
Karma
0
Any suggestions ?


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]