dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #15287
Re: [Bug 427047] Re: Vector indexing in Python with NumPy indices
On Thu, Sep 10, 2009 at 09:55:06AM -0000, Johan Hake wrote:
> On Thursday 10 September 2009 11:34:05 logg wrote:
> > On Thu, Sep 10, 2009 at 08:56:02AM -0000, Johan Hake wrote:
> > > This should be fixed now. Unfortunately does not
> > >
> > > x[long(0)]
> > >
> > > work. When is this needed?
> > >
> > > Johan
> >
> > Does not seem to work for me:
> >
> > File "reconstruction.py", line 102, in _extract_patch_values
> > print x[dofs[0]]
> > File
> >
> > "/home/logg/scratch/src/fenics-dev/dolfin-dev/local/lib/python2.6/site-pac
> > kages/dolfin/cpp.py", line 1843, in __getitem__
> > return _get_vector_single_item(self, indices)
> > File
> >
> > "/home/logg/scratch/src/fenics-dev/dolfin-dev/local/lib/python2.6/site-pac
> > kages/dolfin/cpp.py", line 5481, in _get_vector_single_item
> > return _cpp._get_vector_single_item(*args)
> > TypeError: expected 'int' for argument 2
> >
> > When I print type(dofs[0]) I get
> >
> > <type 'numpy.uint32'>
>
> Ok, then you should refine your bug report. It does not say anything about
> numpy.uint32... ;)
>
> Will check.
Sorry about that.
> > Even stranger, it still doesn't work when I do
> >
> > x[int(dofs[0])]
> >
> > But it does work if I do
> >
> > x[int(int(dofs[0]))]
> >
> > int() does not seem to be idempotent!!!
>
> Not so strange if you concider this:
>
> class A(int):
> def __int__(self):
> return 2
>
> class B(int):
> def __int__(self):
> return A(2)
>
> b = B()
>
> print type(b)
> print type(int(b))
> print type(int(int(b)))
Aha!
--
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