constructing record dtypes from the numpy c-api
Jason Newton <nevion <at> gmail.com>
2015-07-23 22:14:12 GMT
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:
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!
SciPy-Dev mailing list
SciPy-Dev <at> scipy.org