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

Unified initialization syntax for both dense and sparse?

Tags: None
(comma "," separated)
tmakino
Registered Member
Posts
1
Karma
0
Hi,
I'm now using Eigen to implement some mathematical library,
in which the underlying matrix class can be switched through
a template parameter. Idea is that the user can try dense and sparse
matrices to see which is better for his use-case.
It works surprisingly well (thanks for providing Eigen!)
except one thing: initialization.
Consider the following code, which prepares some data for unit-testing:

template <class Mat>
class make_testdata
{
Mat mat1, mat2;
public:
make_testdata() : mat1( rows, cols ), mat2( ... ) {
/* initialize mat1, mat2... */
}
};

The problem is that there no unified syntax that can be used to initialize
both sparse and dense matrices.
The comma-initializer as well as element writing through mat1(i,j) does not
work with sparse matrices.
The syntax with triplets as well as mat1.insert(i,j) does not work with dense matrices.
The only possible way is write elements through mat1.coeffRef(i,j),
but because we cannot use mat1.reserve() nor mat1.makeCompressed() for dense matrices
so the initializing sparse matrix would be slow and wasteful.

So, I wish if either of the following could be possible:
1. Triplet initialization for dense matrix.
2. reserve() and makeCompressed() member functions for dense matrix,
which do nothing at all.
3. Comma initializer for sparse matrix.


Bookmarks



Who is online

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