← Back to team overview

dolfin team mailing list archive

Re: x[:] syntax for DOLFIN vectors

 

On Wednesday December 21 2011 19:33:23 Johan Hake wrote:
> On Wednesday December 21 2011 18:00:23 Garth N. Wells wrote:
> > What happens behind the scenes when for
> > 
> >    x = Vector(100)
> > 
> > ones does
> > 
> >   x[:]
> > 
> > ?
> 
> That depends if x[:] is on the lhs or on the rhs. If it is on the rhs a
> copy will be returned. This is a slice convention in Python.
> 
>   l0 = range(5)
>   l1 = l[:]
>   l1[0] = 1

For clarity:

   l0 = range(5)
   l1 = l0[:]
   l1[0] = 2

:)

Johan

> The last statement will change l1 but not l0. I would expect the same for
> dolfin vectors.
> 
> If it is on lhs and the rhs is either a GeneriVector or a scalar,
> x._assign(rhs) will be envoked.
> 
> The relevant methods in la_post.i are:
> 
>   def __getslice__(...):
>   def __setslize__(...):
> 
> Johan
> 
> > I've added GenericVector operator+= and -= for doubles, and would like
> > to be sure that this can be used from Python without unnecessary
> > copies being made.
> > 
> > Garth
> > 
> > _______________________________________________
> > Mailing list: https://launchpad.net/~dolfin
> > Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~dolfin
> > More help   : https://help.launchpad.net/ListHelp
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp


References