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

numpy-svn@scip... numpy-svn@scip...
Thu Jun 19 23:17:56 CDT 2008


Author: fperez
Date: 2008-06-19 23:17:54 -0500 (Thu, 19 Jun 2008)
New Revision: 5301

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


Modified: trunk/numpy/doc/cython/c_numpy.pxd
===================================================================
--- trunk/numpy/doc/cython/c_numpy.pxd	2008-06-20 00:18:32 UTC (rev 5300)
+++ trunk/numpy/doc/cython/c_numpy.pxd	2008-06-20 04:17:54 UTC (rev 5301)
@@ -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 @@
     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 00:18:32 UTC (rev 5300)
+++ trunk/numpy/doc/cython/numpyx.pyx	2008-06-20 04:17:54 UTC (rev 5301)
@@ -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
 



More information about the Numpy-svn mailing list