diff options
author | Stefan van der Walt <stefan@sun.ac.za> | 2008-08-23 23:55:01 +0000 |
---|---|---|
committer | Stefan van der Walt <stefan@sun.ac.za> | 2008-08-23 23:55:01 +0000 |
commit | 46facee53a506cd26c00ad12d482a682b0176404 (patch) | |
tree | 563e932b1888e28c19a0ca6cc0f6e02bfe0b6f3f /doc/numpybook/comparison/f2py | |
parent | d14243ca1fa3373babfd5b699e12dff177f60dba (diff) | |
download | numpy-46facee53a506cd26c00ad12d482a682b0176404.tar.gz |
Move book to docs directory.
Diffstat (limited to 'doc/numpybook/comparison/f2py')
-rw-r--r-- | doc/numpybook/comparison/f2py/add.f | 45 | ||||
-rw-r--r-- | doc/numpybook/comparison/f2py/add.pyf | 34 | ||||
-rw-r--r-- | doc/numpybook/comparison/f2py/filter.f | 20 | ||||
-rw-r--r-- | doc/numpybook/comparison/f2py/filter.pyf | 16 | ||||
-rw-r--r-- | doc/numpybook/comparison/f2py/filtermodule.c | 293 | ||||
-rwxr-xr-x | doc/numpybook/comparison/f2py/timeme | 1 |
6 files changed, 409 insertions, 0 deletions
diff --git a/doc/numpybook/comparison/f2py/add.f b/doc/numpybook/comparison/f2py/add.f new file mode 100644 index 000000000..26e45da34 --- /dev/null +++ b/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/doc/numpybook/comparison/f2py/add.pyf b/doc/numpybook/comparison/f2py/add.pyf new file mode 100644 index 000000000..1a9ac2c9e --- /dev/null +++ b/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/doc/numpybook/comparison/f2py/filter.f b/doc/numpybook/comparison/f2py/filter.f new file mode 100644 index 000000000..a817a866f --- /dev/null +++ b/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/doc/numpybook/comparison/f2py/filter.pyf b/doc/numpybook/comparison/f2py/filter.pyf new file mode 100644 index 000000000..1e4bc37f4 --- /dev/null +++ b/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/doc/numpybook/comparison/f2py/filtermodule.c b/doc/numpybook/comparison/f2py/filtermodule.c new file mode 100644 index 000000000..8339ad4b9 --- /dev/null +++ b/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/doc/numpybook/comparison/f2py/timeme b/doc/numpybook/comparison/f2py/timeme new file mode 100755 index 000000000..d6ac5741e --- /dev/null +++ b/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)" |