← Back to team overview

dolfin team mailing list archive

Re: std::vector& in Python

 

On Tuesday February 22 2011 09:38:24 Garth N. Wells wrote:
> On 22/02/11 17:35, Johan Hake wrote:
> > What is the signature?
> > 
> > Have you tried using:
> >   PY_SEQUENCE_OF_SCALARS_TO_VECTOR_OF_PRIMITIVES(TYPE,
> >   
> >                                                  TYPE_UPPER,
> >                                                  ARG_NAME,
> > 						 
> > 						 TYPE_NAME,
> > 						 
> >                                                  SEQ_LENGTH)
> > 
> > Look at the end of std_vector_typemaps.i for example of its use.
> > 
> > Then you can pass any iterable for the values.
> > 
> > If you want to expose
> > 
> >    add_cell(uint c, const std::vector<uint>& v)
> 
> That's the one.
> 
> > You should be able to use something like:
> >   IN_TYPEMAP_STD_VECTOR_OF_PRIMITIVES(dolfin::uint, INT32,
> >   
> >                                       v, NPY_UINT, uint, I)
> 
> Where should I put it?

At the end of std_vector_typemaps.i, together with the other typemap 
initializations.

As we are copying the data anyhow for the std::vector typemaps you might want 
to change the interface to passed by value instead. Then you can use the first 
typemap for any iterative of integers.

> Winding this back, is it desirable to wrap std::vector, or should we use
> Array in the C++ interface?

I have no particular preferences here. If you change to Array you can use the 
function from Python using NumPy array without copying.

But I gues this is not a performance issue.

Johan

> Garth
> 
> > Johan
> > 
> > On Tuesday February 22 2011 09:29:24 Garth N. Wells wrote:
> >> I tried to use a function in MeshEditor from the Python interface, but
> >> failed because it expects a const std::vector<uint>&. What's the status
> >> of wrapping small std::vectors? Should it work, or should the C++
> >> interface be changed to use a dolfin::Array?
> >> 
> >> Garth
> >> 
> >> _______________________________________________
> >> Mailing list: https://launchpad.net/~dolfin
> >> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> >> Unsubscribe : https://launchpad.net/~dolfin
> >> More help   : https://help.launchpad.net/ListHelp



References