diff options
author | Fernando Perez <fperez@fperez.org> | 2008-06-20 04:17:54 +0000 |
---|---|---|
committer | Fernando Perez <fperez@fperez.org> | 2008-06-20 04:17:54 +0000 |
commit | e4b8851b2dbe54ccc0ee8080cc05449b3771676a (patch) | |
tree | 18e64b2d1a84d5dba88fbc2a0d28ddfb14e55825 /numpy/doc | |
parent | d2a19ae95c831d093cc5097e4643d2f9e813fe22 (diff) | |
download | numpy-e4b8851b2dbe54ccc0ee8080cc05449b3771676a.tar.gz |
Move the import_array() call directly into c_numpy.pxd.
This makes the user-visible API for Cython usage simpler and closer to
the Python one.
Diffstat (limited to 'numpy/doc')
-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 |