← Back to team overview

dolfin team mailing list archive

Re: [HG DOLFIN] Added slicing capabilities for GenericVector interface in PyDOLFIN:

 

On Friday 17 April 2009 09:47:27 Anders Logg wrote:
> On Fri, Apr 17, 2009 at 09:25:16AM +0200, Johan Hake wrote:
> > On Friday 17 April 2009 09:20:20 DOLFIN wrote:
> > > One or more new changesets pushed to the primary dolfin repository.
> > > A short summary of the last three changesets is included below.
> > >
> > > changeset:   6003:010f9db3ecb7456374a12e3510ff1c93847d5f6b
> > > tag:         tip
> > > user:        "Johan Hake <hake@xxxxxxxxx>"
> > > date:        Fri Apr 17 09:20:16 2009 +0200
> > > files:       ChangeLog dolfin/swig/dolfin_la_post.i
> > > dolfin/swig/dolfin_la_pre.i test/unit/la/python/test.py description:
> > > Added slicing capabilities for GenericVector interface in PyDOLFIN:
> > >
> > >    We can now e.g. do things like:
> > >       v = Vector(10)
> > >       v[:] = 1.0
> > >       v[0:10:2] = 2.0
> > >       v[0:10:2] = v[1:10:2]
> > >       v[[0,3,4,6,9]] = v[1:10:2]
> > >
> > >    in the PyDOLFIN interface. A sliced Vector returns a copy of the old
> > > Vector. I have added a bunch of tests that covers some user cases, but
> > > please report any missbehaviours.
> >
> > This is a nice feature that makes python programming more smooth. The
> > implementation is done totally in an extended c++ layer of the proxy
> > classes in swig.
> >
> > There are some code duplications, which probably could be eliminated, and
> > it does not support numpy arrays on the right hand side, but this could
> > be added in the future.
> >
> > Cheers!
> >
> > Johan
>
> That's really cool. Can you do the same for matrices?

Probably, I did not need it though ;)

However I am not sure how we should treat the sparse matrices. 

Maybe the GenericTensor.{set,get} functions chould be used? I did not use this 
when I implemented it for Vectors, but it should be possible to use these 
functions here too I suppose.

Johan


References