[Numpy-discussion] PyArray_SETITEM with object arrays in Cython

Dag Sverre Seljebotn dagss@student.matnat.uio...
Wed Feb 11 14:25:09 CST 2009


Wes McKinney wrote:
> 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*.

Interesting. Whatever you end up doing, I'll make sure to integrate
whatever works faster into Cython.

I do doubt your results a bit though -- the buffer interface in Cython
increfs/decrefs the objects, but otherwise it should be completely raw
access, so using SETITEM shouldn't be faster except one INCREF/DECREF per
object (i.e. still way faster than using Python).

Could you perhaps post your Cython code?

Dag Sverre



More information about the Numpy-discussion mailing list