Fast array exchange between python and C++

eric jones eric at enthought.com
Wed Jan 23 12:22:34 EST 2002


Hey Jan,

For multi-dimensional arrays, Numeric is the way to go:

    http://www.pfdubois.com/numpy/

It provides fast execution in Python, and also a C level API that provides
access to the array pointer without any data copying.  If your comfortable
with SWIG, then writing typemaps to handle the Python/C conversion isn't to
hard.

Depending upon your needs, another alternative is weave:

    www.scipy.org/site_content/weave

This handles the conversion between Numeric and C or C++ arrays
automatically and allows you to embed your C/C++ code directly in Python.

eric


"Ja'zz" <ja at zz.emsmp.fr> wrote in message news:84adv5s5sv.fsf at zz.emsmp.fr...
>
> What is the recommended way to transfer arrays of numerical data from
> python to a C/C++ library and vise-versa? My current approach is to
> define the array in a C++ class, write put and get methods with indexes
> and use SWIG (-shadow) to access the methods in python. It works but
> creates loads of overhead.
>
> However, at this point, efficiency becomes a vital concern. How to I
> exchange an array of simple datatypes (doubles, integers and strings),
> such that they are read/write at both sides, with a minimum of overhead?
>
> I am a newbie to python programming. Any hints are very much
> appreciated.
> -Jan.
> --
> Jan van der Lee -- vanderlee at cig dot ensmp dot fr





More information about the Python-list mailing list