[Numpy-discussion] Numpy complex types, packing and C99

Charles R Harris charlesr.harris at gmail.com
Wed Jul 1 16:19:31 EDT 2009


On Wed, Jul 1, 2009 at 1:57 PM, Pauli Virtanen <pav at iki.fi> wrote:

> On 2009-07-01, Charles R Harris <charlesr.harris at gmail.com> wrote:
> > On Wed, Jul 1, 2009 at 1:59 AM, David Cournapeau <
> david at ar.media.kyoto-u.ac.jp> wrote:
> >>    I would like to add an explicit configuration test to check that our
> >> complex type is compatible with the C99 complex type (when available).
> >> Is this ok?
>
> Seems OK to me.
>
> >>    As currently defined, complex c types (npy_cfloat, etc...) are not
> >> defined in a way such as they are binary compatible with the C99 complex
> >> type. Strictly speaking, packing the complex type is an ABI break, but
> >> we already make the assumption in ufunc, so we would have wrong
> >> results/crashes currently if it were not packed, so I believe the check
>
> Is there a reason not to pack our complex number struct? I think
> if we bump the ABI version, changing this should be OK.
>
> >> is harmless by itself. The rationale is that I would like to add support
> >> for complex math in npy_math (cabs, cexp, etc...). As I would like to
> >> use the C99 complex type (when available), this requires that numpy
> >> complex type is ABI compatible with C99 type.
>
> Useful goal: this would allow using npy_math functions as a
> compatibility fallback when the C99 ones are not available.
>
> > What do you mean by "packing" ?
>
> C99 defines a complex type such that the real and imag parts are
> packed as in an array:
>
>        double complex t;
>        real = ((double*)&t)[0];
>        imag = ((double*)&t)[1];
>
> Numpy defines this type as a struct, which may imply additional
> padding.
>

OK. I don't see a problem then. As David says the ufuncs already work that
way. <checks c99> Hmm... do we want to implement creal{l,,f} and cimag{l,,f}
also? They are built in functions in gcc, can we detect that? Anyway, those
functions would make rewriting the current complex functions pretty easy. Or
do we want to rewrite the current functions to be ABI compatible with c99?

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090701/62d13060/attachment.html>


More information about the NumPy-Discussion mailing list