chiark / gitweb /
minor typo fixes
[nlopt.git] / swig / numpy.i
1 /* -*- C -*-  (not really, but good for syntax highlighting) */
2
3 /*
4 Copyright (c) 2005-2009, NumPy Developers.
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are
9 met:
10
11     * Redistributions of source code must retain the above copyright
12        notice, this list of conditions and the following disclaimer.
13
14     * Redistributions in binary form must reproduce the above
15        copyright notice, this list of conditions and the following
16        disclaimer in the documentation and/or other materials provided
17        with the distribution.
18
19     * Neither the name of the NumPy Developers nor the names of any
20        contributors may be used to endorse or promote products derived
21        from this software without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #ifdef SWIGPYTHON
37
38 %{
39 #ifndef SWIG_FILE_WITH_INIT
40 #  define NO_IMPORT_ARRAY
41 #endif
42 #include "stdio.h"
43 #include <numpy/arrayobject.h>
44 %}
45
46 /**********************************************************************/
47
48 %fragment("NumPy_Backward_Compatibility", "header")
49 {
50 /* Support older NumPy data type names
51 */
52 %#if NDARRAY_VERSION < 0x01000000
53 %#define NPY_BOOL          PyArray_BOOL
54 %#define NPY_BYTE          PyArray_BYTE
55 %#define NPY_UBYTE         PyArray_UBYTE
56 %#define NPY_SHORT         PyArray_SHORT
57 %#define NPY_USHORT        PyArray_USHORT
58 %#define NPY_INT           PyArray_INT
59 %#define NPY_UINT          PyArray_UINT
60 %#define NPY_LONG          PyArray_LONG
61 %#define NPY_ULONG         PyArray_ULONG
62 %#define NPY_LONGLONG      PyArray_LONGLONG
63 %#define NPY_ULONGLONG     PyArray_ULONGLONG
64 %#define NPY_FLOAT         PyArray_FLOAT
65 %#define NPY_DOUBLE        PyArray_DOUBLE
66 %#define NPY_LONGDOUBLE    PyArray_LONGDOUBLE
67 %#define NPY_CFLOAT        PyArray_CFLOAT
68 %#define NPY_CDOUBLE       PyArray_CDOUBLE
69 %#define NPY_CLONGDOUBLE   PyArray_CLONGDOUBLE
70 %#define NPY_OBJECT        PyArray_OBJECT
71 %#define NPY_STRING        PyArray_STRING
72 %#define NPY_UNICODE       PyArray_UNICODE
73 %#define NPY_VOID          PyArray_VOID
74 %#define NPY_NTYPES        PyArray_NTYPES
75 %#define NPY_NOTYPE        PyArray_NOTYPE
76 %#define NPY_CHAR          PyArray_CHAR
77 %#define NPY_USERDEF       PyArray_USERDEF
78 %#define npy_intp          intp
79
80 %#define NPY_MAX_BYTE      MAX_BYTE
81 %#define NPY_MIN_BYTE      MIN_BYTE
82 %#define NPY_MAX_UBYTE     MAX_UBYTE
83 %#define NPY_MAX_SHORT     MAX_SHORT
84 %#define NPY_MIN_SHORT     MIN_SHORT
85 %#define NPY_MAX_USHORT    MAX_USHORT
86 %#define NPY_MAX_INT       MAX_INT
87 %#define NPY_MIN_INT       MIN_INT
88 %#define NPY_MAX_UINT      MAX_UINT
89 %#define NPY_MAX_LONG      MAX_LONG
90 %#define NPY_MIN_LONG      MIN_LONG
91 %#define NPY_MAX_ULONG     MAX_ULONG
92 %#define NPY_MAX_LONGLONG  MAX_LONGLONG
93 %#define NPY_MIN_LONGLONG  MIN_LONGLONG
94 %#define NPY_MAX_ULONGLONG MAX_ULONGLONG
95 %#define NPY_MAX_INTP      MAX_INTP
96 %#define NPY_MIN_INTP      MIN_INTP
97
98 %#define NPY_FARRAY        FARRAY
99 %#define NPY_F_CONTIGUOUS  F_CONTIGUOUS
100 %#endif
101 }
102
103 /**********************************************************************/
104
105 /* The following code originally appeared in
106  * enthought/kiva/agg/src/numeric.i written by Eric Jones.  It was
107  * translated from C++ to C by John Hunter.  Bill Spotz has modified
108  * it to fix some minor bugs, upgrade from Numeric to numpy (all
109  * versions), add some comments and functionality, and convert from
110  * direct code insertion to SWIG fragments.
111  */
112
113 %fragment("NumPy_Macros", "header")
114 {
115 /* Macros to extract array attributes.
116  */
117 %#define is_array(a)            ((a) && PyArray_Check((PyArrayObject *)a))
118 %#define array_type(a)          (int)(PyArray_TYPE(a))
119 %#define array_numdims(a)       (((PyArrayObject *)a)->nd)
120 %#define array_dimensions(a)    (((PyArrayObject *)a)->dimensions)
121 %#define array_size(a,i)        (((PyArrayObject *)a)->dimensions[i])
122 %#define array_data(a)          (((PyArrayObject *)a)->data)
123 %#define array_is_contiguous(a) (PyArray_ISCONTIGUOUS(a))
124 %#define array_is_native(a)     (PyArray_ISNOTSWAPPED(a))
125 %#define array_is_fortran(a)    (PyArray_ISFORTRAN(a))
126 }
127
128 /**********************************************************************/
129
130 %fragment("NumPy_Utilities", "header")
131 {
132   /* Given a PyObject, return a string describing its type.
133    */
134   char* pytype_string(PyObject* py_obj) {
135     if (py_obj == NULL          ) return "C NULL value";
136     if (py_obj == Py_None       ) return "Python None" ;
137     if (PyCallable_Check(py_obj)) return "callable"    ;
138     if (PyString_Check(  py_obj)) return "string"      ;
139     if (PyInt_Check(     py_obj)) return "int"         ;
140     if (PyFloat_Check(   py_obj)) return "float"       ;
141     if (PyDict_Check(    py_obj)) return "dict"        ;
142     if (PyList_Check(    py_obj)) return "list"        ;
143     if (PyTuple_Check(   py_obj)) return "tuple"       ;
144     if (PyFile_Check(    py_obj)) return "file"        ;
145     if (PyModule_Check(  py_obj)) return "module"      ;
146     if (PyInstance_Check(py_obj)) return "instance"    ;
147
148     return "unknown type";
149   }
150
151   /* Given a NumPy typecode, return a string describing the type.
152    */
153   char* typecode_string(int typecode) {
154     static char* type_names[25] = {"bool", "byte", "unsigned byte",
155                                    "short", "unsigned short", "int",
156                                    "unsigned int", "long", "unsigned long",
157                                    "long long", "unsigned long long",
158                                    "float", "double", "long double",
159                                    "complex float", "complex double",
160                                    "complex long double", "object",
161                                    "string", "unicode", "void", "ntypes",
162                                    "notype", "char", "unknown"};
163     return typecode < 24 ? type_names[typecode] : type_names[24];
164   }
165
166   /* Make sure input has correct numpy type.  Allow character and byte
167    * to match.  Also allow int and long to match.  This is deprecated.
168    * You should use PyArray_EquivTypenums() instead.
169    */
170   int type_match(int actual_type, int desired_type) {
171     return PyArray_EquivTypenums(actual_type, desired_type);
172   }
173 }
174
175 /**********************************************************************/
176
177 %fragment("NumPy_Object_to_Array", "header",
178           fragment="NumPy_Backward_Compatibility",
179           fragment="NumPy_Macros",
180           fragment="NumPy_Utilities")
181 {
182   /* Given a PyObject pointer, cast it to a PyArrayObject pointer if
183    * legal.  If not, set the python error string appropriately and
184    * return NULL.
185    */
186   PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode)
187   {
188     PyArrayObject* ary = NULL;
189     if (is_array(input) && (typecode == NPY_NOTYPE ||
190                             PyArray_EquivTypenums(array_type(input), typecode)))
191     {
192       ary = (PyArrayObject*) input;
193     }
194     else if is_array(input)
195     {
196       char* desired_type = typecode_string(typecode);
197       char* actual_type  = typecode_string(array_type(input));
198       PyErr_Format(PyExc_TypeError,
199                    "Array of type '%s' required.  Array of type '%s' given",
200                    desired_type, actual_type);
201       ary = NULL;
202     }
203     else
204     {
205       char * desired_type = typecode_string(typecode);
206       char * actual_type  = pytype_string(input);
207       PyErr_Format(PyExc_TypeError,
208                    "Array of type '%s' required.  A '%s' was given",
209                    desired_type, actual_type);
210       ary = NULL;
211     }
212     return ary;
213   }
214
215   /* Convert the given PyObject to a NumPy array with the given
216    * typecode.  On success, return a valid PyArrayObject* with the
217    * correct type.  On failure, the python error string will be set and
218    * the routine returns NULL.
219    */
220   PyArrayObject* obj_to_array_allow_conversion(PyObject* input, int typecode,
221                                                int* is_new_object)
222   {
223     PyArrayObject* ary = NULL;
224     PyObject* py_obj;
225     if (is_array(input) && (typecode == NPY_NOTYPE ||
226                             PyArray_EquivTypenums(array_type(input),typecode)))
227     {
228       ary = (PyArrayObject*) input;
229       *is_new_object = 0;
230     }
231     else
232     {
233       py_obj = PyArray_FromObject(input, typecode, 0, 0);
234       /* If NULL, PyArray_FromObject will have set python error value.*/
235       ary = (PyArrayObject*) py_obj;
236       *is_new_object = 1;
237     }
238     return ary;
239   }
240
241   /* Given a PyArrayObject, check to see if it is contiguous.  If so,
242    * return the input pointer and flag it as not a new object.  If it is
243    * not contiguous, create a new PyArrayObject using the original data,
244    * flag it as a new object and return the pointer.
245    */
246   PyArrayObject* make_contiguous(PyArrayObject* ary, int* is_new_object,
247                                  int min_dims, int max_dims)
248   {
249     PyArrayObject* result;
250     if (array_is_contiguous(ary))
251     {
252       result = ary;
253       *is_new_object = 0;
254     }
255     else
256     {
257       result = (PyArrayObject*) PyArray_ContiguousFromObject((PyObject*)ary,
258                                                              array_type(ary),
259                                                              min_dims,
260                                                              max_dims);
261       *is_new_object = 1;
262     }
263     return result;
264   }
265
266   /* Convert a given PyObject to a contiguous PyArrayObject of the
267    * specified type.  If the input object is not a contiguous
268    * PyArrayObject, a new one will be created and the new object flag
269    * will be set.
270    */
271   PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject* input,
272                                                           int typecode,
273                                                           int* is_new_object)
274   {
275     int is_new1 = 0;
276     int is_new2 = 0;
277     PyArrayObject* ary2;
278     PyArrayObject* ary1 = obj_to_array_allow_conversion(input, typecode,
279                                                         &is_new1);
280     if (ary1)
281     {
282       ary2 = make_contiguous(ary1, &is_new2, 0, 0);
283       if ( is_new1 && is_new2)
284       {
285         Py_DECREF(ary1);
286       }
287       ary1 = ary2;
288     }
289     *is_new_object = is_new1 || is_new2;
290     return ary1;
291   }
292 }
293
294 /**********************************************************************/
295
296 %fragment("NumPy_Array_Requirements", "header",
297           fragment="NumPy_Backward_Compatibility",
298           fragment="NumPy_Macros")
299 {
300   /* Test whether a python object is contiguous.  If array is
301    * contiguous, return 1.  Otherwise, set the python error string and
302    * return 0.
303    */
304   int require_contiguous(PyArrayObject* ary)
305   {
306     int contiguous = 1;
307     if (!array_is_contiguous(ary))
308     {
309       PyErr_SetString(PyExc_TypeError,
310                       "Array must be contiguous.  A non-contiguous array was given");
311       contiguous = 0;
312     }
313     return contiguous;
314   }
315
316   /* Require that a numpy array is not byte-swapped.  If the array is
317    * not byte-swapped, return 1.  Otherwise, set the python error string
318    * and return 0.
319    */
320   int require_native(PyArrayObject* ary)
321   {
322     int native = 1;
323     if (!array_is_native(ary))
324     {
325       PyErr_SetString(PyExc_TypeError,
326                       "Array must have native byteorder.  "
327                       "A byte-swapped array was given");
328       native = 0;
329     }
330     return native;
331   }
332
333   /* Require the given PyArrayObject to have a specified number of
334    * dimensions.  If the array has the specified number of dimensions,
335    * return 1.  Otherwise, set the python error string and return 0.
336    */
337   int require_dimensions(PyArrayObject* ary, int exact_dimensions)
338   {
339     int success = 1;
340     if (array_numdims(ary) != exact_dimensions)
341     {
342       PyErr_Format(PyExc_TypeError,
343                    "Array must have %d dimensions.  Given array has %d dimensions",
344                    exact_dimensions, array_numdims(ary));
345       success = 0;
346     }
347     return success;
348   }
349
350   /* Require the given PyArrayObject to have one of a list of specified
351    * number of dimensions.  If the array has one of the specified number
352    * of dimensions, return 1.  Otherwise, set the python error string
353    * and return 0.
354    */
355   int require_dimensions_n(PyArrayObject* ary, int* exact_dimensions, int n)
356   {
357     int success = 0;
358     int i;
359     char dims_str[255] = "";
360     char s[255];
361     for (i = 0; i < n && !success; i++)
362     {
363       if (array_numdims(ary) == exact_dimensions[i])
364       {
365         success = 1;
366       }
367     }
368     if (!success)
369     {
370       for (i = 0; i < n-1; i++)
371       {
372         sprintf(s, "%d, ", exact_dimensions[i]);
373         strcat(dims_str,s);
374       }
375       sprintf(s, " or %d", exact_dimensions[n-1]);
376       strcat(dims_str,s);
377       PyErr_Format(PyExc_TypeError,
378                    "Array must have %s dimensions.  Given array has %d dimensions",
379                    dims_str, array_numdims(ary));
380     }
381     return success;
382   }
383
384   /* Require the given PyArrayObject to have a specified shape.  If the
385    * array has the specified shape, return 1.  Otherwise, set the python
386    * error string and return 0.
387    */
388   int require_size(PyArrayObject* ary, npy_intp* size, int n)
389   {
390     int i;
391     int success = 1;
392     int len;
393     char desired_dims[255] = "[";
394     char s[255];
395     char actual_dims[255] = "[";
396     for(i=0; i < n;i++)
397     {
398       if (size[i] != -1 &&  size[i] != array_size(ary,i))
399       {
400         success = 0;
401       }
402     }
403     if (!success)
404     {
405       for (i = 0; i < n; i++)
406       {
407         if (size[i] == -1)
408         {
409           sprintf(s, "*,");
410         }
411         else
412         {
413           sprintf(s, "%ld,", (long int)size[i]);
414         }
415         strcat(desired_dims,s);
416       }
417       len = strlen(desired_dims);
418       desired_dims[len-1] = ']';
419       for (i = 0; i < n; i++)
420       {
421         sprintf(s, "%ld,", (long int)array_size(ary,i));
422         strcat(actual_dims,s);
423       }
424       len = strlen(actual_dims);
425       actual_dims[len-1] = ']';
426       PyErr_Format(PyExc_TypeError,
427                    "Array must have shape of %s.  Given array has shape of %s",
428                    desired_dims, actual_dims);
429     }
430     return success;
431   }
432
433   /* Require the given PyArrayObject to to be FORTRAN ordered.  If the
434    * the PyArrayObject is already FORTRAN ordered, do nothing.  Else,
435    * set the FORTRAN ordering flag and recompute the strides.
436    */
437   int require_fortran(PyArrayObject* ary)
438   {
439     int success = 1;
440     int nd = array_numdims(ary);
441     int i;
442     if (array_is_fortran(ary)) return success;
443     /* Set the FORTRAN ordered flag */
444     ary->flags = NPY_FARRAY;
445     /* Recompute the strides */
446     ary->strides[0] = ary->strides[nd-1];
447     for (i=1; i < nd; ++i)
448       ary->strides[i] = ary->strides[i-1] * array_size(ary,i-1);
449     return success;
450   }
451 }
452
453 /* Combine all NumPy fragments into one for convenience */
454 %fragment("NumPy_Fragments", "header",
455           fragment="NumPy_Backward_Compatibility",
456           fragment="NumPy_Macros",
457           fragment="NumPy_Utilities",
458           fragment="NumPy_Object_to_Array",
459           fragment="NumPy_Array_Requirements") { }
460
461 /* End John Hunter translation (with modifications by Bill Spotz)
462  */
463
464 /* %numpy_typemaps() macro
465  *
466  * This macro defines a family of 41 typemaps that allow C arguments
467  * of the form
468  *
469  *     (DATA_TYPE IN_ARRAY1[ANY])
470  *     (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
471  *     (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
472  *
473  *     (DATA_TYPE IN_ARRAY2[ANY][ANY])
474  *     (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
475  *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
476  *     (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
477  *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
478  *
479  *     (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
480  *     (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
481  *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
482  *     (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
483  *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
484  *
485  *     (DATA_TYPE INPLACE_ARRAY1[ANY])
486  *     (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
487  *     (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
488  *
489  *     (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
490  *     (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
491  *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
492  *     (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
493  *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
494  *
495  *     (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
496  *     (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
497  *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
498  *     (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
499  *     (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3)
500  *
501  *     (DATA_TYPE ARGOUT_ARRAY1[ANY])
502  *     (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
503  *     (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
504  *
505  *     (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
506  *
507  *     (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
508  *
509  *     (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1)
510  *     (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
511  *
512  *     (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
513  *     (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
514  *     (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
515  *     (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2)
516  *
517  *     (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
518  *     (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
519  *     (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
520  *     (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3)
521  *
522  * where "DATA_TYPE" is any type supported by the NumPy module, and
523  * "DIM_TYPE" is any int-like type suitable for specifying dimensions.
524  * The difference between "ARRAY" typemaps and "FARRAY" typemaps is
525  * that the "FARRAY" typemaps expect FORTRAN ordering of
526  * multidimensional arrays.  In python, the dimensions will not need
527  * to be specified (except for the "DATA_TYPE* ARGOUT_ARRAY1"
528  * typemaps).  The IN_ARRAYs can be a numpy array or any sequence that
529  * can be converted to a numpy array of the specified type.  The
530  * INPLACE_ARRAYs must be numpy arrays of the appropriate type.  The
531  * ARGOUT_ARRAYs will be returned as new numpy arrays of the
532  * appropriate type.
533  *
534  * These typemaps can be applied to existing functions using the
535  * %apply directive.  For example:
536  *
537  *     %apply (double* IN_ARRAY1, int DIM1) {(double* series, int length)};
538  *     double prod(double* series, int length);
539  *
540  *     %apply (int DIM1, int DIM2, double* INPLACE_ARRAY2)
541  *           {(int rows, int cols, double* matrix        )};
542  *     void floor(int rows, int cols, double* matrix, double f);
543  *
544  *     %apply (double IN_ARRAY3[ANY][ANY][ANY])
545  *           {(double tensor[2][2][2]         )};
546  *     %apply (double ARGOUT_ARRAY3[ANY][ANY][ANY])
547  *           {(double low[2][2][2]                )};
548  *     %apply (double ARGOUT_ARRAY3[ANY][ANY][ANY])
549  *           {(double upp[2][2][2]                )};
550  *     void luSplit(double tensor[2][2][2],
551  *                  double low[2][2][2],
552  *                  double upp[2][2][2]    );
553  *
554  * or directly with
555  *
556  *     double prod(double* IN_ARRAY1, int DIM1);
557  *
558  *     void floor(int DIM1, int DIM2, double* INPLACE_ARRAY2, double f);
559  *
560  *     void luSplit(double IN_ARRAY3[ANY][ANY][ANY],
561  *                  double ARGOUT_ARRAY3[ANY][ANY][ANY],
562  *                  double ARGOUT_ARRAY3[ANY][ANY][ANY]);
563  */
564
565 %define %numpy_typemaps(DATA_TYPE, DATA_TYPECODE, DIM_TYPE)
566
567 /************************/
568 /* Input Array Typemaps */
569 /************************/
570
571 /* Typemap suite for (DATA_TYPE IN_ARRAY1[ANY])
572  */
573 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
574            fragment="NumPy_Macros")
575   (DATA_TYPE IN_ARRAY1[ANY])
576 {
577   $1 = is_array($input) || PySequence_Check($input);
578 }
579 %typemap(in,
580          fragment="NumPy_Fragments")
581   (DATA_TYPE IN_ARRAY1[ANY])
582   (PyArrayObject* array=NULL, int is_new_object=0)
583 {
584   npy_intp size[1] = { $1_dim0 };
585   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
586                                                    &is_new_object);
587   if (!array || !require_dimensions(array, 1) ||
588       !require_size(array, size, 1)) SWIG_fail;
589   $1 = ($1_ltype) array_data(array);
590 }
591 %typemap(freearg)
592   (DATA_TYPE IN_ARRAY1[ANY])
593 {
594   if (is_new_object$argnum && array$argnum)
595     { Py_DECREF(array$argnum); }
596 }
597
598 /* Typemap suite for (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
599  */
600 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
601            fragment="NumPy_Macros")
602   (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
603 {
604   $1 = is_array($input) || PySequence_Check($input);
605 }
606 %typemap(in,
607          fragment="NumPy_Fragments")
608   (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
609   (PyArrayObject* array=NULL, int is_new_object=0)
610 {
611   npy_intp size[1] = { -1 };
612   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
613                                                    &is_new_object);
614   if (!array || !require_dimensions(array, 1) ||
615       !require_size(array, size, 1)) SWIG_fail;
616   $1 = (DATA_TYPE*) array_data(array);
617   $2 = (DIM_TYPE) array_size(array,0);
618 }
619 %typemap(freearg)
620   (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
621 {
622   if (is_new_object$argnum && array$argnum)
623     { Py_DECREF(array$argnum); }
624 }
625
626 /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
627  */
628 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
629            fragment="NumPy_Macros")
630   (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
631 {
632   $1 = is_array($input) || PySequence_Check($input);
633 }
634 %typemap(in,
635          fragment="NumPy_Fragments")
636   (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
637   (PyArrayObject* array=NULL, int is_new_object=0)
638 {
639   npy_intp size[1] = {-1};
640   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
641                                                    &is_new_object);
642   if (!array || !require_dimensions(array, 1) ||
643       !require_size(array, size, 1)) SWIG_fail;
644   $1 = (DIM_TYPE) array_size(array,0);
645   $2 = (DATA_TYPE*) array_data(array);
646 }
647 %typemap(freearg)
648   (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
649 {
650   if (is_new_object$argnum && array$argnum)
651     { Py_DECREF(array$argnum); }
652 }
653
654 /* Typemap suite for (DATA_TYPE IN_ARRAY2[ANY][ANY])
655  */
656 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
657            fragment="NumPy_Macros")
658   (DATA_TYPE IN_ARRAY2[ANY][ANY])
659 {
660   $1 = is_array($input) || PySequence_Check($input);
661 }
662 %typemap(in,
663          fragment="NumPy_Fragments")
664   (DATA_TYPE IN_ARRAY2[ANY][ANY])
665   (PyArrayObject* array=NULL, int is_new_object=0)
666 {
667   npy_intp size[2] = { $1_dim0, $1_dim1 };
668   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
669                                                    &is_new_object);
670   if (!array || !require_dimensions(array, 2) ||
671       !require_size(array, size, 2)) SWIG_fail;
672   $1 = ($1_ltype) array_data(array);
673 }
674 %typemap(freearg)
675   (DATA_TYPE IN_ARRAY2[ANY][ANY])
676 {
677   if (is_new_object$argnum && array$argnum)
678     { Py_DECREF(array$argnum); }
679 }
680
681 /* Typemap suite for (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
682  */
683 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
684            fragment="NumPy_Macros")
685   (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
686 {
687   $1 = is_array($input) || PySequence_Check($input);
688 }
689 %typemap(in,
690          fragment="NumPy_Fragments")
691   (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
692   (PyArrayObject* array=NULL, int is_new_object=0)
693 {
694   npy_intp size[2] = { -1, -1 };
695   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
696                                                    &is_new_object);
697   if (!array || !require_dimensions(array, 2) ||
698       !require_size(array, size, 2)) SWIG_fail;
699   $1 = (DATA_TYPE*) array_data(array);
700   $2 = (DIM_TYPE) array_size(array,0);
701   $3 = (DIM_TYPE) array_size(array,1);
702 }
703 %typemap(freearg)
704   (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
705 {
706   if (is_new_object$argnum && array$argnum)
707     { Py_DECREF(array$argnum); }
708 }
709
710 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
711  */
712 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
713            fragment="NumPy_Macros")
714   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
715 {
716   $1 = is_array($input) || PySequence_Check($input);
717 }
718 %typemap(in,
719          fragment="NumPy_Fragments")
720   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
721   (PyArrayObject* array=NULL, int is_new_object=0)
722 {
723   npy_intp size[2] = { -1, -1 };
724   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
725                                                    &is_new_object);
726   if (!array || !require_dimensions(array, 2) ||
727       !require_size(array, size, 2)) SWIG_fail;
728   $1 = (DIM_TYPE) array_size(array,0);
729   $2 = (DIM_TYPE) array_size(array,1);
730   $3 = (DATA_TYPE*) array_data(array);
731 }
732 %typemap(freearg)
733   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
734 {
735   if (is_new_object$argnum && array$argnum)
736     { Py_DECREF(array$argnum); }
737 }
738
739 /* Typemap suite for (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
740  */
741 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
742            fragment="NumPy_Macros")
743   (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
744 {
745   $1 = is_array($input) || PySequence_Check($input);
746 }
747 %typemap(in,
748          fragment="NumPy_Fragments")
749   (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
750   (PyArrayObject* array=NULL, int is_new_object=0)
751 {
752   npy_intp size[2] = { -1, -1 };
753   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
754                                                    &is_new_object);
755   if (!array || !require_dimensions(array, 2) ||
756       !require_size(array, size, 2) || !require_fortran(array)) SWIG_fail;
757   $1 = (DATA_TYPE*) array_data(array);
758   $2 = (DIM_TYPE) array_size(array,0);
759   $3 = (DIM_TYPE) array_size(array,1);
760 }
761 %typemap(freearg)
762   (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
763 {
764   if (is_new_object$argnum && array$argnum)
765     { Py_DECREF(array$argnum); }
766 }
767
768 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
769  */
770 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
771            fragment="NumPy_Macros")
772   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
773 {
774   $1 = is_array($input) || PySequence_Check($input);
775 }
776 %typemap(in,
777          fragment="NumPy_Fragments")
778   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
779   (PyArrayObject* array=NULL, int is_new_object=0)
780 {
781   npy_intp size[2] = { -1, -1 };
782   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
783                                                    &is_new_object);
784   if (!array || !require_dimensions(array, 2) ||
785       !require_size(array, size, 2) || !require_fortran(array)) SWIG_fail;
786   $1 = (DIM_TYPE) array_size(array,0);
787   $2 = (DIM_TYPE) array_size(array,1);
788   $3 = (DATA_TYPE*) array_data(array);
789 }
790 %typemap(freearg)
791   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
792 {
793   if (is_new_object$argnum && array$argnum)
794     { Py_DECREF(array$argnum); }
795 }
796
797 /* Typemap suite for (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
798  */
799 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
800            fragment="NumPy_Macros")
801   (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
802 {
803   $1 = is_array($input) || PySequence_Check($input);
804 }
805 %typemap(in,
806          fragment="NumPy_Fragments")
807   (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
808   (PyArrayObject* array=NULL, int is_new_object=0)
809 {
810   npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 };
811   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
812                                                    &is_new_object);
813   if (!array || !require_dimensions(array, 3) ||
814       !require_size(array, size, 3)) SWIG_fail;
815   $1 = ($1_ltype) array_data(array);
816 }
817 %typemap(freearg)
818   (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
819 {
820   if (is_new_object$argnum && array$argnum)
821     { Py_DECREF(array$argnum); }
822 }
823
824 /* Typemap suite for (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
825  *                    DIM_TYPE DIM3)
826  */
827 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
828            fragment="NumPy_Macros")
829   (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
830 {
831   $1 = is_array($input) || PySequence_Check($input);
832 }
833 %typemap(in,
834          fragment="NumPy_Fragments")
835   (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
836   (PyArrayObject* array=NULL, int is_new_object=0)
837 {
838   npy_intp size[3] = { -1, -1, -1 };
839   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
840                                                    &is_new_object);
841   if (!array || !require_dimensions(array, 3) ||
842       !require_size(array, size, 3)) SWIG_fail;
843   $1 = (DATA_TYPE*) array_data(array);
844   $2 = (DIM_TYPE) array_size(array,0);
845   $3 = (DIM_TYPE) array_size(array,1);
846   $4 = (DIM_TYPE) array_size(array,2);
847 }
848 %typemap(freearg)
849   (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
850 {
851   if (is_new_object$argnum && array$argnum)
852     { Py_DECREF(array$argnum); }
853 }
854
855 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
856  *                    DATA_TYPE* IN_ARRAY3)
857  */
858 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
859            fragment="NumPy_Macros")
860   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
861 {
862   $1 = is_array($input) || PySequence_Check($input);
863 }
864 %typemap(in,
865          fragment="NumPy_Fragments")
866   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
867   (PyArrayObject* array=NULL, int is_new_object=0)
868 {
869   npy_intp size[3] = { -1, -1, -1 };
870   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
871                                                    &is_new_object);
872   if (!array || !require_dimensions(array, 3) ||
873       !require_size(array, size, 3)) SWIG_fail;
874   $1 = (DIM_TYPE) array_size(array,0);
875   $2 = (DIM_TYPE) array_size(array,1);
876   $3 = (DIM_TYPE) array_size(array,2);
877   $4 = (DATA_TYPE*) array_data(array);
878 }
879 %typemap(freearg)
880   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
881 {
882   if (is_new_object$argnum && array$argnum)
883     { Py_DECREF(array$argnum); }
884 }
885
886 /* Typemap suite for (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
887  *                    DIM_TYPE DIM3)
888  */
889 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
890            fragment="NumPy_Macros")
891   (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
892 {
893   $1 = is_array($input) || PySequence_Check($input);
894 }
895 %typemap(in,
896          fragment="NumPy_Fragments")
897   (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
898   (PyArrayObject* array=NULL, int is_new_object=0)
899 {
900   npy_intp size[3] = { -1, -1, -1 };
901   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
902                                                    &is_new_object);
903   if (!array || !require_dimensions(array, 3) ||
904       !require_size(array, size, 3) | !require_fortran(array)) SWIG_fail;
905   $1 = (DATA_TYPE*) array_data(array);
906   $2 = (DIM_TYPE) array_size(array,0);
907   $3 = (DIM_TYPE) array_size(array,1);
908   $4 = (DIM_TYPE) array_size(array,2);
909 }
910 %typemap(freearg)
911   (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
912 {
913   if (is_new_object$argnum && array$argnum)
914     { Py_DECREF(array$argnum); }
915 }
916
917 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
918  *                    DATA_TYPE* IN_FARRAY3)
919  */
920 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
921            fragment="NumPy_Macros")
922   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
923 {
924   $1 = is_array($input) || PySequence_Check($input);
925 }
926 %typemap(in,
927          fragment="NumPy_Fragments")
928   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
929   (PyArrayObject* array=NULL, int is_new_object=0)
930 {
931   npy_intp size[3] = { -1, -1, -1 };
932   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
933                                                    &is_new_object);
934   if (!array || !require_dimensions(array, 3) ||
935       !require_size(array, size, 3) || !require_fortran(array)) SWIG_fail;
936   $1 = (DIM_TYPE) array_size(array,0);
937   $2 = (DIM_TYPE) array_size(array,1);
938   $3 = (DIM_TYPE) array_size(array,2);
939   $4 = (DATA_TYPE*) array_data(array);
940 }
941 %typemap(freearg)
942   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
943 {
944   if (is_new_object$argnum && array$argnum)
945     { Py_DECREF(array$argnum); }
946 }
947
948 /***************************/
949 /* In-Place Array Typemaps */
950 /***************************/
951
952 /* Typemap suite for (DATA_TYPE INPLACE_ARRAY1[ANY])
953  */
954 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
955            fragment="NumPy_Macros")
956   (DATA_TYPE INPLACE_ARRAY1[ANY])
957 {
958   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
959                                                  DATA_TYPECODE);
960 }
961 %typemap(in,
962          fragment="NumPy_Fragments")
963   (DATA_TYPE INPLACE_ARRAY1[ANY])
964   (PyArrayObject* array=NULL)
965 {
966   npy_intp size[1] = { $1_dim0 };
967   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
968   if (!array || !require_dimensions(array,1) || !require_size(array, size, 1) ||
969       !require_contiguous(array) || !require_native(array)) SWIG_fail;
970   $1 = ($1_ltype) array_data(array);
971 }
972
973 /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
974  */
975 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
976            fragment="NumPy_Macros")
977   (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
978 {
979   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
980                                                  DATA_TYPECODE);
981 }
982 %typemap(in,
983          fragment="NumPy_Fragments")
984   (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
985   (PyArrayObject* array=NULL, int i=1)
986 {
987   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
988   if (!array || !require_dimensions(array,1) || !require_contiguous(array)
989       || !require_native(array)) SWIG_fail;
990   $1 = (DATA_TYPE*) array_data(array);
991   $2 = 1;
992   for (i=0; i < array_numdims(array); ++i) $2 *= array_size(array,i);
993 }
994
995 /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
996  */
997 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
998            fragment="NumPy_Macros")
999   (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
1000 {
1001   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1002                                                  DATA_TYPECODE);
1003 }
1004 %typemap(in,
1005          fragment="NumPy_Fragments")
1006   (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
1007   (PyArrayObject* array=NULL, int i=0)
1008 {
1009   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1010   if (!array || !require_dimensions(array,1) || !require_contiguous(array)
1011       || !require_native(array)) SWIG_fail;
1012   $1 = 1;
1013   for (i=0; i < array_numdims(array); ++i) $1 *= array_size(array,i);
1014   $2 = (DATA_TYPE*) array_data(array);
1015 }
1016
1017 /* Typemap suite for (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
1018  */
1019 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1020            fragment="NumPy_Macros")
1021   (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
1022 {
1023   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1024                                                  DATA_TYPECODE);
1025 }
1026 %typemap(in,
1027          fragment="NumPy_Fragments")
1028   (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
1029   (PyArrayObject* array=NULL)
1030 {
1031   npy_intp size[2] = { $1_dim0, $1_dim1 };
1032   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1033   if (!array || !require_dimensions(array,2) || !require_size(array, size, 2) ||
1034       !require_contiguous(array) || !require_native(array)) SWIG_fail;
1035   $1 = ($1_ltype) array_data(array);
1036 }
1037
1038 /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1039  */
1040 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1041            fragment="NumPy_Macros")
1042   (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1043 {
1044   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1045                                                  DATA_TYPECODE);
1046 }
1047 %typemap(in,
1048          fragment="NumPy_Fragments")
1049   (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1050   (PyArrayObject* array=NULL)
1051 {
1052   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1053   if (!array || !require_dimensions(array,2) || !require_contiguous(array)
1054       || !require_native(array)) SWIG_fail;
1055   $1 = (DATA_TYPE*) array_data(array);
1056   $2 = (DIM_TYPE) array_size(array,0);
1057   $3 = (DIM_TYPE) array_size(array,1);
1058 }
1059
1060 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
1061  */
1062 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1063            fragment="NumPy_Macros")
1064   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
1065 {
1066   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1067                                                  DATA_TYPECODE);
1068 }
1069 %typemap(in,
1070          fragment="NumPy_Fragments")
1071   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
1072   (PyArrayObject* array=NULL)
1073 {
1074   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1075   if (!array || !require_dimensions(array,2) || !require_contiguous(array) ||
1076       !require_native(array)) SWIG_fail;
1077   $1 = (DIM_TYPE) array_size(array,0);
1078   $2 = (DIM_TYPE) array_size(array,1);
1079   $3 = (DATA_TYPE*) array_data(array);
1080 }
1081
1082 /* Typemap suite for (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1083  */
1084 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1085            fragment="NumPy_Macros")
1086   (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1087 {
1088   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1089                                                  DATA_TYPECODE);
1090 }
1091 %typemap(in,
1092          fragment="NumPy_Fragments")
1093   (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1094   (PyArrayObject* array=NULL)
1095 {
1096   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1097   if (!array || !require_dimensions(array,2) || !require_contiguous(array)
1098       || !require_native(array) || !require_fortran(array)) SWIG_fail;
1099   $1 = (DATA_TYPE*) array_data(array);
1100   $2 = (DIM_TYPE) array_size(array,0);
1101   $3 = (DIM_TYPE) array_size(array,1);
1102 }
1103
1104 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
1105  */
1106 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1107            fragment="NumPy_Macros")
1108   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
1109 {
1110   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1111                                                  DATA_TYPECODE);
1112 }
1113 %typemap(in,
1114          fragment="NumPy_Fragments")
1115   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
1116   (PyArrayObject* array=NULL)
1117 {
1118   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1119   if (!array || !require_dimensions(array,2) || !require_contiguous(array) ||
1120       !require_native(array) || !require_fortran(array)) SWIG_fail;
1121   $1 = (DIM_TYPE) array_size(array,0);
1122   $2 = (DIM_TYPE) array_size(array,1);
1123   $3 = (DATA_TYPE*) array_data(array);
1124 }
1125
1126 /* Typemap suite for (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
1127  */
1128 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1129            fragment="NumPy_Macros")
1130   (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
1131 {
1132   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1133                                                  DATA_TYPECODE);
1134 }
1135 %typemap(in,
1136          fragment="NumPy_Fragments")
1137   (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
1138   (PyArrayObject* array=NULL)
1139 {
1140   npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 };
1141   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1142   if (!array || !require_dimensions(array,3) || !require_size(array, size, 3) ||
1143       !require_contiguous(array) || !require_native(array)) SWIG_fail;
1144   $1 = ($1_ltype) array_data(array);
1145 }
1146
1147 /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
1148  *                    DIM_TYPE DIM3)
1149  */
1150 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1151            fragment="NumPy_Macros")
1152   (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1153 {
1154   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1155                                                  DATA_TYPECODE);
1156 }
1157 %typemap(in,
1158          fragment="NumPy_Fragments")
1159   (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1160   (PyArrayObject* array=NULL)
1161 {
1162   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1163   if (!array || !require_dimensions(array,3) || !require_contiguous(array) ||
1164       !require_native(array)) SWIG_fail;
1165   $1 = (DATA_TYPE*) array_data(array);
1166   $2 = (DIM_TYPE) array_size(array,0);
1167   $3 = (DIM_TYPE) array_size(array,1);
1168   $4 = (DIM_TYPE) array_size(array,2);
1169 }
1170
1171 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
1172  *                    DATA_TYPE* INPLACE_ARRAY3)
1173  */
1174 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1175            fragment="NumPy_Macros")
1176   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
1177 {
1178   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1179                                                  DATA_TYPECODE);
1180 }
1181 %typemap(in,
1182          fragment="NumPy_Fragments")
1183   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
1184   (PyArrayObject* array=NULL)
1185 {
1186   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1187   if (!array || !require_dimensions(array,3) || !require_contiguous(array)
1188       || !require_native(array)) SWIG_fail;
1189   $1 = (DIM_TYPE) array_size(array,0);
1190   $2 = (DIM_TYPE) array_size(array,1);
1191   $3 = (DIM_TYPE) array_size(array,2);
1192   $4 = (DATA_TYPE*) array_data(array);
1193 }
1194
1195 /* Typemap suite for (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
1196  *                    DIM_TYPE DIM3)
1197  */
1198 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1199            fragment="NumPy_Macros")
1200   (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1201 {
1202   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1203                                                  DATA_TYPECODE);
1204 }
1205 %typemap(in,
1206          fragment="NumPy_Fragments")
1207   (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1208   (PyArrayObject* array=NULL)
1209 {
1210   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1211   if (!array || !require_dimensions(array,3) || !require_contiguous(array) ||
1212       !require_native(array) || !require_fortran(array)) SWIG_fail;
1213   $1 = (DATA_TYPE*) array_data(array);
1214   $2 = (DIM_TYPE) array_size(array,0);
1215   $3 = (DIM_TYPE) array_size(array,1);
1216   $4 = (DIM_TYPE) array_size(array,2);
1217 }
1218
1219 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
1220  *                    DATA_TYPE* INPLACE_FARRAY3)
1221  */
1222 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1223            fragment="NumPy_Macros")
1224   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3)
1225 {
1226   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1227                                                  DATA_TYPECODE);
1228 }
1229 %typemap(in,
1230          fragment="NumPy_Fragments")
1231   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3)
1232   (PyArrayObject* array=NULL)
1233 {
1234   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1235   if (!array || !require_dimensions(array,3) || !require_contiguous(array)
1236       || !require_native(array) || !require_fortran(array)) SWIG_fail;
1237   $1 = (DIM_TYPE) array_size(array,0);
1238   $2 = (DIM_TYPE) array_size(array,1);
1239   $3 = (DIM_TYPE) array_size(array,2);
1240   $4 = (DATA_TYPE*) array_data(array);
1241 }
1242
1243 /*************************/
1244 /* Argout Array Typemaps */
1245 /*************************/
1246
1247 /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY1[ANY])
1248  */
1249 %typemap(in,numinputs=0,
1250          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
1251   (DATA_TYPE ARGOUT_ARRAY1[ANY])
1252   (PyObject * array = NULL)
1253 {
1254   npy_intp dims[1] = { $1_dim0 };
1255   array = PyArray_SimpleNew(1, dims, DATA_TYPECODE);
1256   if (!array) SWIG_fail;
1257   $1 = ($1_ltype) array_data(array);
1258 }
1259 %typemap(argout)
1260   (DATA_TYPE ARGOUT_ARRAY1[ANY])
1261 {
1262   $result = SWIG_Python_AppendOutput($result,array$argnum);
1263 }
1264
1265 /* Typemap suite for (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
1266  */
1267 %typemap(in,numinputs=1,
1268          fragment="NumPy_Fragments")
1269   (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
1270   (PyObject * array = NULL)
1271 {
1272   npy_intp dims[1];
1273   if (!PyInt_Check($input))
1274   {
1275     char* typestring = pytype_string($input);
1276     PyErr_Format(PyExc_TypeError,
1277                  "Int dimension expected.  '%s' given.",
1278                  typestring);
1279     SWIG_fail;
1280   }
1281   $2 = (DIM_TYPE) PyInt_AsLong($input);
1282   dims[0] = (npy_intp) $2;
1283   array = PyArray_SimpleNew(1, dims, DATA_TYPECODE);
1284   if (!array) SWIG_fail;
1285   $1 = (DATA_TYPE*) array_data(array);
1286 }
1287 %typemap(argout)
1288   (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
1289 {
1290   $result = SWIG_Python_AppendOutput($result,array$argnum);
1291 }
1292
1293 /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
1294  */
1295 %typemap(in,numinputs=1,
1296          fragment="NumPy_Fragments")
1297   (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
1298   (PyObject * array = NULL)
1299 {
1300   npy_intp dims[1];
1301   if (!PyInt_Check($input))
1302   {
1303     char* typestring = pytype_string($input);
1304     PyErr_Format(PyExc_TypeError,
1305                  "Int dimension expected.  '%s' given.",
1306                  typestring);
1307     SWIG_fail;
1308   }
1309   $1 = (DIM_TYPE) PyInt_AsLong($input);
1310   dims[0] = (npy_intp) $1;
1311   array = PyArray_SimpleNew(1, dims, DATA_TYPECODE);
1312   if (!array) SWIG_fail;
1313   $2 = (DATA_TYPE*) array_data(array);
1314 }
1315 %typemap(argout)
1316   (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
1317 {
1318   $result = SWIG_Python_AppendOutput($result,array$argnum);
1319 }
1320
1321 /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
1322  */
1323 %typemap(in,numinputs=0,
1324          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
1325   (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
1326   (PyObject * array = NULL)
1327 {
1328   npy_intp dims[2] = { $1_dim0, $1_dim1 };
1329   array = PyArray_SimpleNew(2, dims, DATA_TYPECODE);
1330   if (!array) SWIG_fail;
1331   $1 = ($1_ltype) array_data(array);
1332 }
1333 %typemap(argout)
1334   (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
1335 {
1336   $result = SWIG_Python_AppendOutput($result,array$argnum);
1337 }
1338
1339 /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
1340  */
1341 %typemap(in,numinputs=0,
1342          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
1343   (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
1344   (PyObject * array = NULL)
1345 {
1346   npy_intp dims[3] = { $1_dim0, $1_dim1, $1_dim2 };
1347   array = PyArray_SimpleNew(3, dims, DATA_TYPECODE);
1348   if (!array) SWIG_fail;
1349   $1 = ($1_ltype) array_data(array);
1350 }
1351 %typemap(argout)
1352   (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
1353 {
1354   $result = SWIG_Python_AppendOutput($result,array$argnum);
1355 }
1356
1357 /*****************************/
1358 /* Argoutview Array Typemaps */
1359 /*****************************/
1360
1361 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1)
1362  */
1363 %typemap(in,numinputs=0)
1364   (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1    )
1365   (DATA_TYPE*  data_temp        , DIM_TYPE  dim_temp)
1366 {
1367   $1 = &data_temp;
1368   $2 = &dim_temp;
1369 }
1370 %typemap(argout,
1371          fragment="NumPy_Backward_Compatibility")
1372   (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1)
1373 {
1374   npy_intp dims[1] = { *$2 };
1375   PyObject * array = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$1));
1376   if (!array) SWIG_fail;
1377   $result = SWIG_Python_AppendOutput($result,array);
1378 }
1379
1380 /* Typemap suite for (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
1381  */
1382 %typemap(in,numinputs=0)
1383   (DIM_TYPE* DIM1    , DATA_TYPE** ARGOUTVIEW_ARRAY1)
1384   (DIM_TYPE  dim_temp, DATA_TYPE*  data_temp        )
1385 {
1386   $1 = &dim_temp;
1387   $2 = &data_temp;
1388 }
1389 %typemap(argout,
1390          fragment="NumPy_Backward_Compatibility")
1391   (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
1392 {
1393   npy_intp dims[1] = { *$1 };
1394   PyObject * array = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$2));
1395   if (!array) SWIG_fail;
1396   $result = SWIG_Python_AppendOutput($result,array);
1397 }
1398
1399 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
1400  */
1401 %typemap(in,numinputs=0)
1402   (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
1403   (DATA_TYPE*  data_temp        , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
1404 {
1405   $1 = &data_temp;
1406   $2 = &dim1_temp;
1407   $3 = &dim2_temp;
1408 }
1409 %typemap(argout,
1410          fragment="NumPy_Backward_Compatibility")
1411   (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
1412 {
1413   npy_intp dims[2] = { *$2, *$3 };
1414   PyObject * array = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
1415   if (!array) SWIG_fail;
1416   $result = SWIG_Python_AppendOutput($result,array);
1417 }
1418
1419 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
1420  */
1421 %typemap(in,numinputs=0)
1422   (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEW_ARRAY2)
1423   (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp        )
1424 {
1425   $1 = &dim1_temp;
1426   $2 = &dim2_temp;
1427   $3 = &data_temp;
1428 }
1429 %typemap(argout,
1430          fragment="NumPy_Backward_Compatibility")
1431   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
1432 {
1433   npy_intp dims[2] = { *$1, *$2 };
1434   PyObject * array = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
1435   if (!array) SWIG_fail;
1436   $result = SWIG_Python_AppendOutput($result,array);
1437 }
1438
1439 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
1440  */
1441 %typemap(in,numinputs=0)
1442   (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
1443   (DATA_TYPE*  data_temp        , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
1444 {
1445   $1 = &data_temp;
1446   $2 = &dim1_temp;
1447   $3 = &dim2_temp;
1448 }
1449 %typemap(argout,
1450          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
1451   (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
1452 {
1453   npy_intp dims[2] = { *$2, *$3 };
1454   PyObject * obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
1455   PyArrayObject * array = (PyArrayObject*) obj;
1456   if (!array || !require_fortran(array)) SWIG_fail;
1457   $result = SWIG_Python_AppendOutput($result,obj);
1458 }
1459
1460 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2)
1461  */
1462 %typemap(in,numinputs=0)
1463   (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEW_FARRAY2)
1464   (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp        )
1465 {
1466   $1 = &dim1_temp;
1467   $2 = &dim2_temp;
1468   $3 = &data_temp;
1469 }
1470 %typemap(argout,
1471          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
1472   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2)
1473 {
1474   npy_intp dims[2] = { *$1, *$2 };
1475   PyObject * obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
1476   PyArrayObject * array = (PyArrayObject*) obj;
1477   if (!array || !require_fortran(array)) SWIG_fail;
1478   $result = SWIG_Python_AppendOutput($result,obj);
1479 }
1480
1481 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
1482                       DIM_TYPE* DIM3)
1483  */
1484 %typemap(in,numinputs=0)
1485   (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
1486   (DATA_TYPE* data_temp, DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
1487 {
1488   $1 = &data_temp;
1489   $2 = &dim1_temp;
1490   $3 = &dim2_temp;
1491   $4 = &dim3_temp;
1492 }
1493 %typemap(argout,
1494          fragment="NumPy_Backward_Compatibility")
1495   (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
1496 {
1497   npy_intp dims[3] = { *$2, *$3, *$4 };
1498   PyObject * array = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
1499   if (!array) SWIG_fail;
1500   $result = SWIG_Python_AppendOutput($result,array);
1501 }
1502
1503 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3,
1504                       DATA_TYPE** ARGOUTVIEW_ARRAY3)
1505  */
1506 %typemap(in,numinputs=0)
1507   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
1508   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp)
1509 {
1510   $1 = &dim1_temp;
1511   $2 = &dim2_temp;
1512   $3 = &dim3_temp;
1513   $4 = &data_temp;
1514 }
1515 %typemap(argout,
1516          fragment="NumPy_Backward_Compatibility")
1517   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
1518 {
1519   npy_intp dims[3] = { *$1, *$2, *$3 };
1520   PyObject * array = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$3));
1521   if (!array) SWIG_fail;
1522   $result = SWIG_Python_AppendOutput($result,array);
1523 }
1524
1525 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
1526                       DIM_TYPE* DIM3)
1527  */
1528 %typemap(in,numinputs=0)
1529   (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
1530   (DATA_TYPE* data_temp, DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
1531 {
1532   $1 = &data_temp;
1533   $2 = &dim1_temp;
1534   $3 = &dim2_temp;
1535   $4 = &dim3_temp;
1536 }
1537 %typemap(argout,
1538          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
1539   (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
1540 {
1541   npy_intp dims[3] = { *$2, *$3, *$4 };
1542   PyObject * obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
1543   PyArrayObject * array = (PyArrayObject*) obj;
1544   if (!array || require_fortran(array)) SWIG_fail;
1545   $result = SWIG_Python_AppendOutput($result,obj);
1546 }
1547
1548 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3,
1549                       DATA_TYPE** ARGOUTVIEW_FARRAY3)
1550  */
1551 %typemap(in,numinputs=0)
1552   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3)
1553   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp)
1554 {
1555   $1 = &dim1_temp;
1556   $2 = &dim2_temp;
1557   $3 = &dim3_temp;
1558   $4 = &data_temp;
1559 }
1560 %typemap(argout,
1561          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
1562   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3)
1563 {
1564   npy_intp dims[3] = { *$1, *$2, *$3 };
1565   PyObject * obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$3));
1566   PyArrayObject * array = (PyArrayObject*) obj;
1567   if (!array || require_fortran(array)) SWIG_fail;
1568   $result = SWIG_Python_AppendOutput($result,obj);
1569 }
1570
1571 %enddef    /* %numpy_typemaps() macro */
1572 /* *************************************************************** */
1573
1574 /* Concrete instances of the %numpy_typemaps() macro: Each invocation
1575  * below applies all of the typemaps above to the specified data type.
1576  */
1577 %numpy_typemaps(signed char       , NPY_BYTE     , int)
1578 %numpy_typemaps(unsigned char     , NPY_UBYTE    , int)
1579 %numpy_typemaps(short             , NPY_SHORT    , int)
1580 %numpy_typemaps(unsigned short    , NPY_USHORT   , int)
1581 %numpy_typemaps(int               , NPY_INT      , int)
1582 %numpy_typemaps(unsigned int      , NPY_UINT     , int)
1583 %numpy_typemaps(long              , NPY_LONG     , int)
1584 %numpy_typemaps(unsigned long     , NPY_ULONG    , int)
1585 %numpy_typemaps(long long         , NPY_LONGLONG , int)
1586 %numpy_typemaps(unsigned long long, NPY_ULONGLONG, int)
1587 %numpy_typemaps(float             , NPY_FLOAT    , int)
1588 %numpy_typemaps(double            , NPY_DOUBLE   , int)
1589
1590 /* ***************************************************************
1591  * The follow macro expansion does not work, because C++ bool is 4
1592  * bytes and NPY_BOOL is 1 byte
1593  *
1594  *    %numpy_typemaps(bool, NPY_BOOL, int)
1595  */
1596
1597 /* ***************************************************************
1598  * On my Mac, I get the following warning for this macro expansion:
1599  * 'swig/python detected a memory leak of type 'long double *', no destructor found.'
1600  *
1601  *    %numpy_typemaps(long double, NPY_LONGDOUBLE, int)
1602  */
1603
1604 /* ***************************************************************
1605  * Swig complains about a syntax error for the following macro
1606  * expansions:
1607  *
1608  *    %numpy_typemaps(complex float,  NPY_CFLOAT , int)
1609  *
1610  *    %numpy_typemaps(complex double, NPY_CDOUBLE, int)
1611  *
1612  *    %numpy_typemaps(complex long double, NPY_CLONGDOUBLE, int)
1613  */
1614
1615 #endif /* SWIGPYTHON */