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

Sparse block operations?

Tags: None
(comma "," separated)
christopher_batty
Registered Member
Posts
3
Karma
0

Sparse block operations?

Mon Jun 02, 2014 3:46 pm
The sparse matrix quick reference guide indicates that I can (1) use block operations to access sub-matrices of a SparseMatrix, and (2) add and subtract with sparse matrices.
Is it possible to combine these operations (in such a way that I can write changes back to the original sparse matrix)? It's not obvious to me from glancing at the docs.
e.g.,
Code: Select all
M1.topLeftCorner(10,10) -= M2;

I'm getting a compile error when trying to do this. I can readily imagine this might not be convenient to support, so I'm not necessarily surprised.

If it's not supported, is there a recommended alternative way to accomplish the same thing?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Sparse block operations?

Wed Jun 04, 2014 12:32 pm
Indeed, only subset of columns are writable for a column-major matrix.
I'll accept a patch generalizing the implementation to any submatrices. Might be useful for quick testing or when performance is not critical, or in some cases where the structure does not change. The current implementation is in Eigen/src/SparseCore/SparseBlock.h, in the function:
Code: Select all
template<typename OtherDerived>
inline BlockType& operator=(const SparseMatrixBase<OtherDerived>& other)
{
  /* ... */
}

Perhaps the easiest would be to do the merging within the temporary matrix ('tmp'), and then keep the insertion into the actual matrix unchanged.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]