← Back to team overview

dolfin team mailing list archive

Re: x[:] syntax for DOLFIN vectors

 


On 21 Dec 2011, at 18:33, Johan Hake <johan.hake@xxxxxxxxx> 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
> 
> 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.

What if I do

  x[:] += 1.0

?

Garth

> 
> 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


Follow ups

References