Re: [eigen] Optimization for special complex operations

[ Thread Index | Date Index | More Archives ]

2010/8/16 Carlos Becker <carlosbecker@xxxxxxxxx>:
> Hi everyone again. Lately I've been using Eigen with complex numbers to
> calculate things such as calculating the maximum of the real part or
> imaginary part of a certain vector. I suppose that trying to take the real
> part and then use maxCoeff() or minCoeff() would create a possible
> unnecessary temporary.

No, it wouldn't :-)

> Another thing is to be able to do something like:
> MatrixXf nn,xx;
> xx = nn.colwise().normalized();

Hm. If we start going that route, won't we end up offering every
possible vector operation as colwise() operation?

So we have to draw a line in the sand, somewhere.

One good place to put this limit, is according to the question: "does
this enable any better performance over a for loop?"

in your case,
    xx = nn.colwise().normalized();

I would say yes, this can enable better vectorization. Indeed if nn
has 3 rows-at-compile-time, each individual normalization operation
can't be vectorized at all, but the global colwise().normalized()
operation could be completely vectorized in the horizontal direction.

This can already be achieved today with a complex enough expression:

  xx = nn.array().colwise() / nn.array().abs2().colwise().sum().sqrt();

(if I am not mistaken...)

> Here there are two very different concepts:
> I guess there could be some special functions, in this case only for complex
> numbers, to be able to perform some special optimizations. I remember we
> were talking a bit about a special case with Gael on the chat channel.
> Regarding the .normalized() snippet above, I know I am breaking reduction
> rules,

Oh, I wouldn't talk about "rules" here. Your operation isn't a
reduction, it would be a "vector-wise operation". That's just

The biggest reason not to do it now is that it really isn't necessary
to release Eigen 3.0 .... ;-)


> since I am expecting xx and nn to be of the same size in the end.
> However, I don't know how much is lost if this normalization is done
> manually with, for instance, a for loop.
> Does this make sense? I would like to work on these but I don't want to
> introduce code that would not make sense or break rules. I only have a small
> insight of what eigen looks like inside.
> Carlos

Mail converted by MHonArc 2.6.19+