[Numpy-discussion] PyArray_SETITEM with object arrays in Cython

Hanni Ali hanni.ali@gmail....
Wed Feb 11 11:24:01 CST 2009


Hi Wes,

I do not profess to be an expert, but I have been off loading a fair number
of loops to C from Python code and achieved significant improvements most
have been of the following form (which I have found to be the fastest):

size = *incomingArrayObj->dimensions;

r_dptr = PyArray_DATA(resultArray);

while(size--) {
    r_dptr = result;
    r_dptr++;
}

Where for multidimensional arrays r_dptr could be incremented by the number
of dims rather than just ++:

dims = PyArray_DIM(incomingArrayObj,1);

i have not however actually used PyArray_SETITEM so cannot comment on the
issue you are having.

Hanni



2009/2/11 Wes McKinney <wesmckinn@gmail.com>

> Hello,
>
> I am writing some Cython code and have noted that the buffer interface
> offers very little speedup for PyObject arrays. In trying to rewrite the
> same code using the C API in Cython, I find I can't get PyArray_SETITEM to
> work, in a call like:
>
> PyArray_SETITEM(result, <void *> iterresult.dataptr, obj)
>
> where result is an ndarray of dtype object, and obj is a PyObject*.
>
> Anyone have some experience with this can offer pointers (no pun
> intended!)?
>
> Thanks,
> Wes
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090211/5eb53fa0/attachment.html 


More information about the Numpy-discussion mailing list