Registered Member
|
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 |
Moderator
|
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... |
Registered Member
|
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:
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? |
Registered Member
|
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 |
Moderator
|
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.
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]