← Back to team overview

dolfin team mailing list archive

Re: GenericVector assignment in PyDOLFIN

 


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()[:]

? Is x a numpy array?

Garth


> Johan
>   
>   





Follow ups

References