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

[SOLVED] cwise() with complex function

Tags: None
(comma "," separated)
User avatar
markusfroeb
Registered Member
Posts
6
Karma
0
OS
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.
User avatar
bjacob
Registered Member
Posts
658
Karma
3

RE: cwise() with complex function

Thu Feb 19, 2009 1:55 am
[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!
User avatar
markusfroeb
Registered Member
Posts
6
Karma
0
OS
Thanks! This works very well.
But if I now change the expression a bit, say add a square to the first a
Code: Select all
#include
res = a.cwise().square() / (a + c * b.cwise().square()).cwise().sqrt();

it won't compile again.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
That's because now you miss a cwise() before the /, like this:
Code: Select all
res = a.cwise().square().cwise() / (a + c * b.cwise().square()).cwise().sqrt();


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!
User avatar
markusfroeb
Registered Member
Posts
6
Karma
0
OS
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() :)


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell