[Numpy-discussion] restricting object arrays to a single Python type

Anthony Scopatz scopatz at gmail.com
Tue Jul 16 19:51:58 EDT 2013

Hi Geoffrey,

Not to toot my own horn here too much, but you really should have a look at
xdress (http://xdress.org/ and https://github.com/xdress/xdress).  XDress
will generate a wrapper of the Force class for you and then also create a
custom numpy dtype for this class.  In this way, you could get exactly what
you want.

If you run into any trouble, let me know and I'll be sure to help you out!
 This is the kind of thing that xdress is *supposed* to do so bugs here are
a big priority for me personally =)

Be Well

On Tue, Jul 16, 2013 at 6:44 PM, Geoffrey Irving <irving at naml.us> wrote:

> Is there a standard way of creating an object array restricted to a
> particular python type?  I want a safe way of sending arrays of
> objects back and forth between Python and C++, and it'd be great if I
> could use numpy arrays on the Python side instead of creating a new
> type.
> For example, I might have a C++ class Force which is simultaneously a
> valid Python extension type (also named "Force").  I'd like to be able
> to switch between Array<Force> on the C++ side and a suitable numpy
> array on the Python side, while preventing Python from ever storing an
> object with different type (say, a tuple) in the array.  Note that
> Array<Force> has the memory representation of an array of PyObject*'s.
> Thanks,
> Geoffrey
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130716/76da224a/attachment.html>

More information about the NumPy-Discussion mailing list