[C++-sig] Moving "decorator" into C++ part of module

Matthieu Brucher matthieu.brucher at gmail.com
Thu Jul 12 11:52:05 CEST 2007


Hi,

Sorry to unearth this thread, but I'd like convert numpy array as well, but
not only for matrices (my lab uses multi-dimensional images in C++ and it
could be great to have a non-copying wrapper to Python and from Python).
I'm very new to Boost.Python and to the numpy C-API, I hope I'll not ask
stupid questions.

In your code, Albert, you wrap a uBlas matrix in array_struct__. Is there
some kind of reference counting for the memory allocated in the matrix ? Or
the matrix must be valid until the python variable is destroyed ?
If this is the case, is there a "simple" way of using smart pointers (if the
class that must be wrapped uses smart pointers for holding the data) ?

Matthieu

2007/5/21, Albert Strasheim <fullung at gmail.com>:
>
> Howdy
>
> On Mon, 21 May 2007, Neal Becker wrote:
>
> > Albert Strasheim wrote:
> >
> > > Hello all
> > >
> > > I have a class with various methods that return uBLAS matrices. I've
> > > wrapped various instantiations of these matrices with:
> > >
> > [...]
> >
> > I'm very interested in this.
> >
> > I thought array_interface was only a proposal at this point.  You are
> using
> > it?  If I have python2.5, do I need something to try this out?  (Like,
> > where is the array_interface include file?)
>
> NumPy's array interface is ready to go. I think you might be thinking
> about the enhanced buffer protocol PEP thing.
>
> > Could you post a complete code that shows how you convert ublas::matrix
> to
> > numpy?  Do you have converters in the other direction?
>
> Code attached. This is still very much a work in progress. Test it with:
>
> import numpy as N
> import os
>
> from numpy.testing import *
> # directory where you compiled the module
> set_local_path(os.path.join('..', 'win_build', 'Debug'))
> import pyublas
> restore_path()
>
> at = pyublas.array_test()
> print at
> print at.ref_return()
> print at.const_ref_return()
> print at.pointer_return()
> print at.const_pointer_return()
>
> As you can see, I can now convert return types (just haven't implemented
> return by-value yet). Now that I understand call policies properly, I'm
> going to look at converting arguments.
>
> Cheers,
>
> Albert
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070712/b973c08a/attachment.htm>


More information about the Cplusplus-sig mailing list