Hi all,

I've spent the day writing a Numpy format handler in Cython and thought
there were a few things that the Cython numpy tutorial possibly should
cover:

    * Numpy dtype references appear to be normally "borrowed" references
      in the C API, so when you call numpy array functions that take a
      dtype you need to Py_INCREF the dtype first, this will show up as
      complaints from numpy that you're trying to delete the dtype objects
    * You have to call import_array() in your module or many of the
      Numpy C API entry points will segfault

for the first issue:

cdef extern from "Python.h":
    cdef void Py_INCREF( object )
...
        Py_INCREF( typecode )
        return PyArray_Zeros( c_dims.shape[0],
<np.Py_intptr_t>c_dims.data, typecode, 0 )

for the second issue:

cdef extern from "numpy/arrayobject.h":
    cdef void import_array()
...
import_array()

Anyway, not sure if or where such changes should go, but just thought it
might help others.

Enjoy,
Mike

-- 
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to