Happy marriage of std::vector and Python array?

Hi all, We're looking to share some heavy-weight numerical data in a mixed language C++/Python environment. boost::python::numeric::array provides a C++ binding for the Python numeric array. However, we'd prefer to have an STL compatible (std::vector compatible) interface to the data, rather than python-ising our C++. The underlying runtime issue is to store one copy of the contiguous 1D data in a way that both C++ and Python can read and write, that will follow the Python memory management scheme. Has anyone come across a std::vector compatible wrapper for PyArrayObject? Any thoughts? Cheers, Nigel Stewart

Nigel Stewart wrote:
Hi all,
We're looking to share some heavy-weight numerical data in a mixed language C++/Python environment.
boost::python::numeric::array provides a C++ binding for the Python numeric array. However, we'd prefer to have an STL compatible (std::vector compatible) interface to the data, rather than python-ising our C++.
The underlying runtime issue is to store one copy of the contiguous 1D data in a way that both C++ and Python can read and write, that will follow the Python memory management scheme.
Has anyone come across a std::vector compatible wrapper for PyArrayObject? Any thoughts?
I've been using a wrapper for boost::ublas.

Nigel Stewart wrote:
Has anyone come across a std::vector compatible wrapper for PyArrayObject? Any thoughts?
I've been using a wrapper for boost::ublas.
That sounds interesting. Is it your own wrapper?
Nigel
I put some code here: http://nbecker.dyndns.org:8080/uvector.cc There are some headers missing - I hope this gives you the general idea though. Also, I have modified boost ublas slightly.

I've been using a wrapper for boost::ublas. That sounds interesting. Is it your own wrapper?
I put some code here: http://nbecker.dyndns.org:8080/uvector.cc
Oh, I see. Did you consider using a PyArrayObject as the storage for a boost::numeric::ublas::vector? The advantage with that would be all the Numeric/Numarray/Numpy functionality in Python, with a boost::numeric::ublas::vector interface in C++. Cheers, Nigel

Nigel Stewart wrote:
I've been using a wrapper for boost::ublas. That sounds interesting. Is it your own wrapper?
I put some code here: http://nbecker.dyndns.org:8080/uvector.cc
Oh, I see.
Did you consider using a PyArrayObject as the storage for a boost::numeric::ublas::vector? The advantage with that would be all the Numeric/Numarray/Numpy functionality in Python, with a boost::numeric::ublas::vector interface in C++.
No. Any code sample? My goal was to give python an interface to algorithms written in c++. The algs are generic, but to talk to python I have to choose concrete containers. I chose ublas::vector in hopes that would also be convenient for c++. I don't know what using PyArrayObject would imply, do you?

Nigel Stewart <ns@fluent.com> writes:
I've been using a wrapper for boost::ublas. That sounds interesting. Is it your own wrapper?
I put some code here: http://nbecker.dyndns.org:8080/uvector.cc
Oh, I see.
Did you consider using a PyArrayObject as the storage for a boost::numeric::ublas::vector? The advantage with that would be all the Numeric/Numarray/Numpy functionality in Python, with a boost::numeric::ublas::vector interface in C++.
FWIW, you'll get more answers in the C++-sig (http://www.boost.org/more/mailing_lists.htm#cplussig) -- Dave Abrahams Boost Consulting www.boost-consulting.com

FWIW, you'll get more answers in the C++-sig (http://www.boost.org/more/mailing_lists.htm#cplussig)
Thanks for pointing me in the right direction... By the way... The link to the C++-sig on this page appears to be stale, it has moved from http://www.python.org/sigs/c++-sig/ to http://www.python.org/community/sigs/current/c++-sig/

Nigel Stewart <ns@fluent.com> writes:
Hi all,
We're looking to share some heavy-weight numerical data in a mixed language C++/Python environment.
boost::python::numeric::array provides a C++ binding for the Python numeric array. However, we'd prefer to have an STL compatible (std::vector compatible) interface to the data, rather than python-ising our C++.
The underlying runtime issue is to store one copy of the contiguous 1D data in a way that both C++ and Python can read and write, that will follow the Python memory management scheme.
Has anyone come across a std::vector compatible wrapper for PyArrayObject? Any thoughts?
It's easy enough to write one. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (3)
-
David Abrahams
-
Neal Becker
-
Nigel Stewart