summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorwfspotz@sandia.gov <wfspotz@sandia.gov@localhost>2007-11-23 19:24:59 +0000
committerwfspotz@sandia.gov <wfspotz@sandia.gov@localhost>2007-11-23 19:24:59 +0000
commit0fa45d7deda989711c4af686d7e9c63a89cc8cbb (patch)
tree68c0695dc6478dbaf3eb369fb6528938f32992b5 /numpy
parenta9f446da7d3613743a2f191446519eeef2d8f8d7 (diff)
downloadnumpy-0fa45d7deda989711c4af686d7e9c63a89cc8cbb.tar.gz
Changed numpy.i so that helper macros and helper functions are now
implemented as swig %fragments. This allows me to implement the backward compatibility macros without duplicating them.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/doc/swig/numpy.i814
-rw-r--r--numpy/doc/swig/pyfragments.swg52
2 files changed, 521 insertions, 345 deletions
diff --git a/numpy/doc/swig/numpy.i b/numpy/doc/swig/numpy.i
index 1c9898baf..950c46d2d 100644
--- a/numpy/doc/swig/numpy.i
+++ b/numpy/doc/swig/numpy.i
@@ -7,14 +7,56 @@
#endif
#include "stdio.h"
#include <numpy/arrayobject.h>
+%}
/* The following code originally appeared in
* enthought/kiva/agg/src/numeric.i written by Eric Jones. It was
* translated from C++ to C by John Hunter. Bill Spotz has modified
- * it slightly to fix some minor bugs, upgrade to numpy (all
- * versions), add some comments and some functionality.
+ * it slightly to fix some minor bugs, upgrade from Numeric to numpy
+ * (all versions), add some comments and functionality, and convert
+ * from direct code insertion to SWIG fragments.
*/
+/**********************************************************************/
+
+%fragment("NumPy_Backward_Compatibility", "header")
+{
+/* Support older NumPy data type names
+*/
+%#if NDARRAY_VERSION < 0x01000000
+%#define NPY_BOOL PyArray_BOOL
+%#define NPY_BYTE PyArray_BYTE
+%#define NPY_UBYTE PyArray_UBYTE
+%#define NPY_SHORT PyArray_SHORT
+%#define NPY_USHORT PyArray_USHORT
+%#define NPY_INT PyArray_INT
+%#define NPY_UINT PyArray_UINT
+%#define NPY_LONG PyArray_LONG
+%#define NPY_ULONG PyArray_ULONG
+%#define NPY_LONGLONG PyArray_LONGLONG
+%#define NPY_ULONGLONG PyArray_ULONGLONG
+%#define NPY_FLOAT PyArray_FLOAT
+%#define NPY_DOUBLE PyArray_DOUBLE
+%#define NPY_LONGDOUBLE PyArray_LONGDOUBLE
+%#define NPY_CFLOAT PyArray_CFLOAT
+%#define NPY_CDOUBLE PyArray_CDOUBLE
+%#define NPY_CLONGDOUBLE PyArray_CLONGDOUBLE
+%#define NPY_OBJECT PyArray_OBJECT
+%#define NPY_STRING PyArray_STRING
+%#define NPY_UNICODE PyArray_UNICODE
+%#define NPY_VOID PyArray_VOID
+%#define NPY_NTYPES PyArray_NTYPES
+%#define NPY_NOTYPE PyArray_NOTYPE
+%#define NPY_CHAR PyArray_CHAR
+%#define NPY_USERDEF PyArray_USERDEF
+%#define npy_intp intp
+%#endif
+}
+
+/**********************************************************************/
+
+%fragment("NumPy_Macros", "header")
+{
/* Macros to extract array attributes.
*/
#define is_array(a) ((a) && PyArray_Check((PyArrayObject *)a))
@@ -25,297 +67,317 @@
#define array_data(a) (((PyArrayObject *)a)->data)
#define array_is_contiguous(a) (PyArray_ISCONTIGUOUS(a))
#define array_is_native(a) (PyArray_ISNOTSWAPPED(a))
+}
-/* Support older NumPy data type names
-*/
-#if NDARRAY_VERSION < 0x01000000
-#define NPY_BOOL PyArray_BOOL
-#define NPY_BYTE PyArray_BYTE
-#define NPY_UBYTE PyArray_UBYTE
-#define NPY_SHORT PyArray_SHORT
-#define NPY_USHORT PyArray_USHORT
-#define NPY_INT PyArray_INT
-#define NPY_UINT PyArray_UINT
-#define NPY_LONG PyArray_LONG
-#define NPY_ULONG PyArray_ULONG
-#define NPY_LONGLONG PyArray_LONGLONG
-#define NPY_ULONGLONG PyArray_ULONGLONG
-#define NPY_FLOAT PyArray_FLOAT
-#define NPY_DOUBLE PyArray_DOUBLE
-#define NPY_LONGDOUBLE PyArray_LONGDOUBLE
-#define NPY_CFLOAT PyArray_CFLOAT
-#define NPY_CDOUBLE PyArray_CDOUBLE
-#define NPY_CLONGDOUBLE PyArray_CLONGDOUBLE
-#define NPY_OBJECT PyArray_OBJECT
-#define NPY_STRING PyArray_STRING
-#define NPY_UNICODE PyArray_UNICODE
-#define NPY_VOID PyArray_VOID
-#define NPY_NTYPES PyArray_NTYPES
-#define NPY_NOTYPE PyArray_NOTYPE
-#define NPY_CHAR PyArray_CHAR
-#define NPY_USERDEF PyArray_USERDEF
-#define npy_intp intp
-#endif
+/**********************************************************************/
-/* Given a PyObject, return a string describing its type.
- */
-char* pytype_string(PyObject* py_obj) {
- if (py_obj == NULL ) return "C NULL value";
- if (py_obj == Py_None ) return "Python None" ;
- if (PyCallable_Check(py_obj)) return "callable" ;
- if (PyString_Check( py_obj)) return "string" ;
- if (PyInt_Check( py_obj)) return "int" ;
- if (PyFloat_Check( py_obj)) return "float" ;
- if (PyDict_Check( py_obj)) return "dict" ;
- if (PyList_Check( py_obj)) return "list" ;
- if (PyTuple_Check( py_obj)) return "tuple" ;
- if (PyFile_Check( py_obj)) return "file" ;
- if (PyModule_Check( py_obj)) return "module" ;
- if (PyInstance_Check(py_obj)) return "instance" ;
-
- return "unkown type";
-}
-
-/* Given a NumPy typecode, return a string describing the type.
- */
-char* typecode_string(int typecode) {
- static char* type_names[25] = {"bool", "byte", "unsigned byte",
- "short", "unsigned short", "int",
- "unsigned int", "long", "unsigned long",
- "long long", "unsigned long long",
- "float", "double", "long double",
- "complex float", "complex double",
- "complex long double", "object",
- "string", "unicode", "void", "ntypes",
- "notype", "char", "unknown"};
- return typecode < 24 ? type_names[typecode] : type_names[24];
-}
-
-/* Make sure input has correct numpy type. Allow character and byte
- * to match. Also allow int and long to match. This is deprecated.
- * You should use PyArray_EquivTypenums() instead.
- */
-int type_match(int actual_type, int desired_type) {
- return PyArray_EquivTypenums(actual_type, desired_type);
-}
-
-/* Given a PyObject pointer, cast it to a PyArrayObject pointer if
- * legal. If not, set the python error string appropriately and
- * return NULL.
- */
-PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode) {
- PyArrayObject* ary = NULL;
- if (is_array(input) && (typecode == NPY_NOTYPE ||
- PyArray_EquivTypenums(array_type(input), typecode))) {
- ary = (PyArrayObject*) input;
- }
- else if is_array(input) {
- char* desired_type = typecode_string(typecode);
- char* actual_type = typecode_string(array_type(input));
- PyErr_Format(PyExc_TypeError,
- "Array of type '%s' required. Array of type '%s' given",
- desired_type, actual_type);
- ary = NULL;
- }
- else {
- char * desired_type = typecode_string(typecode);
- char * actual_type = pytype_string(input);
- PyErr_Format(PyExc_TypeError,
- "Array of type '%s' required. A '%s' was given",
- desired_type, actual_type);
- ary = NULL;
+%fragment("NumPy_Utilities", "header")
+{
+ /* Given a PyObject, return a string describing its type.
+ */
+ char* pytype_string(PyObject* py_obj) {
+ if (py_obj == NULL ) return "C NULL value";
+ if (py_obj == Py_None ) return "Python None" ;
+ if (PyCallable_Check(py_obj)) return "callable" ;
+ if (PyString_Check( py_obj)) return "string" ;
+ if (PyInt_Check( py_obj)) return "int" ;
+ if (PyFloat_Check( py_obj)) return "float" ;
+ if (PyDict_Check( py_obj)) return "dict" ;
+ if (PyList_Check( py_obj)) return "list" ;
+ if (PyTuple_Check( py_obj)) return "tuple" ;
+ if (PyFile_Check( py_obj)) return "file" ;
+ if (PyModule_Check( py_obj)) return "module" ;
+ if (PyInstance_Check(py_obj)) return "instance" ;
+
+ return "unkown type";
}
- return ary;
-}
-
-/* Convert the given PyObject to a NumPy array with the given
- * typecode. On success, return a valid PyArrayObject* with the
- * correct type. On failure, the python error string will be set and
- * the routine returns NULL.
- */
-PyArrayObject* obj_to_array_allow_conversion(PyObject* input, int typecode,
- int* is_new_object) {
- PyArrayObject* ary = NULL;
- PyObject* py_obj;
- if (is_array(input) && (typecode == NPY_NOTYPE ||
- PyArray_EquivTypenums(array_type(input),typecode))) {
- ary = (PyArrayObject*) input;
- *is_new_object = 0;
+
+ /* Given a NumPy typecode, return a string describing the type.
+ */
+ char* typecode_string(int typecode) {
+ static char* type_names[25] = {"bool", "byte", "unsigned byte",
+ "short", "unsigned short", "int",
+ "unsigned int", "long", "unsigned long",
+ "long long", "unsigned long long",
+ "float", "double", "long double",
+ "complex float", "complex double",
+ "complex long double", "object",
+ "string", "unicode", "void", "ntypes",
+ "notype", "char", "unknown"};
+ return typecode < 24 ? type_names[typecode] : type_names[24];
}
- else {
- py_obj = PyArray_FromObject(input, typecode, 0, 0);
- /* If NULL, PyArray_FromObject will have set python error value.*/
- ary = (PyArrayObject*) py_obj;
- *is_new_object = 1;
+
+ /* Make sure input has correct numpy type. Allow character and byte
+ * to match. Also allow int and long to match. This is deprecated.
+ * You should use PyArray_EquivTypenums() instead.
+ */
+ int type_match(int actual_type, int desired_type) {
+ return PyArray_EquivTypenums(actual_type, desired_type);
}
- return ary;
}
-/* Given a PyArrayObject, check to see if it is contiguous. If so,
- * return the input pointer and flag it as not a new object. If it is
- * not contiguous, create a new PyArrayObject using the original data,
- * flag it as a new object and return the pointer.
- */
-PyArrayObject* make_contiguous(PyArrayObject* ary, int* is_new_object,
- int min_dims, int max_dims) {
- PyArrayObject* result;
- if (array_is_contiguous(ary)) {
- result = ary;
- *is_new_object = 0;
- }
- else {
- result = (PyArrayObject*) PyArray_ContiguousFromObject((PyObject*)ary,
- array_type(ary),
- min_dims,
- max_dims);
- *is_new_object = 1;
+/**********************************************************************/
+
+%fragment("NumPy_Object_to_Array", "header",
+ fragment="NumPy_Backward_Compatibility",
+ fragment="NumPy_Macros",
+ fragment="NumPy_Utilities")
+{
+ /* Given a PyObject pointer, cast it to a PyArrayObject pointer if
+ * legal. If not, set the python error string appropriately and
+ * return NULL.
+ */
+ PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode)
+ {
+ PyArrayObject* ary = NULL;
+ if (is_array(input) && (typecode == NPY_NOTYPE ||
+ PyArray_EquivTypenums(array_type(input), typecode)))
+ {
+ ary = (PyArrayObject*) input;
+ }
+ else if is_array(input)
+ {
+ char* desired_type = typecode_string(typecode);
+ char* actual_type = typecode_string(array_type(input));
+ PyErr_Format(PyExc_TypeError,
+ "Array of type '%s' required. Array of type '%s' given",
+ desired_type, actual_type);
+ ary = NULL;
+ }
+ else
+ {
+ char * desired_type = typecode_string(typecode);
+ char * actual_type = pytype_string(input);
+ PyErr_Format(PyExc_TypeError,
+ "Array of type '%s' required. A '%s' was given",
+ desired_type, actual_type);
+ ary = NULL;
+ }
+ return ary;
}
- return result;
-}
-
-/* Convert a given PyObject to a contiguous PyArrayObject of the
- * specified type. If the input object is not a contiguous
- * PyArrayObject, a new one will be created and the new object flag
- * will be set.
- */
-PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject* input,
- int typecode,
- int* is_new_object) {
- int is_new1 = 0;
- int is_new2 = 0;
- PyArrayObject* ary2;
- PyArrayObject* ary1 = obj_to_array_allow_conversion(input, typecode,
- &is_new1);
- if (ary1) {
- ary2 = make_contiguous(ary1, &is_new2, 0, 0);
- if ( is_new1 && is_new2) {
- Py_DECREF(ary1);
+
+ /* Convert the given PyObject to a NumPy array with the given
+ * typecode. On success, return a valid PyArrayObject* with the
+ * correct type. On failure, the python error string will be set and
+ * the routine returns NULL.
+ */
+ PyArrayObject* obj_to_array_allow_conversion(PyObject* input, int typecode,
+ int* is_new_object)
+ {
+ PyArrayObject* ary = NULL;
+ PyObject* py_obj;
+ if (is_array(input) && (typecode == NPY_NOTYPE ||
+ PyArray_EquivTypenums(array_type(input),typecode)))
+ {
+ ary = (PyArrayObject*) input;
+ *is_new_object = 0;
+ }
+ else
+ {
+ py_obj = PyArray_FromObject(input, typecode, 0, 0);
+ /* If NULL, PyArray_FromObject will have set python error value.*/
+ ary = (PyArrayObject*) py_obj;
+ *is_new_object = 1;
}
- ary1 = ary2;
+ return ary;
}
- *is_new_object = is_new1 || is_new2;
- return ary1;
-}
-/* Test whether a python object is contiguous. If array is
- * contiguous, return 1. Otherwise, set the python error string and
- * return 0.
- */
-int require_contiguous(PyArrayObject* ary) {
- int contiguous = 1;
- if (!array_is_contiguous(ary)) {
- PyErr_SetString(PyExc_TypeError,
- "Array must be contiguous. A non-contiguous array was given");
- contiguous = 0;
+ /* Given a PyArrayObject, check to see if it is contiguous. If so,
+ * return the input pointer and flag it as not a new object. If it is
+ * not contiguous, create a new PyArrayObject using the original data,
+ * flag it as a new object and return the pointer.
+ */
+ PyArrayObject* make_contiguous(PyArrayObject* ary, int* is_new_object,
+ int min_dims, int max_dims)
+ {
+ PyArrayObject* result;
+ if (array_is_contiguous(ary))
+ {
+ result = ary;
+ *is_new_object = 0;
+ }
+ else
+ {
+ result = (PyArrayObject*) PyArray_ContiguousFromObject((PyObject*)ary,
+ array_type(ary),
+ min_dims,
+ max_dims);
+ *is_new_object = 1;
+ }
+ return result;
}
- return contiguous;
-}
-/* Require that a numpy array is not byte-swapped. If the array is
- * not byte-swapped, return 1. Otherwise, set the python error string
- * and return 0.
- */
-int require_native(PyArrayObject* ary) {
- int native = 1;
- if (!array_is_native(ary)) {
- PyErr_SetString(PyExc_TypeError,
- "Array must have native byteorder. A byte-swapped array was given");
- native = 0;
+ /* Convert a given PyObject to a contiguous PyArrayObject of the
+ * specified type. If the input object is not a contiguous
+ * PyArrayObject, a new one will be created and the new object flag
+ * will be set.
+ */
+ PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject* input,
+ int typecode,
+ int* is_new_object)
+ {
+ int is_new1 = 0;
+ int is_new2 = 0;
+ PyArrayObject* ary2;
+ PyArrayObject* ary1 = obj_to_array_allow_conversion(input, typecode,
+ &is_new1);
+ if (ary1)
+ {
+ ary2 = make_contiguous(ary1, &is_new2, 0, 0);
+ if ( is_new1 && is_new2)
+ {
+ Py_DECREF(ary1);
+ }
+ ary1 = ary2;
+ }
+ *is_new_object = is_new1 || is_new2;
+ return ary1;
}
- return native;
}
-/* Require the given PyArrayObject to have a specified number of
- * dimensions. If the array has the specified number of dimensions,
- * return 1. Otherwise, set the python error string and return 0.
- */
-int require_dimensions(PyArrayObject* ary, int exact_dimensions) {
- int success = 1;
- if (array_numdims(ary) != exact_dimensions) {
- PyErr_Format(PyExc_TypeError,
- "Array must have %d dimensions. Given array has %d dimensions",
- exact_dimensions, array_numdims(ary));
- success = 0;
- }
- return success;
-}
-
-/* Require the given PyArrayObject to have one of a list of specified
- * number of dimensions. If the array has one of the specified number
- * of dimensions, return 1. Otherwise, set the python error string
- * and return 0.
- */
-int require_dimensions_n(PyArrayObject* ary, int* exact_dimensions, int n) {
- int success = 0;
- int i;
- char dims_str[255] = "";
- char s[255];
- for (i = 0; i < n && !success; i++) {
- if (array_numdims(ary) == exact_dimensions[i]) {
- success = 1;
+/**********************************************************************/
+
+%fragment("NumPy_Array_Requirements", "header",
+ fragment="NumPy_Backward_Compatibility",
+ fragment="NumPy_Macros")
+{
+ /* Test whether a python object is contiguous. If array is
+ * contiguous, return 1. Otherwise, set the python error string and
+ * return 0.
+ */
+ int require_contiguous(PyArrayObject* ary)
+ {
+ int contiguous = 1;
+ if (!array_is_contiguous(ary))
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "Array must be contiguous. A non-contiguous array was given");
+ contiguous = 0;
}
+ return contiguous;
}
- if (!success) {
- for (i = 0; i < n-1; i++) {
- sprintf(s, "%d, ", exact_dimensions[i]);
- strcat(dims_str,s);
+
+ /* Require that a numpy array is not byte-swapped. If the array is
+ * not byte-swapped, return 1. Otherwise, set the python error string
+ * and return 0.
+ */
+ int require_native(PyArrayObject* ary)
+ {
+ int native = 1;
+ if (!array_is_native(ary))
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "Array must have native byteorder. "
+ "A byte-swapped array was given");
+ native = 0;
}
- sprintf(s, " or %d", exact_dimensions[n-1]);
- strcat(dims_str,s);
- PyErr_Format(PyExc_TypeError,
- "Array must be have %s dimensions. Given array has %d dimensions",
- dims_str, array_numdims(ary));
+ return native;
}
- return success;
-}
-
-/* Require the given PyArrayObject to have a specified shape. If the
- * array has the specified shape, return 1. Otherwise, set the python
- * error string and return 0.
- */
-int require_size(PyArrayObject* ary, npy_intp* size, int n) {
- int i;
- int success = 1;
- int len;
- char desired_dims[255] = "[";
- char s[255];
- char actual_dims[255] = "[";
- for(i=0; i < n;i++) {
- if (size[i] != -1 && size[i] != array_size(ary,i)) {
- success = 0;
+
+ /* Require the given PyArrayObject to have a specified number of
+ * dimensions. If the array has the specified number of dimensions,
+ * return 1. Otherwise, set the python error string and return 0.
+ */
+ int require_dimensions(PyArrayObject* ary, int exact_dimensions)
+ {
+ int success = 1;
+ if (array_numdims(ary) != exact_dimensions)
+ {
+ PyErr_Format(PyExc_TypeError,
+ "Array must have %d dimensions. Given array has %d dimensions",
+ exact_dimensions, array_numdims(ary));
+ success = 0;
}
+ return success;
}
- if (!success) {
- for (i = 0; i < n; i++) {
- if (size[i] == -1) {
- sprintf(s, "*,");
+
+ /* Require the given PyArrayObject to have one of a list of specified
+ * number of dimensions. If the array has one of the specified number
+ * of dimensions, return 1. Otherwise, set the python error string
+ * and return 0.
+ */
+ int require_dimensions_n(PyArrayObject* ary, int* exact_dimensions, int n)
+ {
+ int success = 0;
+ int i;
+ char dims_str[255] = "";
+ char s[255];
+ for (i = 0; i < n && !success; i++)
+ {
+ if (array_numdims(ary) == exact_dimensions[i])
+ {
+ success = 1;
+ }
+ }
+ if (!success)
+ {
+ for (i = 0; i < n-1; i++)
+ {
+ sprintf(s, "%d, ", exact_dimensions[i]);
+ strcat(dims_str,s);
}
- else
+ sprintf(s, " or %d", exact_dimensions[n-1]);
+ strcat(dims_str,s);
+ PyErr_Format(PyExc_TypeError,
+ "Array must be have %s dimensions. Given array has %d dimensions",
+ dims_str, array_numdims(ary));
+ }
+ return success;
+ }
+
+ /* Require the given PyArrayObject to have a specified shape. If the
+ * array has the specified shape, return 1. Otherwise, set the python
+ * error string and return 0.
+ */
+ int require_size(PyArrayObject* ary, npy_intp* size, int n)
+ {
+ int i;
+ int success = 1;
+ int len;
+ char desired_dims[255] = "[";
+ char s[255];
+ char actual_dims[255] = "[";
+ for(i=0; i < n;i++)
+ {
+ if (size[i] != -1 && size[i] != array_size(ary,i))
{
- sprintf(s, "%ld,", (long int)size[i]);
- }
- strcat(desired_dims,s);
+ success = 0;
+ }
}
- len = strlen(desired_dims);
- desired_dims[len-1] = ']';
- for (i = 0; i < n; i++) {
- sprintf(s, "%ld,", (long int)array_size(ary,i));
- strcat(actual_dims,s);
+ if (!success)
+ {
+ for (i = 0; i < n; i++)
+ {
+ if (size[i] == -1)
+ {
+ sprintf(s, "*,");
+ }
+ else
+ {
+ sprintf(s, "%ld,", (long int)size[i]);
+ }
+ strcat(desired_dims,s);
+ }
+ len = strlen(desired_dims);
+ desired_dims[len-1] = ']';
+ for (i = 0; i < n; i++)
+ {
+ sprintf(s, "%ld,", (long int)array_size(ary,i));
+ strcat(actual_dims,s);
+ }
+ len = strlen(actual_dims);
+ actual_dims[len-1] = ']';
+ PyErr_Format(PyExc_TypeError,
+ "Array must be have shape of %s. Given array has shape of %s",
+ desired_dims, actual_dims);
}
- len = strlen(actual_dims);
- actual_dims[len-1] = ']';
- PyErr_Format(PyExc_TypeError,
- "Array must be have shape of %s. Given array has shape of %s",
- desired_dims, actual_dims);
+ return success;
}
- return success;
}
/* End John Hunter translation (with modifications by Bill Spotz)
*/
-%}
-
/* %numpy_typemaps() macro
*
* This macro defines a family of 23 typemaps that allow C arguments
@@ -452,18 +514,22 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE IN_ARRAY1[ANY])
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE IN_ARRAY1[ANY])
{
$1 = is_array($input) || PySequence_Check($input);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE IN_ARRAY1[ANY])
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[1] = { $1_dim0 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object);
- if (!array || !require_dimensions(array, 1) || !require_size(array, size, 1)) SWIG_fail;
+ array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ &is_new_object);
+ if (!array || !require_dimensions(array, 1) ||
+ !require_size(array, size, 1)) SWIG_fail;
$1 = ($1_ltype) array_data(array);
}
%typemap(freearg)
@@ -475,18 +541,22 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
{
$1 = is_array($input) || PySequence_Check($input);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[1] = { -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object);
- if (!array || !require_dimensions(array, 1) || !require_size(array, size, 1)) SWIG_fail;
+ array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ &is_new_object);
+ if (!array || !require_dimensions(array, 1) ||
+ !require_size(array, size, 1)) SWIG_fail;
$1 = (DATA_TYPE*) array_data(array);
$2 = (DIM_TYPE) array_size(array,0);
}
@@ -499,18 +569,22 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
{
$1 = is_array($input) || PySequence_Check($input);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[1] = {-1};
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object);
- if (!array || !require_dimensions(array, 1) || !require_size(array, size, 1)) SWIG_fail;
+ array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ &is_new_object);
+ if (!array || !require_dimensions(array, 1) ||
+ !require_size(array, size, 1)) SWIG_fail;
$1 = (DIM_TYPE) array_size(array,0);
$2 = (DATA_TYPE*) array_data(array);
}
@@ -523,18 +597,22 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE IN_ARRAY2[ANY][ANY])
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE IN_ARRAY2[ANY][ANY])
{
$1 = is_array($input) || PySequence_Check($input);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE IN_ARRAY2[ANY][ANY])
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[2] = { $1_dim0, $1_dim1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object);
- if (!array || !require_dimensions(array, 2) || !require_size(array, size, 2)) SWIG_fail;
+ array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ &is_new_object);
+ if (!array || !require_dimensions(array, 2) ||
+ !require_size(array, size, 2)) SWIG_fail;
$1 = ($1_ltype) array_data(array);
}
%typemap(freearg)
@@ -546,18 +624,22 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
{
$1 = is_array($input) || PySequence_Check($input);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[2] = { -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object);
- if (!array || !require_dimensions(array, 2) || !require_size(array, size, 2)) SWIG_fail;
+ array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ &is_new_object);
+ if (!array || !require_dimensions(array, 2) ||
+ !require_size(array, size, 2)) SWIG_fail;
$1 = (DATA_TYPE*) array_data(array);
$2 = (DIM_TYPE) array_size(array,0);
$3 = (DIM_TYPE) array_size(array,1);
@@ -571,18 +653,22 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
{
$1 = is_array($input) || PySequence_Check($input);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[2] = { -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object);
- if (!array || !require_dimensions(array, 2) || !require_size(array, size, 2)) SWIG_fail;
+ array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ &is_new_object);
+ if (!array || !require_dimensions(array, 2) ||
+ !require_size(array, size, 2)) SWIG_fail;
$1 = (DIM_TYPE) array_size(array,0);
$2 = (DIM_TYPE) array_size(array,1);
$3 = (DATA_TYPE*) array_data(array);
@@ -596,18 +682,22 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
{
$1 = is_array($input) || PySequence_Check($input);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object);
- if (!array || !require_dimensions(array, 3) || !require_size(array, size, 3)) SWIG_fail;
+ array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ &is_new_object);
+ if (!array || !require_dimensions(array, 3) ||
+ !require_size(array, size, 3)) SWIG_fail;
$1 = ($1_ltype) array_data(array);
}
%typemap(freearg)
@@ -620,18 +710,22 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
* DIM_TYPE DIM3)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
{
$1 = is_array($input) || PySequence_Check($input);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[3] = { -1, -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object);
- if (!array || !require_dimensions(array, 3) || !require_size(array, size, 3)) SWIG_fail;
+ array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ &is_new_object);
+ if (!array || !require_dimensions(array, 3) ||
+ !require_size(array, size, 3)) SWIG_fail;
$1 = (DATA_TYPE*) array_data(array);
$2 = (DIM_TYPE) array_size(array,0);
$3 = (DIM_TYPE) array_size(array,1);
@@ -647,18 +741,22 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
* DATA_TYPE* IN_ARRAY3)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
{
$1 = is_array($input) || PySequence_Check($input);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[3] = { -1, -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE, &is_new_object);
- if (!array || !require_dimensions(array, 3) || !require_size(array, size, 3)) SWIG_fail;
+ array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ &is_new_object);
+ if (!array || !require_dimensions(array, 3) ||
+ !require_size(array, size, 3)) SWIG_fail;
$1 = (DIM_TYPE) array_size(array,0);
$2 = (DIM_TYPE) array_size(array,1);
$3 = (DIM_TYPE) array_size(array,2);
@@ -677,30 +775,36 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE INPLACE_ARRAY1[ANY])
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE INPLACE_ARRAY1[ANY])
{
- $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),DATA_TYPECODE);
+ $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+ DATA_TYPECODE);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE INPLACE_ARRAY1[ANY])
(PyArrayObject* array=NULL)
{
npy_intp size[1] = { $1_dim0 };
array = obj_to_array_no_conversion($input, DATA_TYPECODE);
- if (!array || !require_dimensions(array,1) || !require_size(array, size, 1)
- || !require_contiguous(array) || !require_native(array)) SWIG_fail;
+ if (!array || !require_dimensions(array,1) || !require_size(array, size, 1) ||
+ !require_contiguous(array) || !require_native(array)) SWIG_fail;
$1 = ($1_ltype) array_data(array);
}
/* Typemap suite for (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
{
- $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),DATA_TYPECODE);
+ $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+ DATA_TYPECODE);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
(PyArrayObject* array=NULL, int i=1)
{
@@ -714,12 +818,15 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
{
- $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),DATA_TYPECODE);
+ $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+ DATA_TYPECODE);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
(PyArrayObject* array=NULL, int i=0)
{
@@ -733,30 +840,36 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
{
- $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),DATA_TYPECODE);
+ $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+ DATA_TYPECODE);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
(PyArrayObject* array=NULL)
{
npy_intp size[2] = { $1_dim0, $1_dim1 };
array = obj_to_array_no_conversion($input, DATA_TYPECODE);
- if (!array || !require_dimensions(array,2) || !require_size(array, size, 2)
- || !require_contiguous(array) || !require_native(array)) SWIG_fail;
+ if (!array || !require_dimensions(array,2) || !require_size(array, size, 2) ||
+ !require_contiguous(array) || !require_native(array)) SWIG_fail;
$1 = ($1_ltype) array_data(array);
}
/* Typemap suite for (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
{
- $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),DATA_TYPECODE);
+ $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+ DATA_TYPECODE);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
(PyArrayObject* array=NULL)
{
@@ -770,18 +883,21 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
{
- $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),DATA_TYPECODE);
+ $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+ DATA_TYPECODE);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
(PyArrayObject* array=NULL)
{
array = obj_to_array_no_conversion($input, DATA_TYPECODE);
- if (!array || !require_dimensions(array,2) || !require_contiguous(array)
- || !require_native(array)) SWIG_fail;
+ if (!array || !require_dimensions(array,2) || !require_contiguous(array) ||
+ !require_native(array)) SWIG_fail;
$1 = (DIM_TYPE) array_size(array,0);
$2 = (DIM_TYPE) array_size(array,1);
$3 = (DATA_TYPE*) array_data(array);
@@ -789,37 +905,43 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
{
- $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),DATA_TYPECODE);
+ $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+ DATA_TYPECODE);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
(PyArrayObject* array=NULL)
{
npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 };
array = obj_to_array_no_conversion($input, DATA_TYPECODE);
- if (!array || !require_dimensions(array,3) || !require_size(array, size, 3)
- || !require_contiguous(array) || !require_native(array)) SWIG_fail;
+ if (!array || !require_dimensions(array,3) || !require_size(array, size, 3) ||
+ !require_contiguous(array) || !require_native(array)) SWIG_fail;
$1 = ($1_ltype) array_data(array);
}
/* Typemap suite for (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
* DIM_TYPE DIM3)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
{
- $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),DATA_TYPECODE);
+ $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+ DATA_TYPECODE);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
(PyArrayObject* array=NULL)
{
array = obj_to_array_no_conversion($input, DATA_TYPECODE);
- if (!array || !require_dimensions(array,3) || !require_contiguous(array)
- || !require_native(array)) SWIG_fail;
+ if (!array || !require_dimensions(array,3) || !require_contiguous(array) ||
+ !require_native(array)) SWIG_fail;
$1 = (DATA_TYPE*) array_data(array);
$2 = (DIM_TYPE) array_size(array,0);
$3 = (DIM_TYPE) array_size(array,1);
@@ -829,12 +951,15 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
* DATA_TYPE* INPLACE_ARRAY3)
*/
-%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY)
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
+ fragment="NumPy_Macros")
(DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
{
- $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),DATA_TYPECODE);
+ $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
+ DATA_TYPECODE);
}
-%typemap(in)
+%typemap(in,
+ fragment="NumPy_Object_to_Array,NumPy_Array_Requirements")
(DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
(PyArrayObject* array=NULL)
{
@@ -853,7 +978,8 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE ARGOUT_ARRAY1[ANY])
*/
-%typemap(in,numinputs=0)
+%typemap(in,numinputs=0,
+ fragment="NumPy_Backward_Compatibility,NumPy_Macros")
(DATA_TYPE ARGOUT_ARRAY1[ANY])
(PyObject * array = NULL)
{
@@ -869,12 +995,14 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
*/
-%typemap(in,numinputs=1)
+%typemap(in,numinputs=1,
+ fragment="NumPy_Backward_Compatibility,NumPy_Macros,NumPy_Utilities")
(DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
(PyObject * array = NULL)
{
npy_intp dims[1];
- if (!PyInt_Check($input)) {
+ if (!PyInt_Check($input))
+ {
char* typestring = pytype_string($input);
PyErr_Format(PyExc_TypeError,
"Int dimension expected. '%s' given.",
@@ -894,12 +1022,14 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
*/
-%typemap(in,numinputs=1)
+%typemap(in,numinputs=1,
+ fragment="NumPy_Backward_Compatibility,NumPy_Macros,NumPy_Utilities")
(DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
(PyObject * array = NULL)
{
npy_intp dims[1];
- if (!PyInt_Check($input)) {
+ if (!PyInt_Check($input))
+ {
char* typestring = pytype_string($input);
PyErr_Format(PyExc_TypeError,
"Int dimension expected. '%s' given.",
@@ -919,7 +1049,8 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
*/
-%typemap(in,numinputs=0)
+%typemap(in,numinputs=0,
+ fragment="NumPy_Backward_Compatibility,NumPy_Macros")
(DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
(PyObject * array = NULL)
{
@@ -935,7 +1066,8 @@ int require_size(PyArrayObject* ary, npy_intp* size, int n) {
/* Typemap suite for (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
*/
-%typemap(in,numinputs=0)
+%typemap(in,numinputs=0,
+ fragment="NumPy_Backward_Compatibility,NumPy_Macros")
(DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
(PyObject * array = NULL)
{
diff --git a/numpy/doc/swig/pyfragments.swg b/numpy/doc/swig/pyfragments.swg
index 8a21c131e..e43484b81 100644
--- a/numpy/doc/swig/pyfragments.swg
+++ b/numpy/doc/swig/pyfragments.swg
@@ -1,9 +1,53 @@
-// Override the SWIG_AsVal_frag(long) fragment so that it also checks
-// for numpy scalar array types. The code through the %#endif is
-// essentially cut-and-paste from pyprimtype.swg
+/* For numpy versions prior to 1.0, the names of certain data types
+ * are different than in later versions. This fragment provides macro
+ * substitutions that allow us to support old and new versions on
+ * numpy.
+ */
+
+%fragment("NumPy_Backward_Compatibility", "header")
+{
+/* Support older NumPy data type names
+*/
+%#if NDARRAY_VERSION < 0x01000000
+%#define NPY_BOOL PyArray_BOOL
+%#define NPY_BYTE PyArray_BYTE
+%#define NPY_UBYTE PyArray_UBYTE
+%#define NPY_SHORT PyArray_SHORT
+%#define NPY_USHORT PyArray_USHORT
+%#define NPY_INT PyArray_INT
+%#define NPY_UINT PyArray_UINT
+%#define NPY_LONG PyArray_LONG
+%#define NPY_ULONG PyArray_ULONG
+%#define NPY_LONGLONG PyArray_LONGLONG
+%#define NPY_ULONGLONG PyArray_ULONGLONG
+%#define NPY_FLOAT PyArray_FLOAT
+%#define NPY_DOUBLE PyArray_DOUBLE
+%#define NPY_LONGDOUBLE PyArray_LONGDOUBLE
+%#define NPY_CFLOAT PyArray_CFLOAT
+%#define NPY_CDOUBLE PyArray_CDOUBLE
+%#define NPY_CLONGDOUBLE PyArray_CLONGDOUBLE
+%#define NPY_OBJECT PyArray_OBJECT
+%#define NPY_STRING PyArray_STRING
+%#define NPY_UNICODE PyArray_UNICODE
+%#define NPY_VOID PyArray_VOID
+%#define NPY_NTYPES PyArray_NTYPES
+%#define NPY_NOTYPE PyArray_NOTYPE
+%#define NPY_CHAR PyArray_CHAR
+%#define NPY_USERDEF PyArray_USERDEF
+%#define npy_intp intp
+%#endif
+}
+
+/**********************************************************************/
+
+/* Override the SWIG_AsVal_frag(long) fragment so that it also checks
+ * for numpy scalar array types. The code through the %#endif is
+ * essentially cut-and-paste from pyprimtype.swg
+ */
%fragment(SWIG_AsVal_frag(long), "header",
- fragment="SWIG_CanCastAsInteger")
+ fragment="SWIG_CanCastAsInteger",
+ fragment="NumPy_Backward_Compatibility")
{
SWIGINTERN int
SWIG_AsVal_dec(long)(PyObject * obj, long * val)