[SciPy-Dev] constructing record dtypes from the numpy c-api

Jason Newton nevion at gmail.com
Thu Jul 23 18:14:12 EDT 2015


Hi folks,

Cross-posting from the numpy ML; I can't get my account past the moderator
to get my email out to the list.  Also accidentally sent one out to the
scipy-user list.. I've been a longtime subscriber to scipy-dev though - so
I hope this one gets through in a timely manner.

I was trying to figure out how to make a dtype for a c-struct on the
c-side and storing that in some boost python libraries I'm making.

Imagine the following c-struct, greatly simplified of course from the
real ones I need to expose:

struct datum{
    double position[3];
    float velocity[3];
    int32_t d0;
    uint64_t time_of_receipt;
};


How would you make the dtype/PyArray_Descr for  this?

I have as a point of reference compound types in HDF for similar
struct descriptions (h5py makes these nearly 1:1 and converts back and
forth to dtypes and hdf5 types, it uses Cython to accomplish this) -
but I don't want to bring in hdf for this task - I'm not sure how well
the offsets would go over in that translation to h5py too.

Proper/best solutions would make use of offsetof as we insert entries
to the dtype/PyArray_Descr.

The language I'm working in is C++11.  The end goal is probably going
to be to create a helper infrastructure to allow this to be made
automatically-ish provided implementation of a [static] visitor
pattern in C++.  The idea is to make numpy compatible c++ POD types
rather than use Boost.Python wrapped proxies for every object which
will cut down on some complicated and time consuming code (both of
computer and developer) when ndarrays are what's called for.

Thanks for any advisement!


-Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20150723/3fe3e7eb/attachment.html>


More information about the SciPy-Dev mailing list