[C++-sig] Status of Numpy support in boost python

Jim Bosch talljimbo at gmail.com
Mon Mar 8 20:11:47 CET 2010


On Mon, 2010-03-08 at 13:40 -0500, Stefan Seefeld wrote:
> On 03/08/2010 01:30 PM, Neal Becker wrote:
> >
> > Check out pyublas
> >    
> 
> Thanks for mentioning that.
> 
> Yes, this looks very useful. In fact, my PyArray wrapper was inspired by 
> pyublas.

Definitely useful, and from what I've seen from a quick glance, a very
nice API.  I'm personally using Eigen2 rather than boost.ublas - do you
have any comment on whether this could be made more generic so as to
support other C++ matrix libraries?  Of course, ublas is in boost, so
it's clearly the most important target.

> I think it would be useful to integrate the PyArray wrapper right into 
> boost.python.
> 

I generally agree, but I dislike the idea of including the numpy C-API
header file in all its preprocessor-macro glory in a file which will be
included by users, and I've found it hard to avoid that in a header-only
library.  What was your solution?

> Other libraries which provide more functionality (such as pyublas, or 
> the one Jim is talking about) can then use that wrapper, instead of 
> having to provide it themselves. This should notably also improve 
> interoperability, since the boost.python type registry doesn't (yet) 
> allow multiple wrappers for the same types.

This does seem like the best way to go, if we can find a solution to the
numpy header problem that doesn't require building the boost.python
library itself against numpy.

By the way, here's what I've got - it seems to complement pyublas pretty
well:


- A few "object manager" types for numpy.ndarray, numpy.dtype,
numpy.matrix, and numpy.void scalars, and a pretty easy system for
adding more.  These present a boost.python interface to the parts of the
Numpy C-API, and it sounds like they're pretty similar in spirit to your
PyArray.  I'll look into putting them into the sandbox.

- A tool for creating broadcasting python callables from arbitrary C++
objects that overload operator().

- A multidimensional array template library patterned after numpy; this
is definitely not something that belongs in boost.python, but I find
that they work very well together:

http://code.google.com/p/ndarray/

It would really great if boost.multiarray could fill such a role, but I
found it doesn't do everything needed in talking to numpy - particularly
the ability to handle shared data.


Jim




More information about the Cplusplus-sig mailing list