diff options
-rw-r--r-- | numpy/doc/cython/c_numpy.pxd | 8 | ||||
-rw-r--r-- | numpy/doc/cython/numpyx.pyx | 22 |
2 files changed, 16 insertions, 14 deletions
diff --git a/numpy/doc/cython/c_numpy.pxd b/numpy/doc/cython/c_numpy.pxd index 08fd8d86e..4a0bd1c01 100644 --- a/numpy/doc/cython/c_numpy.pxd +++ b/numpy/doc/cython/c_numpy.pxd @@ -134,11 +134,3 @@ 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 b410e9c4c..cbc786ef0 100644 --- a/numpy/doc/cython/numpyx.pyx +++ b/numpy/doc/cython/numpyx.pyx @@ -2,18 +2,28 @@ """Cython access to Numpy arrays - simple example. """ -# 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. +############################################################################# +# Load C APIs declared in .pxd files via cimport +# +# A 'cimport' is similar to a Python 'import' statement, but it provides access +# to the C part of a library instead of its Python-visible API. See the +# Pyrex/Cython documentation for details. + cimport c_python as py -# (C)Import the NumPy C API (from c_numpy.pxd) cimport c_numpy as cnp -# Import the NumPy module for access to its usual Python API +# NOTE: numpy MUST be initialized before any other code is executed. +cnp.import_array() + +############################################################################# +# Load Python modules via normal import statements + import numpy as np +############################################################################# +# Regular code section begins + # A 'def' function is visible in the Python-imported module def print_array_info(cnp.ndarray arr): """Simple information printer about an array. |