On Thu, May 14, 2009 at 8:31 PM, Carl Witty <[email protected]> wrote:
> On Thu, May 14, 2009 at 4:07 PM, Robert Bradshaw
> <[email protected]> wrote:
>> On May 14, 2009, at 3:56 PM, Lisandro Dalcin wrote:
>>
>>> I used to teach numerical calculus, so I cannot resist :-)
>>
>> Thanks for the heads up--I deal mostly with exact arithmetic (e.g.
>> when writing that code I had the gaussian integers in my head) so
>> it's good to have an expert speak up.

I'm far from being an expect on this :-)

>
> Divisions are very expensive, but the relative cost of division and
> multiplication will obviously depend on the architecture, etc.
>
> In short: Yes, you should do benchmarks :)
>

OK. Still, IMHO we should prefer safety on this. After all, all this
is only relevant for the struct case. I would expect any compiler
providing C99 complex support will implement complex division in the
right and optimized way...

However, interestingly enough, my C++ <complex> header (from GCC
4.3.2) seems to implements the naive way (although warned in the
comment)... Am I missing something here??

  // 26.2.5/15
  // XXX: This is a grammar school implementation.
  template<typename _Tp>
    template<typename _Up>
    complex<_Tp>&
    complex<_Tp>::operator/=(const complex<_Up>& __z)
    {
      const _Tp __r =  _M_real * __z.real() + _M_imag * __z.imag();
      const _Tp __n = std::norm(__z);
      _M_imag = (_M_imag * __z.real() - _M_real * __z.imag()) / __n;
      _M_real = __r / __n;
      return *this;
    }



> But benchmarks should be careful to have a realistic mix of numbers to
> divide, to properly test the branch prediction.  For example, compute
> a couple of arrays of random complexes, and then benchmark elementwise
> division of these arrays (assuming that we think that random complex
> numbers are "realistic").
>
> Carl
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to