dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #17808
Re: Python and std::vector (again)
On Sunday 07 March 2010 06:07:58 Garth N. Wells wrote:
> Anders Logg wrote:
> > On Sun, Mar 07, 2010 at 12:11:53PM +0000, Garth N. Wells wrote:
> >> I've added the function
> >>
> >> GenericVector::sum(const std::vector<uint>& rows)
> >>
> >> which will sum the given row entries. But, frustratingly, it doesn't
> >> work through Python. I can't pass a list or numpy array to it. I get the
> >> error
> >>
> >> TypeError: in method 'GenericVector_sum', argument 2 of type
> >> 'std::vector< dolfin::uint > const &'
> >>
> >> How can I pass a list of integers to this function from Python? It seems
> >> that we haven't resolved passing std::vector from Python to C++
> >> satisfactorily.
> >>
> >> Garth
> >
> > Why std::vector? I thought we discussed replacing it with
> > dolfin::Array in the interface so that it would map easily to Python
> > which would let us remove the std::vector typemaps.
>
> dolfin::Array doesn't work either.
This is because these typemaps needed to be instantiated per argument name. I
have now added "greedy" (argument independent) typemaps for all
const Array<{uint,int,double}> & foo
arguments, using the typemap macro. I guess _all_ const Array argument of the
above primitive types can safely be passed using NumPy arrays. It should now
just work for all argument names of the above types.
We still cannot do this for all Array arguments, as some might be turned into
an argout typemap, which needs to be treated independently. But again I do not
have the whole overview of these cases (if any).
It should now be possible to change all const std::vector<{uint,int,double}>&
foo to Array, and the above mentioned typemap should kick in.
Johan
Follow ups
References