Johan Hake wrote: > On Monday 22 June 2009 10:51:49 Ola Skavhaug wrote: >> On Mon, Jun 22, 2009 at 10:44 AM, Garth N. Wells<gn...@cam.ac.uk> wrote: >>> Johan Hake wrote: >>>> On Saturday 20 June 2009 13:10:46 Garth N. Wells wrote: >>>>> I tried to do >>>>> >>>>> u0.vector() = u1.vector() >>>>> >>>>> where u0 and u1 are both discrete functions, in PyDOLFIN but it doesn't >>>>> work so I'm using >>>>> >>>>> u0.vector().assign( u1.vector() ) >>>> This is the correct way to do it. Assignment operators are just ignored >>>> for the dynamically typed languges supported by SWIG. We therefore >>>> rename the foo.operator= to foo.assign. >>>> >>>> However for the Vector and Matrix interfaces we also support the numpy >>>> lookalike assignment: >>>> >>>> v[:] = u >>>> >>>> and >>>> >>>> A[:,:] = B >>>> >>>> I have talked to Anders about removing both v.assign and v.set(double *) >>>> and "force" the PyDOLFIN users to use the numpy assignments. >>> Is there any difference in performance between the two? >>> >>> Garth >> The slicing means that the actual memory of A is overwritten. I guess >> that is the same as the operator= did before? >> Hence, I guess there will be no big difference. > > When I implemented the slicing operator I assumed that the operator= would be > fastes when a full vector is copied, a la: > > v[:] = u, > > because the operator= can use optimized functions from the underlaying la > library, for example VecCopy for PETSc. So I added a check for this in the > python slicing operator. If a full slice is assigned, as above, we use the > assign method, otherwise we use the set(const double*, uint, const uint*) > method. >
OK, nice. Garth > Johan > >> Ola >> >>>> Johan >>>> >>>>> Is there a fundamental reason why '=' can't be used or does SWIG just >>>>> need to be told how to overload '=' for vectors? >>>>> >>>>> Garth >>>>> _______________________________________________ >>>>> DOLFIN-dev mailing list >>>>> DOLFIN-dev@fenics.org >>>>> http://www.fenics.org/mailman/listinfo/dolfin-dev >>> _______________________________________________ >>> DOLFIN-dev mailing list >>> DOLFIN-dev@fenics.org >>> http://www.fenics.org/mailman/listinfo/dolfin-dev > > _______________________________________________ DOLFIN-dev mailing list DOLFIN-dev@fenics.org http://www.fenics.org/mailman/listinfo/dolfin-dev