Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-06-09 08:58:57

"Neal D. Becker" <nbecker_at_[hidden]> writes:

> Is this the right place to ask boost python questions?

This is OK; the C++-sig ( is
better. I'm cross-posting there.

> I'm interested in getting started with boost python. I would need a
> way to comminicate containers of data between python and c++. My
> domain is signal processing.

Sounds good so far.

> In c++, algorithms usually have an STLsyle iterator interface, and
> concrete containers are usually std::vector. In python numarray
> might be used.


> What options are available to interface between an (efficient)
> python-accessible container and c++ stl-style containers?

What kind of interface did you have in mind? I mean, there are a lot
of options in C++ and Python . You can fairly easily expose STL
containers to Python. Then you can use them together with numarray
arrays from Python. Perhaps you had something else in mind?

> I noticed the boost::python tutorial has a brief discussion of
> iterators. I guess this would suggest a strategy of using vector
> for containers with an iterator interface for python to access them.
> But this doesn't give any way for python to create or manage the
> containers.

Hmm? vector<X> for any X is just a class you can wrap like any
other, and then you can construct it from Python like any other. Am
I missing something?

> Is the reverse a feasible solution? Use python numarray containers and pass
> iterators to c++ algorithms for computation?

Do you know how to get iterators out of a numarray? Probably you can
easily get pointers, which are fine. So, sure, you can do that.
You'd want to expose thin wrapper functions which accept
boost::python::array arguments and then unpackage the iterators to
pass on to the algorithms.


Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at