Registered Member
|
Hi Eigen Team,
First of all, awesome work! Thank you very much! I am quite new to Eigen (moving from FreePooma) and I have a few questions: 1. It's very convenient to be able to define a Scalar -> Scalar function and apply it cwisely:
I have some N-ary operations (for instance, e-0.5*(u*u+v*v+w*w)) and I would like to transform them info functions in order to do
instead of the macro approach I am using right now
So, is it possible to define something like "NaryExpr" in a way that does not hurt perfomance? 2. I have a lot of big expressions ranging from 3 to 20 terms, already factored out, all applied in a cwise fashion. Is there a "not so obvious" way to speed up evaluation of these expressions, or I can simply close my eyes and let Eigen do all the work? Thanks a lot, Renato |
Moderator
|
1- actually, thanks to expression template and the rich API of Eigen it is very rarely the case that you need to write custom cwise functors. Also, custom cwise functors cannot be vectorized while pure Eigen code will be, e.g.:
e + 0.5 * (u.cwise().square() + v.cwise().square() + w.cwise().square()) and then you can even write a template generic function implementing this expression if you want. No need to use cwise functors for that. 2 - Eigen already does unrolling and vectorization for you, so the only way you can help Eigen is to try to evaluate sub expressions which cannot be vectorized such that other parts of the expression get vectorized but this require a deep knowledge about Eigen's current vectorization support... |
Registered Member
|
Hi Gaël,
Thanks for the answers! 1. Ok, undestood, but it raises another question. I am using a macro that implements exactly what you said, using cwise().square(). If I am willing to write a function, I can see two options:
in this case, the return type is also an argument of the function. Not so expressive, but it should work fine. The other option
should return what? I guess is probably an expression, but I don't know how to declare it. 2. Ok, so let Eigen do the job Thanks again, Renato |
Registered Member
|
About 1.
The thing that you should put in "HERE" is the type of the resulting expression which looks very, very ugly, so I wouldn't really recommend that you enter into this; moreover with the current code you'd have to put NestByValue at the right place although that latter point is likely to go away in the next release. So: - if you just want optimal performance, go with your solution taking the result object as argument. - if you want optimal performance AND syntactic sugar, two options: a) let your function return a ReturnByValue object (only with the development version of eigen2) b) use C++1x's new "rvalue references" feature - if your expression is complex enough that adding one redundant copy operation is negligible, and if your matrices are not too big, then just let your function return a Matrix by value.
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
|
Yes, I have guessed I would need to put the resulting expression type on the return argument, which can be very, very ugly.
I will go the optimal performance route using the return as argument. Who likes sugar anyway? Thanks a lot, Renato |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]