[Numpy-discussion] PyArray_FROM_OF from Cython

Dag Sverre Seljebotn dagss@student.matnat.uio...
Fri Oct 9 03:47:43 CDT 2009

David Warde-Farley wrote:
> On 8-Oct-09, at 6:47 PM, Robert Kern wrote:
>> On Thu, Oct 8, 2009 at 17:28, David Warde-Farley  
>> <dwf@cs.toronto.edu> wrote:
>>> I'm trying to use PyArray_FROM_OF from Cython and the generated C  
>>> code
>>> keeps crashing.  Dag said on the Cython list that he wasn't sure what
>>> was going on, so maybe someone here will have an idea.
>> You must call import_array() at the top level before you can use any
>> numpy C API functions.
>> http://wiki.cython.org/tutorials/numpy#UsingtheNumpyCAPI
> Thanks. One more thing: calling Py_DECREF on arrays that I have  
> acquired from PyArray_FROM_OF seems to cause crashes, am I correct in  
> assuming that Cython is somehow tracking all the PyObjects in the  
> scope (even ones acquired via the NumPy C API) and DECREF'ing it for me?

If the function is declared with "object" as return type (or nothing 
which defaults to the same thing), then Cython will interpret that as 
the function handing away the reference of the object and make sure it 
is decref-ed.

Dag Sverre

More information about the NumPy-Discussion mailing list