[Numpy-discussion] Record Arrays and ctypes Interfacing

vel.accel@gmai... vel.accel@gmai...
Tue Mar 18 14:36:58 CDT 2008


On Tue, Mar 18, 2008 at 2:18 PM, Robert Kern <robert.kern@gmail.com> wrote:
>
> On Tue, Mar 18, 2008 at 9:48 AM,  <vel.accel@gmail.com> wrote:
>  > Hi all,
>  >
>  >  How do I handle numpy record arrays (heterogenous dtype) with ctypes?
>  >  The python side is reasonably obvious to me, but I'm confused about
>  >  how to declare my C function's signature; whether I need to include
>  >  the numpy array interface header file or not... etc...
>  >
>  >  It's not obvious to me how a heterogeneous dtype is handled on the C
>  >  side. Could someone give me a quick and dirty example.
>
>  Record arrays (loosely) correspond to arrays of C structs. The
>  correspondence is only loose because the C standard does not specify
>  how the struct members should be aligned. Different systems may place
>  padding in places where numpy didn't. There are often #pragmas one can
>  use to force a particular kind of padding. Here is a reasonably good
>  article on the subject:
>
>   http://en.wikipedia.org/wiki/Data_structure_alignment
>
>  You shouldn't need any numpy headers.
>
>  --
>  Robert Kern
>
>  "I have come to believe that the whole world is an enigma, a harmless
>  enigma that is made terrible by our own mad attempt to interpret it as
>  though it had an underlying truth."
>   -- Umberto Eco
>  _______________________________________________
>  Numpy-discussion mailing list
>  Numpy-discussion@scipy.org
>  http://projects.scipy.org/mailman/listinfo/numpy-discussion
>

Thank you Robert.

I had figured out that all that was required was a struct analogous to
the dtype be defined in the C file. I inserted an simple example in
the ctypes entry of the Wiki for others' reference .
<a href="http://www.scipy.org/Cookbook/Ctypes#head-9c2123bb99fa424ed4a3fc0b4ef38cddf3aa21c6">heterogeneous
types example</a>


More information about the Numpy-discussion mailing list