[Numpy-discussion] Best way to expose std::vector to be used with numpy
njs at pobox.com
Tue Oct 14 07:39:22 EDT 2014
If the goal is to have something that works kind of like the new buffer
protocol but with a wider variety of python versions, then you might find
the old array interface useful:
I always get confused by the history here but I believe that that's the
numpy-only interface that later got cleaned up and generalized to become
the new buffer interface. Numpy itself still supports it.
On 14 Oct 2014 11:19, "Daniele Nicolodi" <daniele at grinta.net> wrote:
> On 14/10/14 04:39, Charles R Harris wrote:
> > On Mon, Oct 13, 2014 at 12:54 PM, Sebastian Berg
> > <sebastian at sipsolutions.net <mailto:sebastian at sipsolutions.net>> wrote:
> > On Mo, 2014-10-13 at 13:35 +0200, Daniele Nicolodi wrote:
> > > Hello,
> > >
> > > I have a C++ application that collects float, int or complex data
> in a
> > > possibly quite large std::vector. The application has some SWIG
> > > generated python wrappers that expose this vector to python.
> > > the standard way in which SWIG exposes the data is to create a
> > > and pass this to python, where it is very often converted to a
> > > array for processing. Of course this is not efficient.
> > >
> > > I would like therefore to generate a smarter python interface. In
> > > 3 I would without doubt go for implementing the buffer protocol,
> > > enables seamless interfacing with numpy. However, I need to
> support also
> > > python 2 and there the buffer protocol is not as nice.
> > Isn't the new buffer protocol in python 2.6 or 2.7 already? There is
> > least a memoryview object in python 2, which maybe could be used to
> > same effect?
> > No memoryview in python2.6, but the older buffer protocol it there. Is
> > Boost Python an option?
> The old buffer protocol is an option, but it is much less nice than the
> new one, as it requires to use numpy.frombuffer() with an exlicit dtype
> instead of the siumpler numpy.asarray() sufficient in python 3.
> Boost Python may be an option as the codebase already depends on Boost,
> but probably not yet on Boost Python. Can you point me to the relevant
> documentation, and maybe to an example? One of the problems I have is
> that the current wrapping is done auto-magically with SWIG and I would
> like to deviate the less possible from that patter.
> Thank you!
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion