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

coefficient wise binary operation

Tags: None
(comma "," separated)
renorm
Registered Member
Posts
31
Karma
0

coefficient wise binary operation

Thu Jul 29, 2010 2:47 am
Is there a way to extend Cwise to use my own binary function? Let's say, I want to apply element wise my own binary function with the following signature
Code: Select all
double f(double, double);

to two matrices of doubles? I could always do it using a nested loop, but I want the whole thing to be vectorized.
Regards,
renorm.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Yes, you can use:
http://eigen.tuxfamily.org/dox/classEig ... d88f6af1ad

However, if you want the resulting code to be vectorized, you'll have to provide some extra information in your functor, especially the packetOp() method. See e.g. Core/Functors.h for some examples e.g. ei_scalar_sum_op.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
renorm
Registered Member
Posts
31
Karma
0
Thanks. That was very helpful.

Another tiny question. Static factory methods Zeros(), Ones() etc of fixed size matrix don't require any arguments, because the sizes are known. Won't it be an error to supply arguments to those methods? I am using Eigne in generic code and the type of matrix can be both fixed and dynamic.
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: coefficient wise binary operation

Thu Jul 29, 2010 12:01 pm
It won't be an error. It will just assert() that your arguments are the correct values. The reason is exactly your use case.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
renorm
Registered Member
Posts
31
Karma
0
That makes perfect sense. Thanks again.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]