[Numpy-discussion] Record Arrays and ctypes Interfacing
Tue Mar 18 14:36:58 CDT 2008
On Tue, Mar 18, 2008 at 2:18 PM, Robert Kern <firstname.lastname@example.org> wrote:
> On Tue, Mar 18, 2008 at 9:48 AM, <email@example.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:
> 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
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 .
More information about the Numpy-discussion