Numpy ndarray as argument or return value using boost python

View: New views
4 Messages — Rating Filter:   Alert me  

Numpy ndarray as argument or return value using boost python

by Pim Schellart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Everyone,

I also posted this to the boost users list.
I tried to find a good example for this but after spending two days on
google and one day getting pyublas to compile I decided to call for
help.
I want to give a numpy ndarray as an argument to a c++ method,
calculate something and return the output as an ndarray to Python.
I would prefer not to use another library (such as PyUblas) for this
so I do not have to add another dependency to my program.
Since the latest information on boost python is quite outdated (uses
numeric) I would like to know the following.

1. Is boost python still maintained or should I switch to another tool.
2. Is numpy supported, and if so,
3. can someone give me a basic example of how to use it.

Kind regards,

Pim Schellart
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: Numpy ndarray as argument or return value using boost python

by Anthony Foglia-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Pim Schellart wrote:
> I also posted this to the boost users list.

Most of the Boost Python discussion goes on here, so this is probably
the better group.

> I want to give a numpy ndarray as an argument to a c++ method,
> calculate something and return the output as an ndarray to Python.
> I would prefer not to use another library (such as PyUblas) for this
> so I do not have to add another dependency to my program.

I did this myself last year, and here's what I can tell you.

> 1. Is boost python still maintained or should I switch to another tool.

Yes it is maintained.

> 2. Is numpy supported, and if so,

Yes and no.  Boost.Python has a header for dealing with Numeric arrays
that works just as well with NumPy.
<http://www.boost.org/doc/libs/1_40_0/libs/python/doc/v2/numeric.html>.
  But it works by passing all methods through the Python interpreter, so
you will see no increase in speed compared to using a more low-level
NumPy API.

There is num_util header created by a third-party that claims to do a
lot of the wrapping.
<http://www.eos.ubc.ca/research/clouds/software/pythonlibs/num_util/num_util_release2/>
  I ended up not using it, but instead going getting using NumPy's C API
directly and keeping the pointers wrapped in boost::python::handle
objects as much as possible.

> 3. can someone give me a basic example of how to use it.

The num_util page has an example of their code.

--
Anthony Foglia
Princeton Consultants
(609) 987-8787 x233

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: Numpy ndarray as argument or return value using boost python

by Stefan Seefeld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/12/2009 11:36 AM, Pim Schellart wrote:

> Hi Everyone,
>
> I also posted this to the boost users list.
> I tried to find a good example for this but after spending two days on
> google and one day getting pyublas to compile I decided to call for
> help.
> I want to give a numpy ndarray as an argument to a c++ method,
> calculate something and return the output as an ndarray to Python.
> I would prefer not to use another library (such as PyUblas) for this
> so I do not have to add another dependency to my program.
> Since the latest information on boost python is quite outdated (uses
> numeric) I would like to know the following.
>
> 1. Is boost python still maintained or should I switch to another tool.
>    

Boost.Python is definitely maintained.

> 2. Is numpy supported, and if so,
>    

That is a good question, to which I don't have an answer. In fact, I
submitted an issue about the docs
(https://svn.boost.org/trac/boost/ticket/3340), as a first step to
getting an up-to-date picture.
Meanwhile, I have written my own wrapper for PyArray, as the existing
one is by far not enough for my needs. (In particular, I need direct
memory access.)

I would be happy to share this code and move it into boost.python, if in
fact everyone agrees that what exists should be replaced.

David, Ralf, do you have an opinion on this ?


> 3. can someone give me a basic example of how to use it.
>    


Regards,
         Stefan

--

       ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: Numpy ndarray as argument or return value using boost python

by Ravi-41 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 12 October 2009 11:36:20 Pim Schellart wrote:
> 1. Is boost python still maintained or should I switch to another tool.
> 2. Is numpy supported, and if so,
> 3. can someone give me a basic example of how to use it.

Please see
 http://mail.python.org/pipermail/cplusplus-sig/2008-October/013825.html
which supports numpy arrays with and without copying, along with pass by
reference and pass by value.

Regards,
Ravi

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig