← 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 01:16:57PM -0000, Johan Hake wrote:
> > 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.
>
> Try now...
>
> numpy c-api is not fun...

I understand your pain.

> Feel free to close the bug if it works.

Works now! Thanks! I'll close the way.

Something I still can't do is the following. It's related but it may
be more of a feature request than a bug report. I'll just post it here
and we can open a new bug report if you think it's a bug:

Works:

  for i in range(n):
    x[cell_dofs[i]] = coefficients[i]

Does not work:

   x[cell_dofs] = coefficients

--
Anders


** Changed in: dolfin
       Status: New => Fix Committed

-- 
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: Fix Committed

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