Re: [eigen] Assignment of Complex Number

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,

>> you could replace the
>> entire loop by the following two statements, Eigen will take care of the
>> rest internally:
>>
>> ComplexVector.real() = FirstVector;
>> ComplexVector.imag() = SecondVector;
> 
> Any feel for that (two passes over memory) vs one pass (with likely
> useless multiplication):
> 
> ComplexVector = FirstVector * std::complex<double>(0,1)*SecondVector;

Oh, so really interesting. Three test cases:

1. Loop
for (int i = 0; i < 10; i++)
   ComplexVector(i) =
      std::complex<double>(FirstVector(i), SecondVector(i));

2. .real()/.imag()
ComplexVector.real() = FirstVector;
ComplexVector.imag() = SecondVector;

3. Multiplication with std::complex
ComplexVector = std::complex<double>(1,0) * FirstVector +
                std::complex<double>(0,1) * SecondVector;


Timing (50 million times on my PC, single core, arrays are allocated
within the loop, so times are slower than they could be. Output
disabled. Code otherwise the same. Still, you see differences):

Loop(1):      8166ms
..real()(2):   8581ms
Mult(3):      8363ms

So the direct access is actually slightly faster. Huh. Wouldn't have
expected that... Probably because SSE packet size is the size of
complex<double> so there's no packet access optimization for Eigen.

Tried with float, which can leverage SSE more for complex data types, got:

Loop(1):      4116ms
..real()(2):   4131ms
Mult(3):      3907ms

Huh. Also interesting. Probably because float can leverage SSE for case
(3), but not that much for (1) and also probably not for (2).

Regards,
Christian




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/