← Back to team overview

dolfin team mailing list archive

Re: GenericVector assignment in PyDOLFIN

 

On Saturday 23 January 2010 14:55:08 Garth N. Wells wrote:
> Johan Hake wrote:
> > On Saturday 23 January 2010 08:42:14 Garth N. Wells wrote:
> >> Is it correct that behind the scenes that
> >>
> >>   U0 = Function(V)
> >>   U  = Function(V)
> >>   U0.vector()[:] = U.vector()[:]
> >>
> >> involves a GenericVector::get(..) call and a GenericVector::set(..)
> >> call? If so, it isn't ideal since it introduces unnecessary new/delete
> >> operations and unnecessary copying of data.
> >
> > None of GenericVector::get(..) or GenericVector::set(..) are invoked, see
> > __getslice__ and __setslice__ in la_post.i.
> >
> >    U0.vector()[:]
> >
> > involves
> >
> >   GenericVector::operator =(..)
> >
> > and
> >
> >   U.vector()[:]
> >
> > involves
> >
> >   GenericVector::copy()
> >
> > However the latter is unnecessary as you instead can do:
> >
> >   U0.vector()[:] = U.vector()
> >
> > invoking the assignment operator of U0's vector with U's vector.
> 
> What happens if I do
> 
>   x = U.vector()[:]

It just triggers the copy method of GenericVector, which is the same behavior 
as for other itterable Python types.

> ? Is x a numpy array?

No you need to call array() to accomplish that.

Johan

> Garth
> 
> > Johan
> 



Follow ups

References