summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Perez <fperez@fperez.org>2008-06-19 06:16:48 +0000
committerFernando Perez <fperez@fperez.org>2008-06-19 06:16:48 +0000
commitab3df7fc073fe57d493fbb07929365dd232a7643 (patch)
tree175d3be6cde0df6691f8fa5378569ac995da2fce
parent19da971bf18e3528f9c42d4c26715cb158f9b97b (diff)
downloadnumpy-ab3df7fc073fe57d493fbb07929365dd232a7643.tar.gz
Updated Cython code to use .pxd files with cimport instead of .pxi/include.
Using cimport/pxd is the currently recommended approach by the Cython team.
-rw-r--r--numpy/doc/cython/Makefile2
-rw-r--r--numpy/doc/cython/c_numpy.pxd (renamed from numpy/doc/cython/numpy.pxi)0
-rw-r--r--numpy/doc/cython/c_python.pxd (renamed from numpy/doc/cython/Python.pxi)0
-rw-r--r--numpy/doc/cython/numpyx.pyx40
4 files changed, 21 insertions, 21 deletions
diff --git a/numpy/doc/cython/Makefile b/numpy/doc/cython/Makefile
index 80be2c066..7c9c72981 100644
--- a/numpy/doc/cython/Makefile
+++ b/numpy/doc/cython/Makefile
@@ -24,7 +24,7 @@ numpyx.so: numpyx.pyx numpyx.c
numpyx.pyx.html: numpyx.pyx
cython -a numpyx.pyx
- @echo "Annotated HTML of the C code generated in numpy.pyx.html"
+ @echo "Annotated HTML of the C code generated in numpyx.html"
# Phony targets for cleanup and similar uses
diff --git a/numpy/doc/cython/numpy.pxi b/numpy/doc/cython/c_numpy.pxd
index 11cb8fac9..11cb8fac9 100644
--- a/numpy/doc/cython/numpy.pxi
+++ b/numpy/doc/cython/c_numpy.pxd
diff --git a/numpy/doc/cython/Python.pxi b/numpy/doc/cython/c_python.pxd
index 46d2fd1a7..46d2fd1a7 100644
--- a/numpy/doc/cython/Python.pxi
+++ b/numpy/doc/cython/c_python.pxd
diff --git a/numpy/doc/cython/numpyx.pyx b/numpy/doc/cython/numpyx.pyx
index 84dc333df..bc6f90498 100644
--- a/numpy/doc/cython/numpyx.pyx
+++ b/numpy/doc/cython/numpyx.pyx
@@ -2,21 +2,21 @@
"""Cython access to Numpy arrays - simple example.
"""
-# Includes from the python headers
-include "Python.pxi"
-# Include the Numpy C API for use via Cython extension code
-include "numpy.pxi"
+# Import the pieces of the Python C API we need to use (from c_python.pxd):
+cimport c_python as py
+
+# 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.
-import_array()
+cnp.import_array()
-# Import the Numpy module for access to its usual Python API
+# Import the NumPy module for access to its usual Python API
import numpy as np
-
# A 'def' function is visible in the Python-imported module
-def print_array_info(ndarray arr):
+def print_array_info(cnp.ndarray arr):
"""Simple information printer about an array.
Code meant to illustrate Cython/NumPy integration only."""
@@ -24,19 +24,19 @@ def print_array_info(ndarray arr):
cdef int i
print '-='*10
- # Note: the double cast here (void * first, then Py_intptr_t) is needed in
- # Cython but not in Pyrex, since the casting behavior of cython is slightly
- # different (and generally safer) than that of Pyrex. In this case, we
- # just want the memory address of the actual Array object, so we cast it to
- # void before doing the Py_intptr_t cast:
+ # Note: the double cast here (void * first, then py.Py_intptr_t) is needed
+ # in Cython but not in Pyrex, since the casting behavior of cython is
+ # slightly different (and generally safer) than that of Pyrex. In this
+ # case, we just want the memory address of the actual Array object, so we
+ # cast it to void before doing the py.Py_intptr_t cast:
print 'Printing array info for ndarray at 0x%0lx'% \
- (<Py_intptr_t><void *>arr,)
+ (<py.Py_intptr_t><void *>arr,)
print 'number of dimensions:',arr.nd
- print 'address of strides: 0x%0lx'%(<Py_intptr_t>arr.strides,)
+ print 'address of strides: 0x%0lx'%(<py.Py_intptr_t>arr.strides,)
print 'strides:'
for i from 0<=i<arr.nd:
# print each stride
- print ' stride %d:'%i,<Py_intptr_t>arr.strides[i]
+ print ' stride %d:'%i,<py.Py_intptr_t>arr.strides[i]
print 'memory dump:'
print_elements( arr.data, arr.strides, arr.dimensions,
arr.nd, sizeof(double), arr.dtype )
@@ -46,12 +46,12 @@ def print_array_info(ndarray arr):
# A 'cdef' function is NOT visible to the python side, but it is accessible to
# the rest of this Cython module
cdef print_elements(char *data,
- Py_intptr_t* strides,
- Py_intptr_t* dimensions,
+ py.Py_intptr_t* strides,
+ py.Py_intptr_t* dimensions,
int nd,
int elsize,
object dtype):
- cdef Py_intptr_t i,j
+ cdef py.Py_intptr_t i,j
cdef void* elptr
if dtype not in [np.dtype(np.object_),
@@ -78,7 +78,7 @@ cdef print_elements(char *data,
print_elements(data, strides+1, dimensions+1, nd-1, elsize, dtype)
data = data + strides[0]
-def test_methods(ndarray arr):
+def test_methods(cnp.ndarray arr):
"""Test a few attribute accesses for an array.
This illustrates how the pyrex-visible object is in practice a strange