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

initialize to zero

Tags: None
(comma "," separated)
ixx
Registered Member
Posts
4
Karma
0

initialize to zero

Thu Nov 12, 2009 4:46 pm
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!
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: initialize to zero

Thu Nov 12, 2009 5:01 pm
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!
ixx
Registered Member
Posts
4
Karma
0

Re: initialize to zero

Thu Nov 12, 2009 5:16 pm
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!
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: initialize to zero

Thu Nov 12, 2009 5:56 pm
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!
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: initialize to zero

Thu Nov 12, 2009 7:11 pm
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!
ixx
Registered Member
Posts
4
Karma
0

Re: initialize to zero

Mon Nov 16, 2009 5:35 pm
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
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: initialize to zero

Mon Nov 16, 2009 6:50 pm
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!
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: initialize to zero

Mon Nov 16, 2009 7:01 pm
Code: Select all
100% tests passed, 0 tests failed out of 43


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!
ixx
Registered Member
Posts
4
Karma
0

Re: initialize to zero

Tue Nov 17, 2009 3:25 pm
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.
Andre
Registered Member
Posts
90
Karma
1

Re: initialize to zero

Tue Nov 17, 2009 7:07 pm
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
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: initialize to zero

Tue Nov 17, 2009 7:41 pm
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!
Andre
Registered Member
Posts
90
Karma
1

Re: initialize to zero

Wed Nov 18, 2009 6:44 am
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


Bookmarks



Who is online

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