[Numpy-discussion] Record Arrays and ctypes Interfacing
Robert Kern
robert.kern at gmail.com
Tue Mar 18 14:18:27 EDT 2008
On Tue, Mar 18, 2008 at 9:48 AM, <vel.accel at 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
More information about the NumPy-Discussion
mailing list