[Numpy-discussion] numpy C API bugs?

David Ian Brown dbrown at ucar.edu
Thu Mar 9 16:59:01 CST 2006

On Mar 9, 2006, at 4:56 PM, David Ian Brown wrote:

> 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  
> 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.

Correction: actually "Guide to NumPy" has the 'getitem' function  
documented with the arguments ordered
as  implemented in NumPy (but still opposite from Numeric). Only the  
macro is documented opposite from
its implementation.

> I hope this is useful.
>  -dave
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting  
> language
> that extends applications into web and mobile media. Attend the live  
> webcast
> and join the prime developer group breaking into this new coding  
> territory!
> http://sel.as-us.falkag.net/sel? 
> cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion

More information about the Numpy-discussion mailing list