Registered Member
|
I have a loop of the type
for (int i = 0; i < max; i++) { res[i] = a[i] / sqrt(a[i] + c * b[i] * b[i]); } (with c constant). I thought that it is equivalent to res = a.cwise() / sqrt(a.cwise() + c * b.cwise() * b.cwise()); but on my Debian unstable system it won't compile. Is my version of Eigen2 too old, does it work with another syntax or doesn't it work like this at all? If it doesn't work like this, I'd love to see it implemented! Eigen already halved my calculation time, before I was using BLAS. And when the calculation times start to get longer than some hours, every speedup is important, so already thanks for the great work!
Last edited by ggael on Thu Feb 19, 2009 6:57 am, edited 1 time in total.
|
Registered Member
|
[quote='markusfroeb' pid='46648' dateline='1235002863']
I have a loop of the type for (int i = 0; i res = a.cwise() / (a + c * b.cwise().square()).cwise().sqrt(); [/code] Think of cwise() as just a "prefix". Also, your sqrt() call had no chance because in Eigen sqrt() is also a member method. And also, you dont need cwise() for elementary linear-algebraic ops such as vector addition. Good luck with Eigen!
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! This works very well.
But if I now change the expression a bit, say add a square to the first a
it won't compile again. |
Registered Member
|
That's because now you miss a cwise() before the /, like this:
You need to add cwise() before every operation that is coefficient-wise and not considered an elementary linear-algebraic operation (by which we mean something that has a general geometric meaning regardless of the choice of a basis).
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
|
Aaah, thanks a lot. I thought if cwise() is used once, it will "propagate" through. But of course it makes sense that a.cwise().square() returns again a vector, with coefficient-wise squared coefficients. I think now I understand the design philosophy of cwise()
|
Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell