Registered Member
|
Hi!
I am trying to modify a finite element code so that it uses Eigen. Previously, I used classes written by myself whose constructors initialized every single vector/matrix to zero. Since I am trying to replace them with Eigen classes, I would need the new classes also to follow that convention, or otherwise I will need to "hunt down" every instance of vector and matrix and set them manually to zero. Is there a way of telling Eigen to initialize to zero (automatically!) every matrix/vector object? Thanks for your help! |
Registered Member
|
We don't have a feature for that at the moment, but that's a valid request (as a non-default option) to help porting. Are you using the devel branch? If yes, I can add that there.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Thanks for your quick reply!
I am not using the developer branch, but if this feature is added, I will upgrade right away. We've been working for quite a while to make our code Eigen-compatible, just to run at the end against this unpleasant surprise. Regards! |
Registered Member
|
OK, actually i also put it in the 2.0 branch so you can stay there (it's safer).
Just define this preprocessor symbol: EIGEN_INITIALIZE_MATRICES_BY_ZERO You'll be the first person to test it, so, do test it before relying on it.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Sorry, there was an infinite recursion --> crash.
It's fixed now (both branches)
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Hi,
we've been doing some serious testing and debugging and we figured out that overloaded operators of the type += do not work well after using the preprocessor symbol. The operation "+=" actually works as "=" I hope it has an easy fix |
Registered Member
|
oops, that was because this operation does a resize() with newsize==oldsize, and the initialize-by-zero was breaking the assumption that this is a NOP.
This is now fixed in both branches.I am now building the whole test suite with that option to check.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
should be safe now! note that the init-by-zero is rather costly, so you should only consider this a temporary solution.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
It works! Thanks a lot.
Using the new symbol and redefining a handful of functions via the EIGEN_MATRIXBASE_PLUGIN we have been able to change seamlessly the core of our finite element code. Actually, a single flag selects between the new and old implementations (and both work!). Now we will try to isolate the parts that require initialization to zero to finally compare the performance of the two implementations. |
Registered Member
|
Would be great if you could post the results.
'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett
'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger |
Registered Member
|
Andre: Note that i didn't even try to optimize the initialization-by-zero, i coded it as a plain for loop setting the coefficients to zero, it is up to the compiler to unroll it if it wants to. I only coded this as a helper for porting.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
benoit: I rather meant ixx' general porting to Eigen. I don't think the initialization will be a bottleneck. Even if, I'd be interested to hear his opinion on the usefulness of the effort.
'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett
'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]