summaryrefslogtreecommitdiff
path: root/numpy/f2py/cfuncs.py
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2011-05-06 21:03:07 +0300
committerPearu Peterson <pearu.peterson@gmail.com>2011-05-06 21:03:07 +0300
commita859492c7b07dac0a56d9a08d6739e006a528f87 (patch)
tree3fb42eba6e311bcba8ce37e4e7e7eca2b98052a2 /numpy/f2py/cfuncs.py
parentf393b6041c0d124b0372c494bab7de8dbe0cd422 (diff)
downloadnumpy-a859492c7b07dac0a56d9a08d6739e006a528f87.tar.gz
BUG: Fix two argument size support for Fortran module routines. Reverted size-to-shape mapping patch and implemented two argument size function in C.
Diffstat (limited to 'numpy/f2py/cfuncs.py')
-rw-r--r--numpy/f2py/cfuncs.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py
index 56a193963..99515b42b 100644
--- a/numpy/f2py/cfuncs.py
+++ b/numpy/f2py/cfuncs.py
@@ -59,6 +59,7 @@ includes['arrayobject.h']='''#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API
#include "arrayobject.h"'''
includes['arrayobject.h']='#include "fortranobject.h"'
+includes['stdarg.h']='#include <stdarg.h>'
############# Type definitions ###############
@@ -243,6 +244,7 @@ cppmacros['MINMAX']="""\
#define MIN(a,b) ((a < b) ? (a) : (b))
#endif
"""
+needs['len..']=['f2py_size']
cppmacros['len..']="""\
#define rank(var) var ## _Rank
#define shape(var,dim) var ## _Dims[dim]
@@ -251,9 +253,36 @@ cppmacros['len..']="""\
#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 old_size(var) PyArray_SIZE((PyArrayObject *)(capi_ ## var ## _tmp))
/* #define index(i) capi_i ## i */
#define slen(var) capi_ ## var ## _len
+#define size(var, dim...) f2py_size((PyArrayObject *)(capi_ ## var ## _tmp), ##dim, -1)
+"""
+needs['f2py_size']=['stdarg.h']
+cfuncs['f2py_size']="""\
+int f2py_size(PyArrayObject* var, ...)
+{
+ npy_int sz = 0;
+ npy_int dim;
+ npy_int rank;
+ va_list argp;
+ va_start(argp, var);
+ dim = va_arg(argp, npy_int);
+ if (dim==-1)
+ {
+ sz = PyArray_SIZE(var);
+ }
+ else
+ {
+ rank = PyArray_NDIM(var);
+ if (dim>=1 && dim<=rank)
+ sz = PyArray_DIM(var, dim-1);
+ else
+ fprintf(stderr, \"f2py_size: 2nd argument value=%d fails to satisfy 1<=value<=%d. Result will be 0.\\n\", dim, rank);
+ }
+ va_end(argp);
+ return sz;
+}
"""
cppmacros['pyobj_from_char1']='#define pyobj_from_char1(v) (PyInt_FromLong(v))'