[Numpy-discussion] Numpy and C++ integration...

Christopher Barker Chris.Barker@noaa....
Mon Feb 4 14:05:45 CST 2008


Lou Pecora wrote:
> I
> would recommend using the C API

I would recommend against this -- there is a lot of code to write in 
extensions to make sure you do reference counting, etc, and it is hard 
to get right.

Much of it is also boiler-plate code, so it makes more sense to have 
that code auto-generated.

There are just too many good tools to do this for you to do it by hand.

The problem is that there is an embarrassment of riches -- if only one 
or tow of the C/C++ interface tools were out there, it would be a whole 
lot easier to choose! My take:

ctypes -- best if you have dll-type interface already defined, and 
particularly if there are a smallish number of functions you want to 
call. Can it call C++ directly at all?

pyrex -- best if you want to implement some custom functions in C from 
scratch. Also pretty good for calling external C code. Only supports 
calling C++ code that's not too fancy -- i.e. stuff that can be called 
from C -- pyrex has no explicit support for C++

SWIG -- best if you have a lot of code to wrap that shares similar 
interfaces - once you write the typemaps, the rest is automatic. Also 
best choice if you want to support more than one scripting language, or 
you want to integrate with other packages built with SWIG (wxPython, 
GDAL, VTK, ...). Bill's numpy-swig typemaps make it easy to deal with 
classic C-style pointers to data blocks. It also comes with built-in 
wrappers for std:vector, though not numpy integration for those.

SIP -- built for pyQT -- folks seem to like it. I don't know if anyone 
has done anything for numpy with it.

Boost::python -- best for writing custom extensions in C++ -- also can 
be used for interfacing with legacy C++. There were boost array classes 
for numpy -- are these being maintained?

Any of these can do that job -- so it's hard to choose, but maybe the 
above helps focus your search.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the Numpy-discussion mailing list