Forzar a NumPy ndarray a tomar posesión de su memoria en Cython

Siguiendoesta respuesta a "¿Puedo obligar a un ndarray numpy a tomar posesión de su memoria?" Intenté usar la función Python C APIPyArray_ENABLEFLAGS a través del envoltorio NumPy de Cython y descubrió que no está expuesto.

El siguiente intento de exponerlo manualmente (este es solo un ejemplo mínimo que reproduce la falla)

from libc.stdlib cimport malloc
import numpy as np
cimport numpy as np

np.import_array()

ctypedef np.int32_t DTYPE_t

cdef extern from "numpy/ndarraytypes.h":
    void PyArray_ENABLEFLAGS(np.PyArrayObject *arr, int flags)

def test():
    cdef int N = 1000

    cdef DTYPE_t *data = <DTYPE_t *>malloc(N * sizeof(DTYPE_t))
    cdef np.ndarray[DTYPE_t, ndim=1] arr = np.PyArray_SimpleNewFromData(1, &N, np.NPY_INT32, data)
    PyArray_ENABLEFLAGS(arr, np.NPY_ARRAY_OWNDATA)

falla con un error de compilación:

Error compiling Cython file:
------------------------------------------------------------
...
def test():
    cdef int N = 1000

    cdef DTYPE_t *data = <DTYPE_t *>malloc(N * sizeof(DTYPE_t))
    cdef np.ndarray[DTYPE_t, ndim=1] arr = np.PyArray_SimpleNewFromData(1, &N, np.NPY_INT32, data)
    PyArray_ENABLEFLAGS(arr, np.NPY_ARRAY_OWNDATA)
                          ^
------------------------------------------------------------

/tmp/test.pyx:19:27: Cannot convert Python object to 'PyArrayObject *'

Mi pregunta: ¿Es este el enfoque correcto para tomar en este caso? Si es así, ¿qué estoy haciendo mal? Si no es así, ¿cómo forzo a NumPy a tomar posesión de Cython sin pasar a un módulo de extensión C?

Respuestas a la pregunta(1)

Su respuesta a la pregunta