[Numpy-discussion] indexing bug?

Robert Kern robert.kern@gmail....
Wed Oct 3 13:18:01 CDT 2007


Timothy Hochberg wrote:

> As I understand it, the whole point of PEP-357 was to allow the coercion
> of int-like things (numpy.int32 say, or your own private integerish
> class) to be used as indices without also allowing things that aren't
> integers, but that can be coerced to integers (floats for instance) to
> slip through. So yes, I'd say this is a bug. Probably someplace that
> should be using __index__ or the C equivalent is still using __int__,
> but I haven't had time to look.

I believe the problem is in numpy/core/src/arrayobject.c:

 2635 static PyObject *
 2636 array_subscript_simple(PyArrayObject *self, PyObject *op)
 2637 {
 2638     intp dimensions[MAX_DIMS], strides[MAX_DIMS];
 2639     intp offset;
 2640     int nd;
 2641     PyArrayObject *other;
 2642     intp value;
 2643
 2644     value = PyArray_PyIntAsIntp(op);

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco


More information about the Numpy-discussion mailing list