[Numpy-discussion] numpy C API bugs?

David Ian Brown dbrown at ucar.edu
Thu Mar 9 15:57:04 EST 2006


Hi Travis and NumPy developers,

I have recently been engaged in updating the PyNIO module 
(http://www.pyngl.ucar.edu/Nio.html)
to work with the NumPy C API. It was originally coded using the 
Numeric's C API.

In the process I have encountered what appear to me to be a couple of  
bugs in the interface.  They were relatively minor  and not  difficult 
to work around, but you would probably like to know of them if you 
don't already.

In the NumPy version of arrayobject.h the macros PyArray_GETITEM and 
PyArray_SETITEM
are defined in way that does not work.  Here is the GETITEM macro:

  #define PyArray_GETITEM(obj,itemptr)                    \
        ((char *)itemptr,       \
                                           (PyArrayObject *)obj);

When I try to use this macro in my code I get a compile error, because 
'getitem' is not a member of NumPy's
PyArray_Descr struct. Instead it is further nested within the struct 
member 'PyArray_ArrFuncs *f'.
So, unless I misunderstand, the macro needs to access the 'getitem' 
function as

((PyArrayObject *)(obj))->descr->f->getitem(...

The other issue with 'getitem', apparently the actual method, not just 
this macro, is that the 2 arguments are
ordered oppositely from what is stated in  "Guide To NumPy",  as well 
as from the way this method was
implemented in Numeric.  Notice in the macro (and in NumPy's  
implementation), 'itemptr' is first and
the PyArrayObject pointer is second. The documentation and Numeric has 
it the other way around.

I hope this is useful.
  -dave





More information about the NumPy-Discussion mailing list