summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorFernando Perez <fperez@fperez.org>2008-06-20 18:24:10 +0000
committerFernando Perez <fperez@fperez.org>2008-06-20 18:24:10 +0000
commitd2d7e7f47eec9ab9575b231f2a3805b788b778ae (patch)
tree3638d55eb91fb21ad40248384a1d406d44b707d0 /numpy
parente4b8851b2dbe54ccc0ee8080cc05449b3771676a (diff)
downloadnumpy-d2d7e7f47eec9ab9575b231f2a3805b788b778ae.tar.gz
Put import_array() back into the .pyx file.
M. Brett noticed that if it's only in the .pxd file, it does NOT get included in the auto-generated C code, and will thus not be called at module initialization time.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/doc/cython/c_numpy.pxd8
-rw-r--r--numpy/doc/cython/numpyx.pyx22
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.