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

blocks in Sparse Matrices ?

Tags: None
(comma "," separated)
Pillard
Registered Member
Posts
2
Karma
0

blocks in Sparse Matrices ?

Thu May 06, 2010 3:45 pm
Hello dear Eigen developers !

I've recently discovered Eigen, and I must say that I am pretty impressed by it !

So we might use it for a project at work, however for this we need to extend it a little bit, particularly the sparse matrices functions.

Essentially, we would like to make sparse matrices behave as "block matrice", e.g. having 3x3Matrices instead of Scalars.

I tried to hack Eigen myself, so that I can declare something like:
SparseMatrice<Matrix3d> mySparse(3, 3);

I had to derive the Matrix class in order to override the Matrix(int/float/double) constructor (so that numerical values in the code of eigen get converted to Matrices implicitely). This way I got a "BlockSparse by BlockSparse" product up and running !

The dark side is that my hack created many side effects (e.g. the transpose of the matrix is wrong as the blocks don't get transposed), and that multipling a blockSparse by a "blockVector" is out of reach, due to the different "Scalar" types used for the two structures (3x3Mats VS 3x1Vec).

Do you guys think that this would be something doable with a bit more efforts and hacking, or do you think that it will eventually turn into a big, nasty mess ?

Thanks for your insight,

Best,

Etienne
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: blocks in Sparse Matrices ?

Thu May 06, 2010 4:35 pm
Are you using the devel branch ? if not I recommend you to use it for this kind of hack.

Regarding your matrix x vector issue, I think this is doable by specializing the ei_scalar_product_traits<A,B> helper template struct which is used to determine the returned scalar type of the product of two different scalar types. See the file Core/util/Meta.h.

If it is not used by the sparse products then it's a bug...
Ian Mackenzie
Registered Member
Posts
15
Karma
0

Re: blocks in Sparse Matrices ?

Thu May 06, 2010 5:07 pm
I'm a bit confused - I thought products were only allowed between operands with the same type (with a special exception for real/complex products) because of vectorization issues. I'd love to able to allow mixed double/Interval operations (I'm working on a project which makes extensive use of intervals and interval matrices), and I'd be quite happy to sacrifice vectorization, but even if I specialize ei_scalar_product_traits for doubles and Intervals I still run into the assertion in CwiseBinaryOp:
Code: Select all
 EIGEN_STATIC_ASSERT((ei_functor_allows_mixing_real_and_complex<BinaryOp>::ret
                           ? int(ei_is_same_type<typename Lhs::RealScalar, typename Rhs::RealScalar>::ret)
                           : int(ei_is_same_type<typename Lhs::Scalar, typename Rhs::Scalar>::ret)),
        YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)

since it still checks that the two operands have the exact same scalar type, not just two scalar types who are compatible according to ei_scalar_product_traits...or has this been changed in the devel branch?
Pillard
Registered Member
Posts
2
Karma
0

Re: blocks in Sparse Matrices ?

Fri Jun 18, 2010 12:50 pm
Hello,

sorry for the late reply, got dragged to other directions for a while...

So I tried the specialization thing, and it worked ! thanks a lot.

I had the same issue as Ian does, but for solving this one I simply commented the assert, and the product seems to work fine ! (I haven't tried more complex ops, hope they work too...)

Thanks again for your help,

Cheers
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: blocks in Sparse Matrices ?

Fri Jun 18, 2010 10:21 pm
To Ian: the RealScalar type associated to your interval class should be double, and so the assertion should not fail. Just make sure the Real typedef in your NumTraits is properly defined.


Bookmarks



Who is online

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