Registered Member
|
Hi,
I am currently working on preconditioners for a iterative solvers which need to access and modify matrix entries. These functions need to work with both dense and sparse matrices. Unfortunately sparse and dense matrices do not possess the same interface: Dense m(i,j) / Sparse m.coeffRef(i,j). I do not want to duplicate all my functions to support both matrix types. Is there a clever way to overcome these problem e.g. compile time check on matrix type? Are there any plans to unify the interfaces of dense and sparse matrices? Thanks Traubi |
Moderator
|
Yes the goal is to be able to write such high level generic code, but you have to understand that for performance reason we cannot offer a purely random access to sparse matrices. This is why there is no operator() for sparse objects. (Note that .coeffRef(i,j) also works for dense objects but it is strongly not recommended to rely on it for sparse objects)
If you don't insert new zeros and that you can treat your elements in a sequential way, then the best way is to use an InnerIterator and modify the values like this: it.value() = new_value; Can you be more specific about what you need to do? can you share some piece of code? This would help a lot for improving the sparse API. |
Registered Member
|
Hi,
thanks for the quick reply. I checked MatrixBase and DenseBase for coeff and coeffRef and did not find anything, so I assumed it was not supported. Sry should have written a small test in the first place . I should have been more specific, for my problem coeff(i,j) is sufficient and should work since I am writing a diagonal preconditioner and all matrices must have no zero entries in the main diagonal. Cheers Traubi |
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft