← Back to team overview

dolfin team mailing list archive

Re: [Bug 427047] Re: Vector indexing in Python with NumPy indices

 

On Thu, Sep 10, 2009 at 12:01:47PM -0000, Johan Hake wrote:
> > Still breaks for me:
> >
> > from dolfin import Vector
> > from numpy import zeros
> >
> > x = Vector(10)
> > i = zeros(10, "I")
> >
> > x[i[0]] = 1.0
> >
> > in __setitem__(self, indices, values)
> >    3802                 raise TypeError, "provide a scalar,
> >    GenericVector or numpy array of float to set items in Vector"
> >    3803         else:
> > -> 3804             raise TypeError, "index must be an int, slice or a
> > list or numpy array of integers"
> >    3805
> >    3806     def __len__(self):
> >
> > TypeError: index must be an int, slice or a list or numpy array of
> > integers
>
> You keep refining your bug reports your bugger! ;)
>
> That should also be fixed now...
>
> Johan

Works now!

Now if only I could also get values from a vector directly from a
Python list or Python array of numpy.uint32... :-)

This fails:

  values = x[dofs]
  values = x[numpy.array(dofs)]

But this works:

  values = [x[dof] for dof in dofs]

dofs is a Python list of numpy.uint32.

--
Anders

-- 
Vector indexing in Python with NumPy indices
https://bugs.launchpad.net/bugs/427047
You received this bug notification because you are subscribed to DOLFIN.

Status in DOLFIN: New

Bug description:
The following breaks:

import dolfin, numpy

x = Vector(10)

print x[numpy.int32(0)]
print x[numpy.int64(0)]
print x[numpy.array((0, 1), dtype='I')

The typechecks in la_post.i looks like they can be expanded. (I tried it myself but couldn't get it working correctly.)


Follow ups

References