Registered Member
|
Hi,
I would like to do either of this (which ever is faster to calculate): 1) vector2 += scaler1 * ((vector - scaler2))^2 or 2) vector2 += (scaler1 * (vector - scaler2))^2 What I have done so far is this like of code:
could you please tell me what is the best way to do that ? so to eliminate temporaries as much as possible. |
Registered Member
|
Your Eigen code is already perfect and won't cause any temporary to be created. It also should vectorize perfectly.
The only comment that I have to make is: if you are interested in this kind of operations, are you sure that you really want vectors (matrices) and not Arrays ? Eigen3 allows you to declare your objects as Arrays so that you don't need to call .array() to get Array behavior. This is just to make your code a bit simpler:
but of course, if you want matrix arithmetic elsehwere in your code, then your current code was the right choice.
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
|
A quick thought: Wouldn't it be nice to have something like type conversion (aka mapping) in the line of
Cheers Frank |
Registered Member
|
Oh you mean naming and storing the expression returned by .array() ? You can do this today; .array() returns a ArrayWrapper object that you can store for later use. See class ArrayWrapper.
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
|
OK, shame on me .
Isn't it nice to have expressions? Yes, it is! |
Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]