need an example of Python numarray to C++ and back again, Boost / SWIG?

PL plucek at ssaris.com
Thu Nov 10 09:59:27 EST 2005


I looked at Stefan's post - but he remarks that "Unfortunately, Blitz
jealously guards its data (restricted pointers), so that it is not so
easy to do the conversion in the other direction.  If anyone knows an
answer to this problem, I'd be glad to hear it"

I've previously looked at Phillip Austin's 'num_util' and  Paulo J. S.
Silva's 'COIN' example, but even from those two, I can't figure out a
way to do: Python 2D numarray --> C++ (process array) --> Python 2D
numarray.

I forgot about "weave" - I had looked there before and will revisit it
to see if it will work.  But I was intending to do this with a compiled
extension.  I wish there was a simple example of this in either the
SWIG or Boost docs or a faq/howto posted somewhere . . .

-Paul


Fernando Perez wrote:
> PL wrote:
>
> > I want to pass a 2D array from Python to C++, manipulate it in C++ (for
> > example, add 1 to each element) and pass it back to Python.
> >
> > With these building blocks I will be able to figure out all the rest of
> > what I need to do for my project.  I am very familiar with Python, but
> > less so with C++ and Boost or SWIG.
> >
> > Does anyone have an example with all steps that I can follow?  More
> > specifically I am looking for the C++ code, ".i" file for SWIG and/or
> > the analagous setup files that Boost would need to do this.
>
> You may want to look into weave.inline or weave.blitz, from scipy.  Typemaps for
> conversion to blitz++ were recently posted on the scipy list:
>
> http://aspn.activestate.com/ASPN/Mail/Message/numpy-discussion/2883831
>
> In particular look at Stefan's post.
>
> For info on weave, here you can find some old slides and example code:
>
> http://amath.colorado.edu/faculty/fperez/python/
> 
> Cheers,
> 
> f




More information about the Python-list mailing list