[Numpy-svn] r5303 - trunk/numpy/doc/cython

numpy-svn@scip... numpy-svn@scip...
Fri Jun 20 13:24:13 CDT 2008


Author: fperez
Date: 2008-06-20 13:24:10 -0500 (Fri, 20 Jun 2008)
New Revision: 5303

Modified:
   trunk/numpy/doc/cython/c_numpy.pxd
   trunk/numpy/doc/cython/numpyx.pyx
Log:
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.



Modified: trunk/numpy/doc/cython/c_numpy.pxd
===================================================================
--- trunk/numpy/doc/cython/c_numpy.pxd	2008-06-20 05:59:26 UTC (rev 5302)
+++ trunk/numpy/doc/cython/c_numpy.pxd	2008-06-20 18:24:10 UTC (rev 5303)
@@ -134,11 +134,3 @@
     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()

Modified: trunk/numpy/doc/cython/numpyx.pyx
===================================================================
--- trunk/numpy/doc/cython/numpyx.pyx	2008-06-20 05:59:26 UTC (rev 5302)
+++ trunk/numpy/doc/cython/numpyx.pyx	2008-06-20 18:24:10 UTC (rev 5303)
@@ -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.



More information about the Numpy-svn mailing list