summaryrefslogtreecommitdiff
path: root/numpy/doc/numpybook/comparison
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/doc/numpybook/comparison')
-rw-r--r--numpy/doc/numpybook/comparison/ctypes/code.c60
-rw-r--r--numpy/doc/numpybook/comparison/ctypes/filter.py26
-rw-r--r--numpy/doc/numpybook/comparison/ctypes/interface.py60
-rw-r--r--numpy/doc/numpybook/comparison/ctypes/newfile.datbin0 -> 800 bytes
-rwxr-xr-xnumpy/doc/numpybook/comparison/ctypes/timeme2
-rw-r--r--numpy/doc/numpybook/comparison/f2py/add.f45
-rw-r--r--numpy/doc/numpybook/comparison/f2py/add.pyf34
-rw-r--r--numpy/doc/numpybook/comparison/f2py/filter.f20
-rw-r--r--numpy/doc/numpybook/comparison/f2py/filter.pyf16
-rw-r--r--numpy/doc/numpybook/comparison/f2py/filtermodule.c293
-rwxr-xr-xnumpy/doc/numpybook/comparison/f2py/timeme1
-rw-r--r--numpy/doc/numpybook/comparison/pyrex/add.c560
-rw-r--r--numpy/doc/numpybook/comparison/pyrex/add.pyx75
-rw-r--r--numpy/doc/numpybook/comparison/pyrex/c_numpy.pxd106
-rw-r--r--numpy/doc/numpybook/comparison/pyrex/filter.c388
-rw-r--r--numpy/doc/numpybook/comparison/pyrex/filter.pyx44
-rw-r--r--numpy/doc/numpybook/comparison/pyrex/setup.py29
-rwxr-xr-xnumpy/doc/numpybook/comparison/pyrex/timeme2
-rw-r--r--numpy/doc/numpybook/comparison/timing.py63
-rw-r--r--numpy/doc/numpybook/comparison/weave/filter.py23
-rw-r--r--numpy/doc/numpybook/comparison/weave/inline.py49
-rwxr-xr-xnumpy/doc/numpybook/comparison/weave/timeme2
22 files changed, 1898 insertions, 0 deletions
diff --git a/numpy/doc/numpybook/comparison/ctypes/code.c b/numpy/doc/numpybook/comparison/ctypes/code.c
new file mode 100644
index 000000000..0927a7ed3
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/ctypes/code.c
@@ -0,0 +1,60 @@
+
+typedef struct {double real; double imag;} cdouble;
+typedef struct {double real; double imag;} cfloat;
+
+/* Add arrays of contiguous data */
+void zadd(cdouble *a, cdouble *b, cdouble *c, long n)
+{
+ while (n--) {
+ c->real = a->real + b->real;
+ c->imag = a->imag + b->imag;
+ a++; b++; c++;
+ }
+}
+
+void cadd(cfloat *a, cfloat *b, cfloat *c, long n)
+{
+ while (n--) {
+ c->real = a->real + b->real;
+ c->imag = a->imag + b->imag;
+ a++; b++; c++;
+ }
+}
+
+void dadd(double *a, double *b, double *c, long n)
+{
+ while (n--) {
+ *c++ = *a++ + *b++;
+ }
+}
+
+void sadd(float *a, float *b, float *c, long n)
+{
+ while (n--) {
+ *c++ = *a++ + *b++;
+ }
+}
+
+/* Assumes b is contiguous and
+ a has strides that are multiples of sizeof(double)
+*/
+void dfilter2d(double *a, double *b, int *astrides, int *dims)
+{
+ int i, j, M, N, S0, S1;
+ int r, c, rm1, rp1, cp1, cm1;
+
+ M = dims[0]; N = dims[1];
+ S0 = astrides[0]/sizeof(double);
+ S1=astrides[1]/sizeof(double);
+ for (i=1; i<M-1; i++) {
+ r = i*S0; rp1 = r+S0; rm1 = r-S0;
+ for (j=1; j<N-1; j++) {
+ c = j*S1; cp1 = j+S1; cm1 = j-S1;
+ b[i*N+j] = a[r+c] + \
+ (a[rp1+c] + a[rm1+c] + \
+ a[r+cp1] + a[r+cm1])*0.5 + \
+ (a[rp1+cp1] + a[rp1+cm1] + \
+ a[rm1+cp1] + a[rm1+cp1])*0.25;
+ }
+ }
+}
diff --git a/numpy/doc/numpybook/comparison/ctypes/filter.py b/numpy/doc/numpybook/comparison/ctypes/filter.py
new file mode 100644
index 000000000..e92aa5eab
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/ctypes/filter.py
@@ -0,0 +1,26 @@
+__all__ = ['filter2d']
+
+import numpy as N
+import os
+import ctypes
+
+_path = os.path.dirname('__file__')
+lib = N.ctypeslib.load_library('code', _path)
+
+lib.dfilter2d.restype = None
+lib.dfilter2d.argtypes = [N.ctypeslib.ndpointer(float, ndim=2,
+ flags='aligned'),
+ N.ctypeslib.ndpointer(float, ndim=2,
+ flags='aligned, contiguous,'\
+ 'writeable'),
+ ctypes.POINTER(N.ctypeslib.c_intp),
+ ctypes.POINTER(N.ctypeslib.c_intp)]
+
+def filter2d(a):
+ a = N.require(a, float, ['ALIGNED'])
+ b = N.zeros_like(a)
+ lib.dfilter2d(a, b, a.ctypes.strides, a.ctypes.shape)
+ return b
+
+
+
diff --git a/numpy/doc/numpybook/comparison/ctypes/interface.py b/numpy/doc/numpybook/comparison/ctypes/interface.py
new file mode 100644
index 000000000..06c12aef3
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/ctypes/interface.py
@@ -0,0 +1,60 @@
+__all__ = ['add', 'filter2d']
+
+import numpy as N
+import os
+import ctypes
+
+_path = os.path.dirname('__file__')
+lib = N.ctypeslib.load_library('code', _path)
+_typedict = {'zadd' : complex,
+ 'sadd' : N.single,
+ 'cadd' : N.csingle,
+ 'dadd' : float}
+for name in _typedict.keys():
+ val = getattr(lib, name)
+ val.restype = None
+ _type = _typedict[name]
+ val.argtypes = [N.ctypeslib.ndpointer(_type, flags='aligned, contiguous'),
+ N.ctypeslib.ndpointer(_type, flags='aligned, contiguous'),
+ N.ctypeslib.ndpointer(_type, flags='aligned, contiguous,'\
+ 'writeable'),
+ N.ctypeslib.c_intp]
+
+lib.dfilter2d.restype=None
+lib.dfilter2d.argtypes = [N.ctypeslib.ndpointer(float, ndim=2,
+ flags='aligned'),
+ N.ctypeslib.ndpointer(float, ndim=2,
+ flags='aligned, contiguous,'\
+ 'writeable'),
+ ctypes.POINTER(N.ctypeslib.c_intp),
+ ctypes.POINTER(N.ctypeslib.c_intp)]
+
+def select(dtype):
+ if dtype.char in ['?bBhHf']:
+ return lib.sadd, N.single
+ elif dtype.char in ['F']:
+ return lib.cadd, N.csingle
+ elif dtype.char in ['DG']:
+ return lib.zadd, complex
+ else:
+ return lib.dadd, float
+ return func, ntype
+
+def add(a, b):
+ requires = ['CONTIGUOUS', 'ALIGNED']
+ a = N.asanyarray(a)
+ func, dtype = select(a.dtype)
+ a = N.require(a, dtype, requires)
+ b = N.require(b, dtype, requires)
+ c = N.empty_like(a)
+ func(a,b,c,a.size)
+ return c
+
+def filter2d(a):
+ a = N.require(a, float, ['ALIGNED'])
+ b = N.zeros_like(a)
+ lib.dfilter2d(a, b, a.ctypes.strides, a.ctypes.shape)
+ return b
+
+
+
diff --git a/numpy/doc/numpybook/comparison/ctypes/newfile.dat b/numpy/doc/numpybook/comparison/ctypes/newfile.dat
new file mode 100644
index 000000000..d3899c294
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/ctypes/newfile.dat
Binary files differ
diff --git a/numpy/doc/numpybook/comparison/ctypes/timeme b/numpy/doc/numpybook/comparison/ctypes/timeme
new file mode 100755
index 000000000..2f7cd297f
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/ctypes/timeme
@@ -0,0 +1,2 @@
+python2.4 -m timeit -s "import numpy as N; a=N.random.rand(100,200); import filter" "b = filter.filter(a)"
+
diff --git a/numpy/doc/numpybook/comparison/f2py/add.f b/numpy/doc/numpybook/comparison/f2py/add.f
new file mode 100644
index 000000000..26e45da34
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/f2py/add.f
@@ -0,0 +1,45 @@
+C
+ SUBROUTINE ZADD(A,B,C,N)
+C
+ DOUBLE COMPLEX A(*)
+ DOUBLE COMPLEX B(*)
+ DOUBLE COMPLEX C(*)
+ INTEGER N
+ DO 20 J = 1, N
+ C(J) = A(J) + B(J)
+ 20 CONTINUE
+ END
+
+ SUBROUTINE CADD(A,B,C,N)
+C
+ COMPLEX A(*)
+ COMPLEX B(*)
+ COMPLEX C(*)
+ INTEGER N
+ DO 20 J = 1, N
+ C(J) = A(J) + B(J)
+ 20 CONTINUE
+ END
+
+ SUBROUTINE DADD(A,B,C,N)
+C
+ DOUBLE PRECISION A(*)
+ DOUBLE PRECISION B(*)
+ DOUBLE PRECISION C(*)
+ INTEGER N
+ DO 20 J = 1, N
+ C(J) = A(J) + B(J)
+ 20 CONTINUE
+ END
+
+ SUBROUTINE SADD(A,B,C,N)
+C
+ REAL A(*)
+ REAL B(*)
+ REAL C(*)
+ INTEGER N
+ DO 20 J = 1, N
+ C(J) = A(J) + B(J)
+ 20 CONTINUE
+ END
+
diff --git a/numpy/doc/numpybook/comparison/f2py/add.pyf b/numpy/doc/numpybook/comparison/f2py/add.pyf
new file mode 100644
index 000000000..1a9ac2c9e
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/f2py/add.pyf
@@ -0,0 +1,34 @@
+! -*- f90 -*-
+! Note: the context of this file is case sensitive.
+
+python module add ! in
+ interface ! in :add
+ subroutine zadd(a,b,c,n) ! in :add:add.f
+ double complex dimension(n) :: a
+ double complex dimension(n) :: b
+ double complex intent(out), dimension(n) :: c
+ integer intent(hide), depend(a) :: n = len(a)
+ end subroutine zadd
+ subroutine cadd(a,b,c,n) ! in :add:add.f
+ complex dimension(*) :: a
+ complex dimension(*) :: b
+ complex dimension(*) :: c
+ integer :: n
+ end subroutine cadd
+ subroutine dadd(a,b,c,n) ! in :add:add.f
+ double precision dimension(*) :: a
+ double precision dimension(*) :: b
+ double precision dimension(*) :: c
+ integer :: n
+ end subroutine dadd
+ subroutine sadd(a,b,c,n) ! in :add:add.f
+ real dimension(*) :: a
+ real dimension(*) :: b
+ real dimension(*) :: c
+ integer :: n
+ end subroutine sadd
+ end interface
+end python module add
+
+! This file was auto-generated with f2py (version:2_2694).
+! See http://cens.ioc.ee/projects/f2py2e/
diff --git a/numpy/doc/numpybook/comparison/f2py/filter.f b/numpy/doc/numpybook/comparison/f2py/filter.f
new file mode 100644
index 000000000..a817a866f
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/f2py/filter.f
@@ -0,0 +1,20 @@
+
+ SUBROUTINE DFILTER2D(A,B,M,N)
+C
+ DOUBLE PRECISION A(M,N)
+ DOUBLE PRECISION B(M,N)
+ INTEGER N, M
+CF2PY INTENT(OUT) :: B
+CF2PY INTENT(HIDE) :: N
+CF2PY INTENT(HIDE) :: M
+ DO 20 I = 2,M-1
+ DO 40 J=2,N-1
+ B(I,J) = A(I,J) +
+ $ (A(I-1,J)+A(I+1,J) +
+ $ A(I,J-1)+A(I,J+1) )*0.5D0 +
+ $ (A(I-1,J-1) + A(I-1,J+1) +
+ $ A(I+1,J-1) + A(I+1,J+1))*0.25D0
+ 40 CONTINUE
+ 20 CONTINUE
+ END
+
diff --git a/numpy/doc/numpybook/comparison/f2py/filter.pyf b/numpy/doc/numpybook/comparison/f2py/filter.pyf
new file mode 100644
index 000000000..1e4bc37f4
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/f2py/filter.pyf
@@ -0,0 +1,16 @@
+! -*- f90 -*-
+! Note: the context of this file is case sensitive.
+
+python module filter ! in
+ interface ! in :filter
+ subroutine dfilter2d(a,b,m,n) ! in :filter:filter.f
+ double precision dimension(m,n) :: a
+ double precision dimension(m,n),intent(out),depend(m,n) :: b
+ integer optional,intent(hide),check(shape(a,0)==m),depend(a) :: m=shape(a,0)
+ integer optional,intent(hide),check(shape(a,1)==n),depend(a) :: n=shape(a,1)
+ end subroutine dfilter2d
+ end interface
+end python module filter
+
+! This file was auto-generated with f2py (version:2_3032).
+! See http://cens.ioc.ee/projects/f2py2e/
diff --git a/numpy/doc/numpybook/comparison/f2py/filtermodule.c b/numpy/doc/numpybook/comparison/f2py/filtermodule.c
new file mode 100644
index 000000000..8339ad4b9
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/f2py/filtermodule.c
@@ -0,0 +1,293 @@
+/* File: filtermodule.c
+ * This file is auto-generated with f2py (version:2_3032).
+ * f2py is a Fortran to Python Interface Generator (FPIG), Second Edition,
+ * written by Pearu Peterson <pearu@cens.ioc.ee>.
+ * See http://cens.ioc.ee/projects/f2py2e/
+ * Generation date: Thu Aug 17 12:03:28 2006
+ * $Revision:$
+ * $Date:$
+ * Do not edit this file directly unless you know what you are doing!!!
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*********************** See f2py2e/cfuncs.py: includes ***********************/
+#include "Python.h"
+#include "fortranobject.h"
+#include <math.h>
+
+/**************** See f2py2e/rules.py: mod_rules['modulebody'] ****************/
+static PyObject *filter_error;
+static PyObject *filter_module;
+
+/*********************** See f2py2e/cfuncs.py: typedefs ***********************/
+/*need_typedefs*/
+
+/****************** See f2py2e/cfuncs.py: typedefs_generated ******************/
+/*need_typedefs_generated*/
+
+/********************** See f2py2e/cfuncs.py: cppmacros **********************/
+#if defined(PREPEND_FORTRAN)
+#if defined(NO_APPEND_FORTRAN)
+#if defined(UPPERCASE_FORTRAN)
+#define F_FUNC(f,F) _##F
+#else
+#define F_FUNC(f,F) _##f
+#endif
+#else
+#if defined(UPPERCASE_FORTRAN)
+#define F_FUNC(f,F) _##F##_
+#else
+#define F_FUNC(f,F) _##f##_
+#endif
+#endif
+#else
+#if defined(NO_APPEND_FORTRAN)
+#if defined(UPPERCASE_FORTRAN)
+#define F_FUNC(f,F) F
+#else
+#define F_FUNC(f,F) f
+#endif
+#else
+#if defined(UPPERCASE_FORTRAN)
+#define F_FUNC(f,F) F##_
+#else
+#define F_FUNC(f,F) f##_
+#endif
+#endif
+#endif
+#if defined(UNDERSCORE_G77)
+#define F_FUNC_US(f,F) F_FUNC(f##_,F##_)
+#else
+#define F_FUNC_US(f,F) F_FUNC(f,F)
+#endif
+
+#define rank(var) var ## _Rank
+#define shape(var,dim) var ## _Dims[dim]
+#define old_rank(var) (((PyArrayObject *)(capi_ ## var ## _tmp))->nd)
+#define old_shape(var,dim) (((PyArrayObject *)(capi_ ## var ## _tmp))->dimensions[dim])
+#define fshape(var,dim) shape(var,rank(var)-dim-1)
+#define len(var) shape(var,0)
+#define flen(var) fshape(var,0)
+#define size(var) PyArray_SIZE((PyArrayObject *)(capi_ ## var ## _tmp))
+/* #define index(i) capi_i ## i */
+#define slen(var) capi_ ## var ## _len
+
+#define CHECKSCALAR(check,tcheck,name,show,var)\
+ if (!(check)) {\
+ PyErr_SetString(filter_error,"("tcheck") failed for "name);\
+ fprintf(stderr,show"\n",var);\
+ /*goto capi_fail;*/\
+ } else
+#ifdef DEBUGCFUNCS
+#define CFUNCSMESS(mess) fprintf(stderr,"debug-capi:"mess);
+#define CFUNCSMESSPY(mess,obj) CFUNCSMESS(mess) \
+ PyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\
+ fprintf(stderr,"\n");
+#else
+#define CFUNCSMESS(mess)
+#define CFUNCSMESSPY(mess,obj)
+#endif
+
+#ifndef MAX
+#define MAX(a,b) ((a > b) ? (a) : (b))
+#endif
+#ifndef MIN
+#define MIN(a,b) ((a < b) ? (a) : (b))
+#endif
+
+
+/************************ See f2py2e/cfuncs.py: cfuncs ************************/
+/*need_cfuncs*/
+
+/********************* See f2py2e/cfuncs.py: userincludes *********************/
+/*need_userincludes*/
+
+/********************* See f2py2e/capi_rules.py: usercode *********************/
+
+
+/* See f2py2e/rules.py */
+extern void F_FUNC(dfilter2d,DFILTER2D)(double*,double*,int*,int*);
+/*eof externroutines*/
+
+/******************** See f2py2e/capi_rules.py: usercode1 ********************/
+
+
+/******************* See f2py2e/cb_rules.py: buildcallback *******************/
+/*need_callbacks*/
+
+/*********************** See f2py2e/rules.py: buildapi ***********************/
+
+/********************************* dfilter2d *********************************/
+static char doc_f2py_rout_filter_dfilter2d[] = "\
+Function signature:\n\
+ b = dfilter2d(a)\n\
+Required arguments:\n"
+" a : input rank-2 array('d') with bounds (m,n)\n"
+"Return objects:\n"
+" b : rank-2 array('d') with bounds (m,n)";
+/* extern void F_FUNC(dfilter2d,DFILTER2D)(double*,double*,int*,int*); */
+static PyObject *f2py_rout_filter_dfilter2d(const PyObject *capi_self,
+ PyObject *capi_args,
+ PyObject *capi_keywds,
+ void (*f2py_func)(double*,double*,int*,int*)) {
+ PyObject * volatile capi_buildvalue = NULL;
+ volatile int f2py_success = 1;
+/*decl*/
+
+ double *a = NULL;
+ npy_intp a_Dims[2] = {-1, -1};
+ const int a_Rank = 2;
+ PyArrayObject *capi_a_tmp = NULL;
+ int capi_a_intent = 0;
+ PyObject *a_capi = Py_None;
+ double *b = NULL;
+ npy_intp b_Dims[2] = {-1, -1};
+ const int b_Rank = 2;
+ PyArrayObject *capi_b_tmp = NULL;
+ int capi_b_intent = 0;
+ int m = 0;
+ int n = 0;
+ static char *capi_kwlist[] = {"a",NULL};
+
+/*routdebugenter*/
+#ifdef F2PY_REPORT_ATEXIT
+f2py_start_clock();
+#endif
+ if (!PyArg_ParseTupleAndKeywords(capi_args,capi_keywds,\
+ "O|:filter.dfilter2d",\
+ capi_kwlist,&a_capi))
+ return NULL;
+/*frompyobj*/
+ /* Processing variable a */
+ ;
+ capi_a_intent |= F2PY_INTENT_IN;
+ capi_a_tmp = array_from_pyobj(PyArray_DOUBLE,a_Dims,a_Rank,capi_a_intent,a_capi);
+ if (capi_a_tmp == NULL) {
+ if (!PyErr_Occurred())
+ PyErr_SetString(filter_error,"failed in converting 1st argument `a' of filter.dfilter2d to C/Fortran array" );
+ } else {
+ a = (double *)(capi_a_tmp->data);
+
+ /* Processing variable m */
+ m = shape(a,0);
+ CHECKSCALAR(shape(a,0)==m,"shape(a,0)==m","hidden m","dfilter2d:m=%d",m) {
+ /* Processing variable n */
+ n = shape(a,1);
+ CHECKSCALAR(shape(a,1)==n,"shape(a,1)==n","hidden n","dfilter2d:n=%d",n) {
+ /* Processing variable b */
+ b_Dims[0]=m,b_Dims[1]=n;
+ capi_b_intent |= F2PY_INTENT_OUT|F2PY_INTENT_HIDE;
+ capi_b_tmp = array_from_pyobj(PyArray_DOUBLE,b_Dims,b_Rank,capi_b_intent,Py_None);
+ if (capi_b_tmp == NULL) {
+ if (!PyErr_Occurred())
+ PyErr_SetString(filter_error,"failed in converting hidden `b' of filter.dfilter2d to C/Fortran array" );
+ } else {
+ b = (double *)(capi_b_tmp->data);
+
+/*end of frompyobj*/
+#ifdef F2PY_REPORT_ATEXIT
+f2py_start_call_clock();
+#endif
+/*callfortranroutine*/
+ (*f2py_func)(a,b,&m,&n);
+if (PyErr_Occurred())
+ f2py_success = 0;
+#ifdef F2PY_REPORT_ATEXIT
+f2py_stop_call_clock();
+#endif
+/*end of callfortranroutine*/
+ if (f2py_success) {
+/*pyobjfrom*/
+/*end of pyobjfrom*/
+ CFUNCSMESS("Building return value.\n");
+ capi_buildvalue = Py_BuildValue("N",capi_b_tmp);
+/*closepyobjfrom*/
+/*end of closepyobjfrom*/
+ } /*if (f2py_success) after callfortranroutine*/
+/*cleanupfrompyobj*/
+ } /*if (capi_b_tmp == NULL) ... else of b*/
+ /* End of cleaning variable b */
+ } /*CHECKSCALAR(shape(a,1)==n)*/
+ /* End of cleaning variable n */
+ } /*CHECKSCALAR(shape(a,0)==m)*/
+ /* End of cleaning variable m */
+ if((PyObject *)capi_a_tmp!=a_capi) {
+ Py_XDECREF(capi_a_tmp); }
+ } /*if (capi_a_tmp == NULL) ... else of a*/
+ /* End of cleaning variable a */
+/*end of cleanupfrompyobj*/
+ if (capi_buildvalue == NULL) {
+/*routdebugfailure*/
+ } else {
+/*routdebugleave*/
+ }
+ CFUNCSMESS("Freeing memory.\n");
+/*freemem*/
+#ifdef F2PY_REPORT_ATEXIT
+f2py_stop_clock();
+#endif
+ return capi_buildvalue;
+}
+/****************************** end of dfilter2d ******************************/
+/*eof body*/
+
+/******************* See f2py2e/f90mod_rules.py: buildhooks *******************/
+/*need_f90modhooks*/
+
+/************** See f2py2e/rules.py: module_rules['modulebody'] **************/
+
+/******************* See f2py2e/common_rules.py: buildhooks *******************/
+
+/*need_commonhooks*/
+
+/**************************** See f2py2e/rules.py ****************************/
+
+static FortranDataDef f2py_routine_defs[] = {
+ {"dfilter2d",-1,{{-1}},0,(char *)F_FUNC(dfilter2d,DFILTER2D),(f2py_init_func)f2py_rout_filter_dfilter2d,doc_f2py_rout_filter_dfilter2d},
+
+/*eof routine_defs*/
+ {NULL}
+};
+
+static PyMethodDef f2py_module_methods[] = {
+
+ {NULL,NULL}
+};
+
+PyMODINIT_FUNC initfilter(void) {
+ int i;
+ PyObject *m,*d, *s;
+ m = filter_module = Py_InitModule("filter", f2py_module_methods);
+ PyFortran_Type.ob_type = &PyType_Type;
+ import_array();
+ if (PyErr_Occurred())
+ Py_FatalError("can't initialize module filter (failed to import numpy)");
+ d = PyModule_GetDict(m);
+ s = PyString_FromString("$Revision: $");
+ PyDict_SetItemString(d, "__version__", s);
+ s = PyString_FromString("This module 'filter' is auto-generated with f2py (version:2_3032).\nFunctions:\n"
+" b = dfilter2d(a)\n"
+".");
+ PyDict_SetItemString(d, "__doc__", s);
+ filter_error = PyErr_NewException ("filter.error", NULL, NULL);
+ Py_DECREF(s);
+ for(i=0;f2py_routine_defs[i].name!=NULL;i++)
+ PyDict_SetItemString(d, f2py_routine_defs[i].name,PyFortranObject_NewAsAttr(&f2py_routine_defs[i]));
+
+/*eof initf2pywraphooks*/
+/*eof initf90modhooks*/
+
+/*eof initcommonhooks*/
+
+
+#ifdef F2PY_REPORT_ATEXIT
+ if (! PyErr_Occurred())
+ on_exit(f2py_report_on_exit,(void*)"filter");
+#endif
+
+}
+#ifdef __cplusplus
+}
+#endif
diff --git a/numpy/doc/numpybook/comparison/f2py/timeme b/numpy/doc/numpybook/comparison/f2py/timeme
new file mode 100755
index 000000000..d6ac5741e
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/f2py/timeme
@@ -0,0 +1 @@
+python2.4 -m timeit -s "import numpy as N; a=N.random.rand(100,200); import filter" "b=N.zeros_like(a); none = filter.DFILTER2D(a,b)"
diff --git a/numpy/doc/numpybook/comparison/pyrex/add.c b/numpy/doc/numpybook/comparison/pyrex/add.c
new file mode 100644
index 000000000..d5e3bd725
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/pyrex/add.c
@@ -0,0 +1,560 @@
+/* Generated by Pyrex 0.9.4.1 on Thu Aug 17 02:11:41 2006 */
+
+#include "Python.h"
+#include "structmember.h"
+#ifndef PY_LONG_LONG
+ #define PY_LONG_LONG LONG_LONG
+#endif
+#ifdef __cplusplus
+#define __PYX_EXTERN_C extern "C"
+#else
+#define __PYX_EXTERN_C extern
+#endif
+__PYX_EXTERN_C double pow(double, double);
+#include "numpy/arrayobject.h"
+
+
+typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
+typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
+static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
+static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
+static int __Pyx_PrintItem(PyObject *); /*proto*/
+static int __Pyx_PrintNewline(void); /*proto*/
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static void __Pyx_ReRaise(void); /*proto*/
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
+static PyObject *__Pyx_GetExcValue(void); /*proto*/
+static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
+static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
+static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
+static void __Pyx_WriteUnraisable(char *name); /*proto*/
+static void __Pyx_AddTraceback(char *funcname); /*proto*/
+static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size); /*proto*/
+static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
+static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
+static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
+static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static int __pyx_lineno;
+static char *__pyx_filename;
+static char **__pyx_f;
+
+/* Declarations from c_numpy */
+
+static PyTypeObject *__pyx_ptype_7c_numpy_dtype = 0;
+static PyTypeObject *__pyx_ptype_7c_numpy_ndarray = 0;
+
+/* Declarations from add */
+
+
+/* Implementation of add */
+
+static PyObject *__pyx_n_c_numpy;
+static PyObject *__pyx_n_zadd;
+static PyObject *__pyx_n_cadd;
+static PyObject *__pyx_n_dadd;
+static PyObject *__pyx_n_sadd;
+
+static PyObject *__pyx_f_3add_zadd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_f_3add_zadd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_ao = 0;
+ PyObject *__pyx_v_bo = 0;
+ PyArrayObject *__pyx_v_c;
+ PyArrayObject *__pyx_v_a;
+ PyArrayObject *__pyx_v_b;
+ npy_intp __pyx_v_i;
+ PyObject *__pyx_r;
+ PyObject *__pyx_1 = 0;
+ npy_intp __pyx_2;
+ static char *__pyx_argnames[] = {"ao","bo",0};
+ if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_ao, &__pyx_v_bo)) return 0;
+ Py_INCREF(__pyx_v_ao);
+ Py_INCREF(__pyx_v_bo);
+ __pyx_v_c = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_a = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_b = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":15 */
+ __pyx_1 = PyArray_ContiguousFromAny(__pyx_v_ao,NPY_CDOUBLE,1,1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_a));
+ __pyx_v_a = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":16 */
+ __pyx_1 = PyArray_ContiguousFromAny(__pyx_v_bo,NPY_CDOUBLE,1,1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_b));
+ __pyx_v_b = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":18 */
+ __pyx_1 = PyArray_SimpleNew(__pyx_v_a->nd,__pyx_v_a->dimensions,__pyx_v_a->descr->type_num); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_c));
+ __pyx_v_c = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":21 */
+ __pyx_2 = (__pyx_v_a->dimensions[0]);
+ for (__pyx_v_i = 0; __pyx_v_i < __pyx_2; ++__pyx_v_i) {
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":22 */
+ (((npy_cdouble (*))__pyx_v_c->data)[__pyx_v_i]).real = ((((npy_cdouble (*))__pyx_v_a->data)[__pyx_v_i]).real + (((npy_cdouble (*))__pyx_v_b->data)[__pyx_v_i]).real);
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":24 */
+ (((npy_cdouble (*))__pyx_v_c->data)[__pyx_v_i]).imag = ((((npy_cdouble (*))__pyx_v_a->data)[__pyx_v_i]).imag + (((npy_cdouble (*))__pyx_v_b->data)[__pyx_v_i]).imag);
+ __pyx_L2:;
+ }
+ __pyx_L3:;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":26 */
+ Py_INCREF(((PyObject *)__pyx_v_c));
+ __pyx_r = ((PyObject *)__pyx_v_c);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; Py_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1:;
+ Py_XDECREF(__pyx_1);
+ __Pyx_AddTraceback("add.zadd");
+ __pyx_r = 0;
+ __pyx_L0:;
+ Py_DECREF(__pyx_v_c);
+ Py_DECREF(__pyx_v_a);
+ Py_DECREF(__pyx_v_b);
+ Py_DECREF(__pyx_v_ao);
+ Py_DECREF(__pyx_v_bo);
+ return __pyx_r;
+}
+
+static PyObject *__pyx_f_3add_cadd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_f_3add_cadd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_ao = 0;
+ PyObject *__pyx_v_bo = 0;
+ PyArrayObject *__pyx_v_c;
+ PyArrayObject *__pyx_v_a;
+ PyArrayObject *__pyx_v_b;
+ npy_intp __pyx_v_i;
+ PyObject *__pyx_r;
+ PyObject *__pyx_1 = 0;
+ npy_intp __pyx_2;
+ static char *__pyx_argnames[] = {"ao","bo",0};
+ if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_ao, &__pyx_v_bo)) return 0;
+ Py_INCREF(__pyx_v_ao);
+ Py_INCREF(__pyx_v_bo);
+ __pyx_v_c = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_a = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_b = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":32 */
+ __pyx_1 = PyArray_ContiguousFromAny(__pyx_v_ao,NPY_CFLOAT,1,1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_a));
+ __pyx_v_a = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":33 */
+ __pyx_1 = PyArray_ContiguousFromAny(__pyx_v_bo,NPY_CFLOAT,1,1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_b));
+ __pyx_v_b = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":35 */
+ __pyx_1 = PyArray_SimpleNew(__pyx_v_a->nd,__pyx_v_a->dimensions,__pyx_v_a->descr->type_num); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_c));
+ __pyx_v_c = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":38 */
+ __pyx_2 = (__pyx_v_a->dimensions[0]);
+ for (__pyx_v_i = 0; __pyx_v_i < __pyx_2; ++__pyx_v_i) {
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":39 */
+ (((npy_cfloat (*))__pyx_v_c->data)[__pyx_v_i]).real = ((((npy_cfloat (*))__pyx_v_a->data)[__pyx_v_i]).real + (((npy_cfloat (*))__pyx_v_b->data)[__pyx_v_i]).real);
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":41 */
+ (((npy_cfloat (*))__pyx_v_c->data)[__pyx_v_i]).imag = ((((npy_cfloat (*))__pyx_v_a->data)[__pyx_v_i]).imag + (((npy_cfloat (*))__pyx_v_b->data)[__pyx_v_i]).imag);
+ __pyx_L2:;
+ }
+ __pyx_L3:;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":43 */
+ Py_INCREF(((PyObject *)__pyx_v_c));
+ __pyx_r = ((PyObject *)__pyx_v_c);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; Py_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1:;
+ Py_XDECREF(__pyx_1);
+ __Pyx_AddTraceback("add.cadd");
+ __pyx_r = 0;
+ __pyx_L0:;
+ Py_DECREF(__pyx_v_c);
+ Py_DECREF(__pyx_v_a);
+ Py_DECREF(__pyx_v_b);
+ Py_DECREF(__pyx_v_ao);
+ Py_DECREF(__pyx_v_bo);
+ return __pyx_r;
+}
+
+static PyObject *__pyx_f_3add_dadd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_f_3add_dadd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_ao = 0;
+ PyObject *__pyx_v_bo = 0;
+ PyArrayObject *__pyx_v_c;
+ PyArrayObject *__pyx_v_a;
+ PyArrayObject *__pyx_v_b;
+ npy_intp __pyx_v_i;
+ PyObject *__pyx_r;
+ PyObject *__pyx_1 = 0;
+ npy_intp __pyx_2;
+ static char *__pyx_argnames[] = {"ao","bo",0};
+ if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_ao, &__pyx_v_bo)) return 0;
+ Py_INCREF(__pyx_v_ao);
+ Py_INCREF(__pyx_v_bo);
+ __pyx_v_c = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_a = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_b = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":50 */
+ __pyx_1 = PyArray_ContiguousFromAny(__pyx_v_ao,NPY_DOUBLE,1,1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_a));
+ __pyx_v_a = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":51 */
+ __pyx_1 = PyArray_ContiguousFromAny(__pyx_v_bo,NPY_DOUBLE,1,1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_b));
+ __pyx_v_b = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":53 */
+ __pyx_1 = PyArray_SimpleNew(__pyx_v_a->nd,__pyx_v_a->dimensions,__pyx_v_a->descr->type_num); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_c));
+ __pyx_v_c = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":56 */
+ __pyx_2 = (__pyx_v_a->dimensions[0]);
+ for (__pyx_v_i = 0; __pyx_v_i < __pyx_2; ++__pyx_v_i) {
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":57 */
+ (((double (*))__pyx_v_c->data)[__pyx_v_i]) = ((((double (*))__pyx_v_a->data)[__pyx_v_i]) + (((double (*))__pyx_v_b->data)[__pyx_v_i]));
+ __pyx_L2:;
+ }
+ __pyx_L3:;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":59 */
+ Py_INCREF(((PyObject *)__pyx_v_c));
+ __pyx_r = ((PyObject *)__pyx_v_c);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; Py_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1:;
+ Py_XDECREF(__pyx_1);
+ __Pyx_AddTraceback("add.dadd");
+ __pyx_r = 0;
+ __pyx_L0:;
+ Py_DECREF(__pyx_v_c);
+ Py_DECREF(__pyx_v_a);
+ Py_DECREF(__pyx_v_b);
+ Py_DECREF(__pyx_v_ao);
+ Py_DECREF(__pyx_v_bo);
+ return __pyx_r;
+}
+
+static PyObject *__pyx_f_3add_sadd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_f_3add_sadd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_ao = 0;
+ PyObject *__pyx_v_bo = 0;
+ PyArrayObject *__pyx_v_c;
+ PyArrayObject *__pyx_v_a;
+ PyArrayObject *__pyx_v_b;
+ npy_intp __pyx_v_i;
+ PyObject *__pyx_r;
+ PyObject *__pyx_1 = 0;
+ npy_intp __pyx_2;
+ static char *__pyx_argnames[] = {"ao","bo",0};
+ if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_ao, &__pyx_v_bo)) return 0;
+ Py_INCREF(__pyx_v_ao);
+ Py_INCREF(__pyx_v_bo);
+ __pyx_v_c = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_a = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_b = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":66 */
+ __pyx_1 = PyArray_ContiguousFromAny(__pyx_v_ao,NPY_FLOAT,1,1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_a));
+ __pyx_v_a = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":67 */
+ __pyx_1 = PyArray_ContiguousFromAny(__pyx_v_bo,NPY_FLOAT,1,1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_b));
+ __pyx_v_b = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":69 */
+ __pyx_1 = PyArray_SimpleNew(__pyx_v_a->nd,__pyx_v_a->dimensions,__pyx_v_a->descr->type_num); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_c));
+ __pyx_v_c = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":72 */
+ __pyx_2 = (__pyx_v_a->dimensions[0]);
+ for (__pyx_v_i = 0; __pyx_v_i < __pyx_2; ++__pyx_v_i) {
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":73 */
+ (((float (*))__pyx_v_c->data)[__pyx_v_i]) = ((((float (*))__pyx_v_a->data)[__pyx_v_i]) + (((float (*))__pyx_v_b->data)[__pyx_v_i]));
+ __pyx_L2:;
+ }
+ __pyx_L3:;
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":75 */
+ Py_INCREF(((PyObject *)__pyx_v_c));
+ __pyx_r = ((PyObject *)__pyx_v_c);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; Py_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1:;
+ Py_XDECREF(__pyx_1);
+ __Pyx_AddTraceback("add.sadd");
+ __pyx_r = 0;
+ __pyx_L0:;
+ Py_DECREF(__pyx_v_c);
+ Py_DECREF(__pyx_v_a);
+ Py_DECREF(__pyx_v_b);
+ Py_DECREF(__pyx_v_ao);
+ Py_DECREF(__pyx_v_bo);
+ return __pyx_r;
+}
+
+static __Pyx_InternTabEntry __pyx_intern_tab[] = {
+ {&__pyx_n_c_numpy, "c_numpy"},
+ {&__pyx_n_cadd, "cadd"},
+ {&__pyx_n_dadd, "dadd"},
+ {&__pyx_n_sadd, "sadd"},
+ {&__pyx_n_zadd, "zadd"},
+ {0, 0}
+};
+
+static struct PyMethodDef __pyx_methods[] = {
+ {"zadd", (PyCFunction)__pyx_f_3add_zadd, METH_VARARGS|METH_KEYWORDS, 0},
+ {"cadd", (PyCFunction)__pyx_f_3add_cadd, METH_VARARGS|METH_KEYWORDS, 0},
+ {"dadd", (PyCFunction)__pyx_f_3add_dadd, METH_VARARGS|METH_KEYWORDS, 0},
+ {"sadd", (PyCFunction)__pyx_f_3add_sadd, METH_VARARGS|METH_KEYWORDS, 0},
+ {0, 0, 0, 0}
+};
+
+static void __pyx_init_filenames(void); /*proto*/
+
+PyMODINIT_FUNC initadd(void); /*proto*/
+PyMODINIT_FUNC initadd(void) {
+ __pyx_init_filenames();
+ __pyx_m = Py_InitModule4("add", __pyx_methods, 0, 0, PYTHON_API_VERSION);
+ if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
+ __pyx_b = PyImport_AddModule("__builtin__");
+ if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
+ if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
+ if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
+ __pyx_ptype_7c_numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr)); if (!__pyx_ptype_7c_numpy_dtype) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 74; goto __pyx_L1;}
+ __pyx_ptype_7c_numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject)); if (!__pyx_ptype_7c_numpy_ndarray) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; goto __pyx_L1;}
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":9 */
+ import_array();
+
+ /* "/Users/oliphant/numpybook/pyrex/add.pyx":62 */
+ return;
+ __pyx_L1:;
+ __Pyx_AddTraceback("add");
+}
+
+static char *__pyx_filenames[] = {
+ "add.pyx",
+ "c_numpy.pxd",
+};
+
+/* Runtime support code */
+
+static void __pyx_init_filenames(void) {
+ __pyx_f = __pyx_filenames;
+}
+
+static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
+ if (!type) {
+ PyErr_Format(PyExc_SystemError, "Missing type object");
+ return 0;
+ }
+ if (obj == Py_None || PyObject_TypeCheck(obj, type))
+ return 1;
+ PyErr_Format(PyExc_TypeError, "Cannot convert %s to %s",
+ obj->ob_type->tp_name, type->tp_name);
+ return 0;
+}
+
+static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
+ while (t->p) {
+ *t->p = PyString_InternFromString(t->s);
+ if (!*t->p)
+ return -1;
+ ++t;
+ }
+ return 0;
+}
+
+static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name,
+ long size)
+{
+ PyObject *py_module_name = 0;
+ PyObject *py_class_name = 0;
+ PyObject *py_name_list = 0;
+ PyObject *py_module = 0;
+ PyObject *result = 0;
+
+ py_module_name = PyString_FromString(module_name);
+ if (!py_module_name)
+ goto bad;
+ py_class_name = PyString_FromString(class_name);
+ if (!py_class_name)
+ goto bad;
+ py_name_list = PyList_New(1);
+ if (!py_name_list)
+ goto bad;
+ Py_INCREF(py_class_name);
+ if (PyList_SetItem(py_name_list, 0, py_class_name) < 0)
+ goto bad;
+ py_module = __Pyx_Import(py_module_name, py_name_list);
+ if (!py_module)
+ goto bad;
+ result = PyObject_GetAttr(py_module, py_class_name);
+ if (!result)
+ goto bad;
+ if (!PyType_Check(result)) {
+ PyErr_Format(PyExc_TypeError,
+ "%s.%s is not a type object",
+ module_name, class_name);
+ goto bad;
+ }
+ if (((PyTypeObject *)result)->tp_basicsize != size) {
+ PyErr_Format(PyExc_ValueError,
+ "%s.%s does not appear to be the correct type object",
+ module_name, class_name);
+ goto bad;
+ }
+ goto done;
+bad:
+ Py_XDECREF(result);
+ result = 0;
+done:
+ Py_XDECREF(py_module_name);
+ Py_XDECREF(py_class_name);
+ Py_XDECREF(py_name_list);
+ return (PyTypeObject *)result;
+}
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
+ PyObject *__import__ = 0;
+ PyObject *empty_list = 0;
+ PyObject *module = 0;
+ PyObject *global_dict = 0;
+ PyObject *empty_dict = 0;
+ PyObject *list;
+ __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
+ if (!__import__)
+ goto bad;
+ if (from_list)
+ list = from_list;
+ else {
+ empty_list = PyList_New(0);
+ if (!empty_list)
+ goto bad;
+ list = empty_list;
+ }
+ global_dict = PyModule_GetDict(__pyx_m);
+ if (!global_dict)
+ goto bad;
+ empty_dict = PyDict_New();
+ if (!empty_dict)
+ goto bad;
+ module = PyObject_CallFunction(__import__, "OOOO",
+ name, global_dict, empty_dict, list);
+bad:
+ Py_XDECREF(empty_list);
+ Py_XDECREF(__import__);
+ Py_XDECREF(empty_dict);
+ return module;
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+
+static void __Pyx_AddTraceback(char *funcname) {
+ PyObject *py_srcfile = 0;
+ PyObject *py_funcname = 0;
+ PyObject *py_globals = 0;
+ PyObject *empty_tuple = 0;
+ PyObject *empty_string = 0;
+ PyCodeObject *py_code = 0;
+ PyFrameObject *py_frame = 0;
+
+ py_srcfile = PyString_FromString(__pyx_filename);
+ if (!py_srcfile) goto bad;
+ py_funcname = PyString_FromString(funcname);
+ if (!py_funcname) goto bad;
+ py_globals = PyModule_GetDict(__pyx_m);
+ if (!py_globals) goto bad;
+ empty_tuple = PyTuple_New(0);
+ if (!empty_tuple) goto bad;
+ empty_string = PyString_FromString("");
+ if (!empty_string) goto bad;
+ py_code = PyCode_New(
+ 0, /*int argcount,*/
+ 0, /*int nlocals,*/
+ 0, /*int stacksize,*/
+ 0, /*int flags,*/
+ empty_string, /*PyObject *code,*/
+ empty_tuple, /*PyObject *consts,*/
+ empty_tuple, /*PyObject *names,*/
+ empty_tuple, /*PyObject *varnames,*/
+ empty_tuple, /*PyObject *freevars,*/
+ empty_tuple, /*PyObject *cellvars,*/
+ py_srcfile, /*PyObject *filename,*/
+ py_funcname, /*PyObject *name,*/
+ __pyx_lineno, /*int firstlineno,*/
+ empty_string /*PyObject *lnotab*/
+ );
+ if (!py_code) goto bad;
+ py_frame = PyFrame_New(
+ PyThreadState_Get(), /*PyThreadState *tstate,*/
+ py_code, /*PyCodeObject *code,*/
+ py_globals, /*PyObject *globals,*/
+ 0 /*PyObject *locals*/
+ );
+ if (!py_frame) goto bad;
+ py_frame->f_lineno = __pyx_lineno;
+ PyTraceBack_Here(py_frame);
+bad:
+ Py_XDECREF(py_srcfile);
+ Py_XDECREF(py_funcname);
+ Py_XDECREF(empty_tuple);
+ Py_XDECREF(empty_string);
+ Py_XDECREF(py_code);
+ Py_XDECREF(py_frame);
+}
diff --git a/numpy/doc/numpybook/comparison/pyrex/add.pyx b/numpy/doc/numpybook/comparison/pyrex/add.pyx
new file mode 100644
index 000000000..63c231641
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/pyrex/add.pyx
@@ -0,0 +1,75 @@
+# -*- Mode: Python -*- Not really, but close enough
+
+cimport c_numpy
+from c_numpy cimport import_array, ndarray, npy_intp, npy_cdouble, \
+ npy_cfloat, NPY_DOUBLE, NPY_CDOUBLE, NPY_FLOAT, \
+ NPY_CFLOAT
+
+#We need to initialize NumPy
+import_array()
+
+def zadd(object ao, object bo):
+ cdef ndarray c, a, b
+ cdef npy_intp i
+
+ a = c_numpy.PyArray_ContiguousFromAny(ao, NPY_CDOUBLE, 1, 1)
+ b = c_numpy.PyArray_ContiguousFromAny(bo, NPY_CDOUBLE, 1, 1)
+
+ c = c_numpy.PyArray_SimpleNew(a.nd, a.dimensions,
+ a.descr.type_num)
+
+ for i from 0 <= i < a.dimensions[0]:
+ (<npy_cdouble *>c.data)[i].real = (<npy_cdouble *>a.data)[i].real + \
+ (<npy_cdouble *>b.data)[i].real
+ (<npy_cdouble *>c.data)[i].imag = (<npy_cdouble *>a.data)[i].imag + \
+ (<npy_cdouble *>b.data)[i].imag
+ return c
+
+def cadd(object ao, object bo):
+ cdef ndarray c, a, b
+ cdef npy_intp i
+
+ a = c_numpy.PyArray_ContiguousFromAny(ao, NPY_CFLOAT, 1, 1)
+ b = c_numpy.PyArray_ContiguousFromAny(bo, NPY_CFLOAT, 1, 1)
+
+ c = c_numpy.PyArray_SimpleNew(a.nd, a.dimensions,
+ a.descr.type_num)
+
+ for i from 0 <= i < a.dimensions[0]:
+ (<npy_cfloat *>c.data)[i].real = (<npy_cfloat *>a.data)[i].real + \
+ (<npy_cfloat *>b.data)[i].real
+ (<npy_cfloat *>c.data)[i].imag = (<npy_cfloat *>a.data)[i].imag + \
+ (<npy_cfloat *>b.data)[i].imag
+ return c
+
+
+def dadd(object ao, object bo):
+ cdef ndarray c, a, b
+ cdef npy_intp i
+
+ a = c_numpy.PyArray_ContiguousFromAny(ao, NPY_DOUBLE, 1, 1)
+ b = c_numpy.PyArray_ContiguousFromAny(bo, NPY_DOUBLE, 1, 1)
+
+ c = c_numpy.PyArray_SimpleNew(a.nd, a.dimensions,
+ a.descr.type_num)
+
+ for i from 0 <= i < a.dimensions[0]:
+ (<double *>c.data)[i] = (<double *>a.data)[i] + \
+ (<double *>b.data)[i]
+ return c
+
+
+def sadd(object ao, object bo):
+ cdef ndarray c, a, b
+ cdef npy_intp i
+
+ a = c_numpy.PyArray_ContiguousFromAny(ao, NPY_FLOAT, 1, 1)
+ b = c_numpy.PyArray_ContiguousFromAny(bo, NPY_FLOAT, 1, 1)
+
+ c = c_numpy.PyArray_SimpleNew(a.nd, a.dimensions,
+ a.descr.type_num)
+
+ for i from 0 <= i < a.dimensions[0]:
+ (<float *>c.data)[i] = (<float *>a.data)[i] + \
+ (<float *>b.data)[i]
+ return c
diff --git a/numpy/doc/numpybook/comparison/pyrex/c_numpy.pxd b/numpy/doc/numpybook/comparison/pyrex/c_numpy.pxd
new file mode 100644
index 000000000..e772f6fee
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/pyrex/c_numpy.pxd
@@ -0,0 +1,106 @@
+# :Author: Robert Kern
+# :Copyright: 2004, Enthought, Inc.
+# :License: BSD Style
+
+
+cdef extern from "numpy/arrayobject.h":
+
+ cdef enum NPY_TYPES:
+ NPY_BOOL
+ NPY_BYTE
+ NPY_UBYTE
+ NPY_SHORT
+ NPY_USHORT
+ NPY_INT
+ NPY_UINT
+ NPY_LONG
+ NPY_ULONG
+ NPY_LONGLONG
+ NPY_ULONGLONG
+ NPY_FLOAT
+ NPY_DOUBLE
+ NPY_LONGDOUBLE
+ NPY_CFLOAT
+ NPY_CDOUBLE
+ NPY_CLONGDOUBLE
+ NPY_OBJECT
+ NPY_STRING
+ NPY_UNICODE
+ NPY_VOID
+ NPY_NTYPES
+ NPY_NOTYPE
+
+ cdef enum requirements:
+ NPY_CONTIGUOUS
+ NPY_FORTRAN
+ NPY_OWNDATA
+ NPY_FORCECAST
+ NPY_ENSURECOPY
+ NPY_ENSUREARRAY
+ NPY_ELEMENTSTRIDES
+ NPY_ALIGNED
+ NPY_NOTSWAPPED
+ NPY_WRITEABLE
+ NPY_UPDATEIFCOPY
+ NPY_ARR_HAS_DESCR
+
+ NPY_BEHAVED
+ NPY_BEHAVED_NS
+ NPY_CARRAY
+ NPY_CARRAY_RO
+ NPY_FARRAY
+ NPY_FARRAY_RO
+ NPY_DEFAULT
+
+ NPY_IN_ARRAY
+ NPY_OUT_ARRAY
+ NPY_INOUT_ARRAY
+ NPY_IN_FARRAY
+ NPY_OUT_FARRAY
+ NPY_INOUT_FARRAY
+
+ NPY_UPDATE_ALL
+
+ ctypedef struct npy_cdouble:
+ double real
+ double imag
+
+ ctypedef struct npy_cfloat:
+ double real
+ double imag
+
+ ctypedef int npy_intp
+
+ ctypedef extern class numpy.dtype [object PyArray_Descr]:
+ cdef int type_num, elsize, alignment
+ cdef char type, kind, byteorder, hasobject
+ cdef object fields, typeobj
+
+ ctypedef extern class numpy.ndarray [object PyArrayObject]:
+ cdef char *data
+ cdef int nd
+ cdef npy_intp *dimensions
+ cdef npy_intp *strides
+ cdef object base
+ cdef dtype descr
+ cdef int flags
+
+ object PyArray_ZEROS(int ndims, npy_intp* dims, NPY_TYPES type_num, int fortran)
+ object PyArray_EMPTY(int ndims, npy_intp* dims, NPY_TYPES type_num, int fortran)
+ dtype PyArray_DescrFromTypeNum(NPY_TYPES type_num)
+ object PyArray_SimpleNew(int ndims, npy_intp* dims, NPY_TYPES type_num)
+ int PyArray_Check(object obj)
+ object PyArray_ContiguousFromAny(object obj, NPY_TYPES type,
+ int mindim, int maxdim)
+ npy_intp PyArray_SIZE(ndarray arr)
+ npy_intp PyArray_NBYTES(ndarray arr)
+ void *PyArray_DATA(ndarray arr)
+ object PyArray_FromAny(object obj, dtype newtype, int mindim, int maxdim,
+ int requirements, object context)
+ object PyArray_FROMANY(object obj, NPY_TYPES type_num, int min,
+ int max, int requirements)
+ object PyArray_NewFromDescr(object subtype, dtype newtype, int nd,
+ npy_intp* dims, npy_intp* strides, void* data,
+ int flags, object parent)
+
+ void import_array()
diff --git a/numpy/doc/numpybook/comparison/pyrex/filter.c b/numpy/doc/numpybook/comparison/pyrex/filter.c
new file mode 100644
index 000000000..1c25eb677
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/pyrex/filter.c
@@ -0,0 +1,388 @@
+/* Generated by Pyrex 0.9.4.1 on Thu Aug 17 02:11:42 2006 */
+
+#include "Python.h"
+#include "structmember.h"
+#ifndef PY_LONG_LONG
+ #define PY_LONG_LONG LONG_LONG
+#endif
+#ifdef __cplusplus
+#define __PYX_EXTERN_C extern "C"
+#else
+#define __PYX_EXTERN_C extern
+#endif
+__PYX_EXTERN_C double pow(double, double);
+#include "numpy/arrayobject.h"
+
+
+typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
+typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
+static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
+static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
+static int __Pyx_PrintItem(PyObject *); /*proto*/
+static int __Pyx_PrintNewline(void); /*proto*/
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static void __Pyx_ReRaise(void); /*proto*/
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
+static PyObject *__Pyx_GetExcValue(void); /*proto*/
+static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
+static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
+static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
+static void __Pyx_WriteUnraisable(char *name); /*proto*/
+static void __Pyx_AddTraceback(char *funcname); /*proto*/
+static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size); /*proto*/
+static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
+static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/
+static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
+static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static int __pyx_lineno;
+static char *__pyx_filename;
+static char **__pyx_f;
+
+/* Declarations from c_numpy */
+
+static PyTypeObject *__pyx_ptype_7c_numpy_dtype = 0;
+static PyTypeObject *__pyx_ptype_7c_numpy_ndarray = 0;
+
+/* Declarations from filter */
+
+
+/* Implementation of filter */
+
+static PyObject *__pyx_n_c_numpy;
+static PyObject *__pyx_n_filter;
+
+static PyObject *__pyx_f_6filter_filter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_f_6filter_filter(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_ao = 0;
+ PyArrayObject *__pyx_v_a;
+ PyArrayObject *__pyx_v_b;
+ npy_intp __pyx_v_i;
+ npy_intp __pyx_v_j;
+ npy_intp __pyx_v_M;
+ npy_intp __pyx_v_N;
+ npy_intp __pyx_v_S0;
+ npy_intp __pyx_v_S1;
+ npy_intp __pyx_v_r;
+ npy_intp __pyx_v_rm1;
+ npy_intp __pyx_v_rp1;
+ npy_intp __pyx_v_c;
+ npy_intp __pyx_v_cm1;
+ npy_intp __pyx_v_cp1;
+ PyObject *__pyx_v_oS;
+ PyObject *__pyx_r;
+ PyObject *__pyx_1 = 0;
+ long __pyx_2;
+ long __pyx_3;
+ PyObject *__pyx_4 = 0;
+ int __pyx_5;
+ static char *__pyx_argnames[] = {"ao",0};
+ if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_ao)) return 0;
+ Py_INCREF(__pyx_v_ao);
+ __pyx_v_a = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_b = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+ __pyx_v_oS = Py_None; Py_INCREF(Py_None);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":18 */
+ __pyx_1 = PyArray_FROMANY(__pyx_v_ao,NPY_DOUBLE,2,2,NPY_ALIGNED); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_a));
+ __pyx_v_a = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":19 */
+ __pyx_1 = PyArray_ZEROS(__pyx_v_a->nd,__pyx_v_a->dimensions,__pyx_v_a->descr->type_num,0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;}
+ if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;}
+ Py_DECREF(((PyObject *)__pyx_v_b));
+ __pyx_v_b = ((PyArrayObject *)__pyx_1);
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":20 */
+ __pyx_v_M = (__pyx_v_a->dimensions[0]);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":21 */
+ __pyx_v_N = (__pyx_v_a->dimensions[1]);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":22 */
+ __pyx_v_S0 = (__pyx_v_a->strides[0]);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":23 */
+ __pyx_v_S1 = (__pyx_v_a->strides[1]);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":24 */
+ __pyx_2 = (__pyx_v_M - 1);
+ for (__pyx_v_i = 1; __pyx_v_i < __pyx_2; ++__pyx_v_i) {
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":25 */
+ __pyx_v_r = (__pyx_v_i * __pyx_v_S0);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":26 */
+ __pyx_v_rm1 = (__pyx_v_r - __pyx_v_S0);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":27 */
+ __pyx_v_rp1 = (__pyx_v_r + __pyx_v_S0);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":28 */
+ __pyx_1 = PyInt_FromLong((__pyx_v_i * __pyx_v_N)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; goto __pyx_L1;}
+ Py_DECREF(__pyx_v_oS);
+ __pyx_v_oS = __pyx_1;
+ __pyx_1 = 0;
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":29 */
+ __pyx_3 = (__pyx_v_N - 1);
+ for (__pyx_v_j = 1; __pyx_v_j < __pyx_3; ++__pyx_v_j) {
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":30 */
+ __pyx_v_c = (__pyx_v_j * __pyx_v_S1);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":31 */
+ __pyx_v_cm1 = (__pyx_v_c - __pyx_v_S1);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":32 */
+ __pyx_v_cp1 = (__pyx_v_c + __pyx_v_S1);
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":38 */
+ __pyx_1 = PyInt_FromLong(__pyx_v_j); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
+ __pyx_4 = PyNumber_Add(__pyx_v_oS, __pyx_1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
+ Py_DECREF(__pyx_1); __pyx_1 = 0;
+ __pyx_5 = PyInt_AsLong(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
+ Py_DECREF(__pyx_4); __pyx_4 = 0;
+ (((double (*))__pyx_v_b->data)[__pyx_5]) = (((((double (*))((__pyx_v_a->data + __pyx_v_r) + __pyx_v_c))[0]) + (((((((double (*))((__pyx_v_a->data + __pyx_v_rm1) + __pyx_v_c))[0]) + (((double (*))((__pyx_v_a->data + __pyx_v_rp1) + __pyx_v_c))[0])) + (((double (*))((__pyx_v_a->data + __pyx_v_r) + __pyx_v_cm1))[0])) + (((double (*))((__pyx_v_a->data + __pyx_v_r) + __pyx_v_cp1))[0])) * 0.5)) + (((((((double (*))((__pyx_v_a->data + __pyx_v_rm1) + __pyx_v_cm1))[0]) + (((double (*))((__pyx_v_a->data + __pyx_v_rp1) + __pyx_v_cm1))[0])) + (((double (*))((__pyx_v_a->data + __pyx_v_rp1) + __pyx_v_cp1))[0])) + (((double (*))((__pyx_v_a->data + __pyx_v_rm1) + __pyx_v_cp1))[0])) * 0.25));
+ __pyx_L4:;
+ }
+ __pyx_L5:;
+ __pyx_L2:;
+ }
+ __pyx_L3:;
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":43 */
+ Py_INCREF(((PyObject *)__pyx_v_b));
+ __pyx_r = ((PyObject *)__pyx_v_b);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; Py_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1:;
+ Py_XDECREF(__pyx_1);
+ Py_XDECREF(__pyx_4);
+ __Pyx_AddTraceback("filter.filter");
+ __pyx_r = 0;
+ __pyx_L0:;
+ Py_DECREF(__pyx_v_a);
+ Py_DECREF(__pyx_v_b);
+ Py_DECREF(__pyx_v_oS);
+ Py_DECREF(__pyx_v_ao);
+ return __pyx_r;
+}
+
+static __Pyx_InternTabEntry __pyx_intern_tab[] = {
+ {&__pyx_n_c_numpy, "c_numpy"},
+ {&__pyx_n_filter, "filter"},
+ {0, 0}
+};
+
+static struct PyMethodDef __pyx_methods[] = {
+ {"filter", (PyCFunction)__pyx_f_6filter_filter, METH_VARARGS|METH_KEYWORDS, 0},
+ {0, 0, 0, 0}
+};
+
+static void __pyx_init_filenames(void); /*proto*/
+
+PyMODINIT_FUNC initfilter(void); /*proto*/
+PyMODINIT_FUNC initfilter(void) {
+ __pyx_init_filenames();
+ __pyx_m = Py_InitModule4("filter", __pyx_methods, 0, 0, PYTHON_API_VERSION);
+ if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
+ __pyx_b = PyImport_AddModule("__builtin__");
+ if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
+ if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
+ if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
+ __pyx_ptype_7c_numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr)); if (!__pyx_ptype_7c_numpy_dtype) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 74; goto __pyx_L1;}
+ __pyx_ptype_7c_numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject)); if (!__pyx_ptype_7c_numpy_ndarray) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; goto __pyx_L1;}
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":9 */
+ import_array();
+
+ /* "/Users/oliphant/numpybook/pyrex/filter.pyx":11 */
+ return;
+ __pyx_L1:;
+ __Pyx_AddTraceback("filter");
+}
+
+static char *__pyx_filenames[] = {
+ "filter.pyx",
+ "c_numpy.pxd",
+};
+
+/* Runtime support code */
+
+static void __pyx_init_filenames(void) {
+ __pyx_f = __pyx_filenames;
+}
+
+static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
+ if (!type) {
+ PyErr_Format(PyExc_SystemError, "Missing type object");
+ return 0;
+ }
+ if (obj == Py_None || PyObject_TypeCheck(obj, type))
+ return 1;
+ PyErr_Format(PyExc_TypeError, "Cannot convert %s to %s",
+ obj->ob_type->tp_name, type->tp_name);
+ return 0;
+}
+
+static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
+ while (t->p) {
+ *t->p = PyString_InternFromString(t->s);
+ if (!*t->p)
+ return -1;
+ ++t;
+ }
+ return 0;
+}
+
+static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name,
+ long size)
+{
+ PyObject *py_module_name = 0;
+ PyObject *py_class_name = 0;
+ PyObject *py_name_list = 0;
+ PyObject *py_module = 0;
+ PyObject *result = 0;
+
+ py_module_name = PyString_FromString(module_name);
+ if (!py_module_name)
+ goto bad;
+ py_class_name = PyString_FromString(class_name);
+ if (!py_class_name)
+ goto bad;
+ py_name_list = PyList_New(1);
+ if (!py_name_list)
+ goto bad;
+ Py_INCREF(py_class_name);
+ if (PyList_SetItem(py_name_list, 0, py_class_name) < 0)
+ goto bad;
+ py_module = __Pyx_Import(py_module_name, py_name_list);
+ if (!py_module)
+ goto bad;
+ result = PyObject_GetAttr(py_module, py_class_name);
+ if (!result)
+ goto bad;
+ if (!PyType_Check(result)) {
+ PyErr_Format(PyExc_TypeError,
+ "%s.%s is not a type object",
+ module_name, class_name);
+ goto bad;
+ }
+ if (((PyTypeObject *)result)->tp_basicsize != size) {
+ PyErr_Format(PyExc_ValueError,
+ "%s.%s does not appear to be the correct type object",
+ module_name, class_name);
+ goto bad;
+ }
+ goto done;
+bad:
+ Py_XDECREF(result);
+ result = 0;
+done:
+ Py_XDECREF(py_module_name);
+ Py_XDECREF(py_class_name);
+ Py_XDECREF(py_name_list);
+ return (PyTypeObject *)result;
+}
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
+ PyObject *__import__ = 0;
+ PyObject *empty_list = 0;
+ PyObject *module = 0;
+ PyObject *global_dict = 0;
+ PyObject *empty_dict = 0;
+ PyObject *list;
+ __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
+ if (!__import__)
+ goto bad;
+ if (from_list)
+ list = from_list;
+ else {
+ empty_list = PyList_New(0);
+ if (!empty_list)
+ goto bad;
+ list = empty_list;
+ }
+ global_dict = PyModule_GetDict(__pyx_m);
+ if (!global_dict)
+ goto bad;
+ empty_dict = PyDict_New();
+ if (!empty_dict)
+ goto bad;
+ module = PyObject_CallFunction(__import__, "OOOO",
+ name, global_dict, empty_dict, list);
+bad:
+ Py_XDECREF(empty_list);
+ Py_XDECREF(__import__);
+ Py_XDECREF(empty_dict);
+ return module;
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+
+static void __Pyx_AddTraceback(char *funcname) {
+ PyObject *py_srcfile = 0;
+ PyObject *py_funcname = 0;
+ PyObject *py_globals = 0;
+ PyObject *empty_tuple = 0;
+ PyObject *empty_string = 0;
+ PyCodeObject *py_code = 0;
+ PyFrameObject *py_frame = 0;
+
+ py_srcfile = PyString_FromString(__pyx_filename);
+ if (!py_srcfile) goto bad;
+ py_funcname = PyString_FromString(funcname);
+ if (!py_funcname) goto bad;
+ py_globals = PyModule_GetDict(__pyx_m);
+ if (!py_globals) goto bad;
+ empty_tuple = PyTuple_New(0);
+ if (!empty_tuple) goto bad;
+ empty_string = PyString_FromString("");
+ if (!empty_string) goto bad;
+ py_code = PyCode_New(
+ 0, /*int argcount,*/
+ 0, /*int nlocals,*/
+ 0, /*int stacksize,*/
+ 0, /*int flags,*/
+ empty_string, /*PyObject *code,*/
+ empty_tuple, /*PyObject *consts,*/
+ empty_tuple, /*PyObject *names,*/
+ empty_tuple, /*PyObject *varnames,*/
+ empty_tuple, /*PyObject *freevars,*/
+ empty_tuple, /*PyObject *cellvars,*/
+ py_srcfile, /*PyObject *filename,*/
+ py_funcname, /*PyObject *name,*/
+ __pyx_lineno, /*int firstlineno,*/
+ empty_string /*PyObject *lnotab*/
+ );
+ if (!py_code) goto bad;
+ py_frame = PyFrame_New(
+ PyThreadState_Get(), /*PyThreadState *tstate,*/
+ py_code, /*PyCodeObject *code,*/
+ py_globals, /*PyObject *globals,*/
+ 0 /*PyObject *locals*/
+ );
+ if (!py_frame) goto bad;
+ py_frame->f_lineno = __pyx_lineno;
+ PyTraceBack_Here(py_frame);
+bad:
+ Py_XDECREF(py_srcfile);
+ Py_XDECREF(py_funcname);
+ Py_XDECREF(empty_tuple);
+ Py_XDECREF(empty_string);
+ Py_XDECREF(py_code);
+ Py_XDECREF(py_frame);
+}
diff --git a/numpy/doc/numpybook/comparison/pyrex/filter.pyx b/numpy/doc/numpybook/comparison/pyrex/filter.pyx
new file mode 100644
index 000000000..492bc43de
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/pyrex/filter.pyx
@@ -0,0 +1,44 @@
+# -*- Mode: Python -*- Not really, but close enough
+
+cimport c_numpy
+from c_numpy cimport import_array, ndarray, npy_intp,\
+ NPY_DOUBLE, NPY_CDOUBLE, NPY_FLOAT, \
+ NPY_CFLOAT, NPY_ALIGNED
+
+#We need to initialize NumPy
+import_array()
+
+def filter(object ao):
+ cdef ndarray a, b
+ cdef npy_intp i, j, M, N, S0, S1
+ cdef npy_intp r,rm1,rp1,c,cm1,cp1
+
+ # Require an ALIGNED array (but not necessarily contiguous)
+ # We will use strides to access the elements.
+ a = c_numpy.PyArray_FROMANY(ao, NPY_DOUBLE, 2, 2, NPY_ALIGNED)
+ b = c_numpy.PyArray_ZEROS(a.nd, a.dimensions, a.descr.type_num, 0)
+ M = a.dimensions[0]
+ N = a.dimensions[1]
+ S0 = a.strides[0]
+ S1 = a.strides[1]
+ for i from 1 <= i < M-1:
+ r = i*S0
+ rm1 = r-S0
+ rp1 = r+S0
+ oS = i*N
+ for j from 1 <= j < N-1:
+ c = j*S1
+ cm1 = c-S1
+ cp1 = c+S1
+ (<double *>b.data)[oS+j] = \
+ (<double *>(a.data+r+c))[0] + \
+ ((<double *>(a.data+rm1+c))[0] + \
+ (<double *>(a.data+rp1+c))[0] + \
+ (<double *>(a.data+r+cm1))[0] + \
+ (<double *>(a.data+r+cp1))[0])*0.5 + \
+ ((<double *>(a.data+rm1+cm1))[0] + \
+ (<double *>(a.data+rp1+cm1))[0] + \
+ (<double *>(a.data+rp1+cp1))[0] + \
+ (<double *>(a.data+rm1+cp1))[0])*0.25
+ return b
+
diff --git a/numpy/doc/numpybook/comparison/pyrex/setup.py b/numpy/doc/numpybook/comparison/pyrex/setup.py
new file mode 100644
index 000000000..64cf12bc8
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/pyrex/setup.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+from distutils.core import setup
+from distutils.extension import Extension
+
+import numpy
+
+# Define a pyrex-based extension module, using the generated sources if pyrex
+from Pyrex.Distutils import build_ext
+pyx_sources = ['add.pyx']
+cmdclass = {'build_ext': build_ext}
+
+
+pyx_ext = Extension('add',
+ pyx_sources,
+ include_dirs = [numpy.get_include()])
+
+pyx_ext2 = Extension('blur',
+ ['blur.pyx'],
+ include_dirs = [numpy.get_include()])
+
+
+# Call the routine which does the real work
+setup(name = 'add',
+ description = 'Small example on using Pyrex to write a Numpy extension',
+ url = 'http://www.scipy.org/Cookbook/Pyrex_and_NumPy',
+ ext_modules = [pyx_ext, pyx_ext2],
+ cmdclass = cmdclass,
+ )
diff --git a/numpy/doc/numpybook/comparison/pyrex/timeme b/numpy/doc/numpybook/comparison/pyrex/timeme
new file mode 100755
index 000000000..2f7cd297f
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/pyrex/timeme
@@ -0,0 +1,2 @@
+python2.4 -m timeit -s "import numpy as N; a=N.random.rand(100,200); import filter" "b = filter.filter(a)"
+
diff --git a/numpy/doc/numpybook/comparison/timing.py b/numpy/doc/numpybook/comparison/timing.py
new file mode 100644
index 000000000..14841d7cb
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/timing.py
@@ -0,0 +1,63 @@
+
+import timeit
+
+pyrex_pre = """
+import numpy as N
+a = N.random.rand(%d,%d)
+import filter
+"""
+
+pyrex_run = """
+b = filter.filter(a)
+"""
+
+weave_pre = """
+import numpy as N
+a = N.random.rand(%d,%d)
+import filter
+"""
+
+weave_run = """
+b = filter.filter(a)
+"""
+
+ctypes_pre = """
+import numpy as N
+a = N.random.rand(%d,%d)
+import filter
+"""
+
+ctypes_run = """
+b = filter.filter(a)
+"""
+
+f2py_pre = """
+import numpy as N
+a = N.random.rand(%d, %d).T
+import filter
+"""
+
+f2py_run = """
+b = N.zeros_like(a)
+filter.DFILTER2D(a,b)
+"""
+
+N = [10,20,30,40,50,100,200,300, 400, 500]
+
+res = {}
+
+import os
+import sys
+path = sys.path
+
+for kind in ['f2py']:#['ctypes', 'pyrex', 'weave', 'f2py']:
+ res[kind] = []
+ sys.path = ['/Users/oliphant/numpybook/%s' % (kind,)] + path
+ print sys.path
+ for n in N:
+ print "%s - %d" % (kind, n)
+ t = timeit.Timer(eval('%s_run'%kind), eval('%s_pre %% (%d,%d)'%(kind,n,n)))
+ mytime = min(t.repeat(3,100))
+ res[kind].append(mytime)
+
+
diff --git a/numpy/doc/numpybook/comparison/weave/filter.py b/numpy/doc/numpybook/comparison/weave/filter.py
new file mode 100644
index 000000000..b2fdb277e
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/weave/filter.py
@@ -0,0 +1,23 @@
+from scipy import weave, zeros_like
+
+def filter(a):
+ if a.ndim != 2:
+ raise ValueError, "a must be 2-d"
+ code = r"""
+ int i,j;
+ for(i=1;i<Na[0]-1;i++) {
+ for(j=1;j<Na[1]-1;j++) {
+ B2(i,j) = A2(i,j) + (A2(i-1,j) +
+ A2(i+1,j) + A2(i,j-1)
+ + A2(i,j+1))*0.5
+ + (A2(i-1,j-1)
+ + A2(i-1,j+1)
+ + A2(i+1,j-1)
+ + A2(i+1,j+1))*0.25;
+ }
+ }
+ """
+ b = zeros_like(a)
+ weave.inline(code,['a','b'])
+ return b
+
diff --git a/numpy/doc/numpybook/comparison/weave/inline.py b/numpy/doc/numpybook/comparison/weave/inline.py
new file mode 100644
index 000000000..31499213e
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/weave/inline.py
@@ -0,0 +1,49 @@
+from scipy import weave
+from numpy import rand, zeros_like
+
+def example1(a):
+ if not isinstance(a, list):
+ raise ValueError, "argument must be a list"
+ code = r"""
+ int i;
+ py::tuple results(2);
+ for (i=0; i<a.length(); i++) {
+ a[i] = i;
+ }
+ results[0] = 3.0;
+ results[1] = 4.0;
+ return_val = results;
+ """
+ return weave.inline(code,['a'])
+
+def arr(a):
+ if a.ndim != 2:
+ raise ValueError, "a must be 2-d"
+ code = r"""
+ int i,j;
+ for(i=1;i<Na[0]-1;i++) {
+ for(j=1;j<Na[1]-1;j++) {
+ B2(i,j) = A2(i,j) + A2(i-1,j)*0.5 +
+ A2(i+1,j)*0.5 + A2(i,j-1)*0.5
+ + A2(i,j+1)*0.5
+ + A2(i-1,j-1)*0.25
+ + A2(i-1,j+1)*0.25
+ + A2(i+1,j-1)*0.25
+ + A2(i+1,j+1)*0.25;
+ }
+ }
+ """
+ b = zeros_like(a)
+ weave.inline(code,['a','b'])
+ return b
+
+a = [None]*10
+print example1(a)
+print a
+
+a = rand(512,512)
+b = arr(a)
+
+h = [[0.25,0.5,0.25],[0.5,1,0.5],[0.25,0.5,0.25]]
+import scipy.signal as ss
+b2 = ss.convolve(h,a,'same')
diff --git a/numpy/doc/numpybook/comparison/weave/timeme b/numpy/doc/numpybook/comparison/weave/timeme
new file mode 100755
index 000000000..2f7cd297f
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/weave/timeme
@@ -0,0 +1,2 @@
+python2.4 -m timeit -s "import numpy as N; a=N.random.rand(100,200); import filter" "b = filter.filter(a)"
+