diff options
Diffstat (limited to 'numpy/doc/cython')
-rw-r--r-- | numpy/doc/cython/c_numpy.pxd | 11 | ||||
-rw-r--r-- | numpy/doc/cython/numpyx.pyx | 11 |
2 files changed, 16 insertions, 6 deletions
diff --git a/numpy/doc/cython/c_numpy.pxd b/numpy/doc/cython/c_numpy.pxd index 11cb8fac9..08fd8d86e 100644 --- a/numpy/doc/cython/c_numpy.pxd +++ b/numpy/doc/cython/c_numpy.pxd @@ -1,5 +1,8 @@ # :Author: Travis Oliphant +# API declaration section. This basically exposes the NumPy C API to +# Pyrex/Cython programs. + cdef extern from "numpy/arrayobject.h": cdef enum NPY_TYPES: @@ -131,3 +134,11 @@ cdef extern from "numpy/arrayobject.h": void PyArray_ITER_NEXT(flatiter it) void import_array() + +######################################################################## +# Other code (mostly initialization) + +# NumPy must be initialized before any user code is called in the extension +# module. By doing so here, we ensure the users don't have to explicitly +# remember this themselves, and provide a cleaner Cython API. +import_array() diff --git a/numpy/doc/cython/numpyx.pyx b/numpy/doc/cython/numpyx.pyx index bc6f90498..b410e9c4c 100644 --- a/numpy/doc/cython/numpyx.pyx +++ b/numpy/doc/cython/numpyx.pyx @@ -2,16 +2,15 @@ """Cython access to Numpy arrays - simple example. """ -# Import the pieces of the Python C API we need to use (from c_python.pxd): +# Load the pieces of the Python C API we need to use (from c_python.pxd). Note +# that a 'cimport' is similart to a Python 'import' statement, but it provides +# access to the C part of a library instead of its Python-visible API. Please +# consult the Pyrex/Cython documentation for further details. cimport c_python as py -# Import the NumPy C API (from c_numpy.pxd) +# (C)Import the NumPy C API (from c_numpy.pxd) cimport c_numpy as cnp -################################################ -# Initialize numpy - this MUST be done before any other code is executed. -cnp.import_array() - # Import the NumPy module for access to its usual Python API import numpy as np |