chiark / gitweb /
05ae90b2bed289148ba316425735efa46b6616a5
[nlopt.git] / swig / numpy.i
1 /* -*- C -*-  (not really, but good for syntax highlighting) */
2 #ifdef SWIGPYTHON
3
4 %{
5 #ifndef SWIG_FILE_WITH_INIT
6 #define NO_IMPORT_ARRAY
7 #endif
8 #include "stdio.h"
9 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
10 #include <numpy/arrayobject.h>
11 %}
12
13 /**********************************************************************/
14
15 %fragment("NumPy_Backward_Compatibility", "header")
16 {
17 %#if NPY_API_VERSION < 0x00000007
18 %#define NPY_ARRAY_DEFAULT NPY_DEFAULT
19 %#define NPY_ARRAY_FARRAY  NPY_FARRAY
20 %#define NPY_FORTRANORDER  NPY_FORTRAN
21 %#endif
22 }
23
24 /**********************************************************************/
25
26 /* The following code originally appeared in
27  * enthought/kiva/agg/src/numeric.i written by Eric Jones.  It was
28  * translated from C++ to C by John Hunter.  Bill Spotz has modified
29  * it to fix some minor bugs, upgrade from Numeric to numpy (all
30  * versions), add some comments and functionality, and convert from
31  * direct code insertion to SWIG fragments.
32  */
33
34 %fragment("NumPy_Macros", "header")
35 {
36 /* Macros to extract array attributes.
37  */
38 %#if NPY_API_VERSION < 0x00000007
39 %#define is_array(a)            ((a) && PyArray_Check((PyArrayObject*)a))
40 %#define array_type(a)          (int)(PyArray_TYPE((PyArrayObject*)a))
41 %#define array_numdims(a)       (((PyArrayObject*)a)->nd)
42 %#define array_dimensions(a)    (((PyArrayObject*)a)->dimensions)
43 %#define array_size(a,i)        (((PyArrayObject*)a)->dimensions[i])
44 %#define array_strides(a)       (((PyArrayObject*)a)->strides)
45 %#define array_stride(a,i)      (((PyArrayObject*)a)->strides[i])
46 %#define array_data(a)          (((PyArrayObject*)a)->data)
47 %#define array_descr(a)         (((PyArrayObject*)a)->descr)
48 %#define array_flags(a)         (((PyArrayObject*)a)->flags)
49 %#define array_enableflags(a,f) (((PyArrayObject*)a)->flags) = f
50 %#else
51 %#define is_array(a)            ((a) && PyArray_Check(a))
52 %#define array_type(a)          PyArray_TYPE((PyArrayObject*)a)
53 %#define array_numdims(a)       PyArray_NDIM((PyArrayObject*)a)
54 %#define array_dimensions(a)    PyArray_DIMS((PyArrayObject*)a)
55 %#define array_strides(a)       PyArray_STRIDES((PyArrayObject*)a)
56 %#define array_stride(a,i)      PyArray_STRIDE((PyArrayObject*)a,i)
57 %#define array_size(a,i)        PyArray_DIM((PyArrayObject*)a,i)
58 %#define array_data(a)          PyArray_DATA((PyArrayObject*)a)
59 %#define array_descr(a)         PyArray_DESCR((PyArrayObject*)a)
60 %#define array_flags(a)         PyArray_FLAGS((PyArrayObject*)a)
61 %#define array_enableflags(a,f) PyArray_ENABLEFLAGS((PyArrayObject*)a,f)
62 %#endif
63 %#define array_is_contiguous(a) (PyArray_ISCONTIGUOUS((PyArrayObject*)a))
64 %#define array_is_native(a)     (PyArray_ISNOTSWAPPED((PyArrayObject*)a))
65 %#define array_is_fortran(a)    (PyArray_ISFORTRAN((PyArrayObject*)a))
66 }
67
68 /**********************************************************************/
69
70 %fragment("NumPy_Utilities",
71           "header")
72 {
73   /* Given a PyObject, return a string describing its type.
74    */
75   const char* pytype_string(PyObject* py_obj)
76   {
77     if (py_obj == NULL          ) return "C NULL value";
78     if (py_obj == Py_None       ) return "Python None" ;
79     if (PyCallable_Check(py_obj)) return "callable"    ;
80     if (PyString_Check(  py_obj)) return "string"      ;
81     if (PyInt_Check(     py_obj)) return "int"         ;
82     if (PyFloat_Check(   py_obj)) return "float"       ;
83     if (PyDict_Check(    py_obj)) return "dict"        ;
84     if (PyList_Check(    py_obj)) return "list"        ;
85     if (PyTuple_Check(   py_obj)) return "tuple"       ;
86 %#if PY_MAJOR_VERSION < 3
87     if (PyFile_Check(    py_obj)) return "file"        ;
88     if (PyModule_Check(  py_obj)) return "module"      ;
89     if (PyInstance_Check(py_obj)) return "instance"    ;
90 %#endif
91
92     return "unknown type";
93   }
94
95   /* Given a NumPy typecode, return a string describing the type.
96    */
97   const char* typecode_string(int typecode)
98   {
99     static const char* type_names[25] = {"bool",
100                                          "byte",
101                                          "unsigned byte",
102                                          "short",
103                                          "unsigned short",
104                                          "int",
105                                          "unsigned int",
106                                          "long",
107                                          "unsigned long",
108                                          "long long",
109                                          "unsigned long long",
110                                          "float",
111                                          "double",
112                                          "long double",
113                                          "complex float",
114                                          "complex double",
115                                          "complex long double",
116                                          "object",
117                                          "string",
118                                          "unicode",
119                                          "void",
120                                          "ntypes",
121                                          "notype",
122                                          "char",
123                                          "unknown"};
124     return typecode < 24 ? type_names[typecode] : type_names[24];
125   }
126
127   /* Make sure input has correct numpy type.  This now just calls
128      PyArray_EquivTypenums().
129    */
130   int type_match(int actual_type,
131                  int desired_type)
132   {
133     return PyArray_EquivTypenums(actual_type, desired_type);
134   }
135
136 %#ifdef SWIGPY_USE_CAPSULE
137   void free_cap(PyObject * cap)
138   {
139     void* array = (void*) PyCapsule_GetPointer(cap,SWIGPY_CAPSULE_NAME);
140     if (array != NULL) free(array);
141   }
142 %#endif
143
144
145 }
146
147 /**********************************************************************/
148
149 %fragment("NumPy_Object_to_Array",
150           "header",
151           fragment="NumPy_Backward_Compatibility",
152           fragment="NumPy_Macros",
153           fragment="NumPy_Utilities")
154 {
155   /* Given a PyObject pointer, cast it to a PyArrayObject pointer if
156    * legal.  If not, set the python error string appropriately and
157    * return NULL.
158    */
159   PyArrayObject* obj_to_array_no_conversion(PyObject* input,
160                                             int        typecode)
161   {
162     PyArrayObject* ary = NULL;
163     if (is_array(input) && (typecode == NPY_NOTYPE ||
164                             PyArray_EquivTypenums(array_type(input), typecode)))
165     {
166       ary = (PyArrayObject*) input;
167     }
168     else if is_array(input)
169     {
170       const char* desired_type = typecode_string(typecode);
171       const char* actual_type  = typecode_string(array_type(input));
172       PyErr_Format(PyExc_TypeError,
173                    "Array of type '%s' required.  Array of type '%s' given",
174                    desired_type, actual_type);
175       ary = NULL;
176     }
177     else
178     {
179       const char* desired_type = typecode_string(typecode);
180       const char* actual_type  = pytype_string(input);
181       PyErr_Format(PyExc_TypeError,
182                    "Array of type '%s' required.  A '%s' was given",
183                    desired_type,
184                    actual_type);
185       ary = NULL;
186     }
187     return ary;
188   }
189
190   /* Convert the given PyObject to a NumPy array with the given
191    * typecode.  On success, return a valid PyArrayObject* with the
192    * correct type.  On failure, the python error string will be set and
193    * the routine returns NULL.
194    */
195   PyArrayObject* obj_to_array_allow_conversion(PyObject* input,
196                                                int       typecode,
197                                                int*      is_new_object)
198   {
199     PyArrayObject* ary = NULL;
200     PyObject*      py_obj;
201     if (is_array(input) && (typecode == NPY_NOTYPE ||
202                             PyArray_EquivTypenums(array_type(input),typecode)))
203     {
204       ary = (PyArrayObject*) input;
205       *is_new_object = 0;
206     }
207     else
208     {
209       py_obj = PyArray_FROMANY(input, typecode, 0, 0, NPY_ARRAY_DEFAULT);
210       /* If NULL, PyArray_FromObject will have set python error value.*/
211       ary = (PyArrayObject*) py_obj;
212       *is_new_object = 1;
213     }
214     return ary;
215   }
216
217   /* Given a PyArrayObject, check to see if it is contiguous.  If so,
218    * return the input pointer and flag it as not a new object.  If it is
219    * not contiguous, create a new PyArrayObject using the original data,
220    * flag it as a new object and return the pointer.
221    */
222   PyArrayObject* make_contiguous(PyArrayObject* ary,
223                                  int*           is_new_object,
224                                  int            min_dims,
225                                  int            max_dims)
226   {
227     PyArrayObject* result;
228     if (array_is_contiguous(ary))
229     {
230       result = ary;
231       *is_new_object = 0;
232     }
233     else
234     {
235       result = (PyArrayObject*) PyArray_ContiguousFromObject((PyObject*)ary,
236                                                               array_type(ary),
237                                                               min_dims,
238                                                               max_dims);
239       *is_new_object = 1;
240     }
241     return result;
242   }
243
244   /* Given a PyArrayObject, check to see if it is Fortran-contiguous.
245    * If so, return the input pointer, but do not flag it as not a new
246    * object.  If it is not Fortran-contiguous, create a new
247    * PyArrayObject using the original data, flag it as a new object
248    * and return the pointer.
249    */
250   PyArrayObject* make_fortran(PyArrayObject* ary,
251                               int*           is_new_object)
252   {
253     PyArrayObject* result;
254     if (array_is_fortran(ary))
255     {
256       result = ary;
257       *is_new_object = 0;
258     }
259     else
260     {
261       Py_INCREF(array_descr(ary));
262       result = (PyArrayObject*) PyArray_FromArray(ary,
263                                                   array_descr(ary),
264                                                   NPY_FORTRANORDER);
265       *is_new_object = 1;
266     }
267     return result;
268   }
269
270   /* Convert a given PyObject to a contiguous PyArrayObject of the
271    * specified type.  If the input object is not a contiguous
272    * PyArrayObject, a new one will be created and the new object flag
273    * will be set.
274    */
275   PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject* input,
276                                                           int       typecode,
277                                                           int*      is_new_object)
278   {
279     int is_new1 = 0;
280     int is_new2 = 0;
281     PyArrayObject* ary2;
282     PyArrayObject* ary1 = obj_to_array_allow_conversion(input,
283                                                         typecode,
284                                                         &is_new1);
285     if (ary1)
286     {
287       ary2 = make_contiguous(ary1, &is_new2, 0, 0);
288       if ( is_new1 && is_new2)
289       {
290         Py_DECREF(ary1);
291       }
292       ary1 = ary2;
293     }
294     *is_new_object = is_new1 || is_new2;
295     return ary1;
296   }
297
298   /* Convert a given PyObject to a Fortran-ordered PyArrayObject of the
299    * specified type.  If the input object is not a Fortran-ordered
300    * PyArrayObject, a new one will be created and the new object flag
301    * will be set.
302    */
303   PyArrayObject* obj_to_array_fortran_allow_conversion(PyObject* input,
304                                                        int       typecode,
305                                                        int*      is_new_object)
306   {
307     int is_new1 = 0;
308     int is_new2 = 0;
309     PyArrayObject* ary2;
310     PyArrayObject* ary1 = obj_to_array_allow_conversion(input,
311                                                         typecode,
312                                                         &is_new1);
313     if (ary1)
314     {
315       ary2 = make_fortran(ary1, &is_new2);
316       if (is_new1 && is_new2)
317       {
318         Py_DECREF(ary1);
319       }
320       ary1 = ary2;
321     }
322     *is_new_object = is_new1 || is_new2;
323     return ary1;
324   }
325 } /* end fragment */
326
327 /**********************************************************************/
328
329 %fragment("NumPy_Array_Requirements",
330           "header",
331           fragment="NumPy_Backward_Compatibility",
332           fragment="NumPy_Macros")
333 {
334   /* Test whether a python object is contiguous.  If array is
335    * contiguous, return 1.  Otherwise, set the python error string and
336    * return 0.
337    */
338   int require_contiguous(PyArrayObject* ary)
339   {
340     int contiguous = 1;
341     if (!array_is_contiguous(ary))
342     {
343       PyErr_SetString(PyExc_TypeError,
344                       "Array must be contiguous.  A non-contiguous array was given");
345       contiguous = 0;
346     }
347     return contiguous;
348   }
349
350   /* Require that a numpy array is not byte-swapped.  If the array is
351    * not byte-swapped, return 1.  Otherwise, set the python error string
352    * and return 0.
353    */
354   int require_native(PyArrayObject* ary)
355   {
356     int native = 1;
357     if (!array_is_native(ary))
358     {
359       PyErr_SetString(PyExc_TypeError,
360                       "Array must have native byteorder.  "
361                       "A byte-swapped array was given");
362       native = 0;
363     }
364     return native;
365   }
366
367   /* Require the given PyArrayObject to have a specified number of
368    * dimensions.  If the array has the specified number of dimensions,
369    * return 1.  Otherwise, set the python error string and return 0.
370    */
371   int require_dimensions(PyArrayObject* ary,
372                          int            exact_dimensions)
373   {
374     int success = 1;
375     if (array_numdims(ary) != exact_dimensions)
376     {
377       PyErr_Format(PyExc_TypeError,
378                    "Array must have %d dimensions.  Given array has %d dimensions",
379                    exact_dimensions,
380                    array_numdims(ary));
381       success = 0;
382     }
383     return success;
384   }
385
386   /* Require the given PyArrayObject to have one of a list of specified
387    * number of dimensions.  If the array has one of the specified number
388    * of dimensions, return 1.  Otherwise, set the python error string
389    * and return 0.
390    */
391   int require_dimensions_n(PyArrayObject* ary,
392                            int*           exact_dimensions,
393                            int            n)
394   {
395     int success = 0;
396     int i;
397     char dims_str[255] = "";
398     char s[255];
399     for (i = 0; i < n && !success; i++)
400     {
401       if (array_numdims(ary) == exact_dimensions[i])
402       {
403         success = 1;
404       }
405     }
406     if (!success)
407     {
408       for (i = 0; i < n-1; i++)
409       {
410         sprintf(s, "%d, ", exact_dimensions[i]);
411         strcat(dims_str,s);
412       }
413       sprintf(s, " or %d", exact_dimensions[n-1]);
414       strcat(dims_str,s);
415       PyErr_Format(PyExc_TypeError,
416                    "Array must have %s dimensions.  Given array has %d dimensions",
417                    dims_str,
418                    array_numdims(ary));
419     }
420     return success;
421   }
422
423   /* Require the given PyArrayObject to have a specified shape.  If the
424    * array has the specified shape, return 1.  Otherwise, set the python
425    * error string and return 0.
426    */
427   int require_size(PyArrayObject* ary,
428                    npy_intp*      size,
429                    int            n)
430   {
431     int i;
432     int success = 1;
433     int len;
434     char desired_dims[255] = "[";
435     char s[255];
436     char actual_dims[255] = "[";
437     for(i=0; i < n;i++)
438     {
439       if (size[i] != -1 &&  size[i] != array_size(ary,i))
440       {
441         success = 0;
442       }
443     }
444     if (!success)
445     {
446       for (i = 0; i < n; i++)
447       {
448         if (size[i] == -1)
449         {
450           sprintf(s, "*,");
451         }
452         else
453         {
454           sprintf(s, "%ld,", (long int)size[i]);
455         }
456         strcat(desired_dims,s);
457       }
458       len = strlen(desired_dims);
459       desired_dims[len-1] = ']';
460       for (i = 0; i < n; i++)
461       {
462         sprintf(s, "%ld,", (long int)array_size(ary,i));
463         strcat(actual_dims,s);
464       }
465       len = strlen(actual_dims);
466       actual_dims[len-1] = ']';
467       PyErr_Format(PyExc_TypeError,
468                    "Array must have shape of %s.  Given array has shape of %s",
469                    desired_dims,
470                    actual_dims);
471     }
472     return success;
473   }
474
475   /* Require the given PyArrayObject to to be Fortran ordered.  If the
476    * the PyArrayObject is already Fortran ordered, do nothing.  Else,
477    * set the Fortran ordering flag and recompute the strides.
478    */
479   int require_fortran(PyArrayObject* ary)
480   {
481     int success = 1;
482     int nd = array_numdims(ary);
483     int i;
484     npy_intp * strides = array_strides(ary);
485     if (array_is_fortran(ary)) return success;
486     /* Set the Fortran ordered flag */
487     array_enableflags(ary,NPY_ARRAY_FARRAY);
488     /* Recompute the strides */
489     strides[0] = strides[nd-1];
490     for (i=1; i < nd; ++i)
491       strides[i] = strides[i-1] * array_size(ary,i-1);
492     return success;
493   }
494 }
495
496 /* Combine all NumPy fragments into one for convenience */
497 %fragment("NumPy_Fragments",
498           "header",
499           fragment="NumPy_Backward_Compatibility",
500           fragment="NumPy_Macros",
501           fragment="NumPy_Utilities",
502           fragment="NumPy_Object_to_Array",
503           fragment="NumPy_Array_Requirements")
504 {
505 }
506
507 /* End John Hunter translation (with modifications by Bill Spotz)
508  */
509
510 /* %numpy_typemaps() macro
511  *
512  * This macro defines a family of 74 typemaps that allow C arguments
513  * of the form
514  *
515  *    1. (DATA_TYPE IN_ARRAY1[ANY])
516  *    2. (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
517  *    3. (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
518  *
519  *    4. (DATA_TYPE IN_ARRAY2[ANY][ANY])
520  *    5. (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
521  *    6. (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
522  *    7. (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
523  *    8. (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
524  *
525  *    9. (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
526  *   10. (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
527  *   11. (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
528  *   12. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
529  *   13. (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
530  *   14. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
531  *
532  *   15. (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
533  *   16. (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
534  *   17. (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
535  *   18. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, , DIM_TYPE DIM4, DATA_TYPE* IN_ARRAY4)
536  *   19. (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
537  *   20. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_FARRAY4)
538  *
539  *   21. (DATA_TYPE INPLACE_ARRAY1[ANY])
540  *   22. (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
541  *   23. (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
542  *
543  *   24. (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
544  *   25. (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
545  *   26. (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
546  *   27. (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
547  *   28. (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
548  *
549  *   29. (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
550  *   30. (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
551  *   31. (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
552  *   32. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
553  *   33. (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
554  *   34. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3)
555  *
556  *   35. (DATA_TYPE INPLACE_ARRAY4[ANY][ANY][ANY][ANY])
557  *   36. (DATA_TYPE* INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
558  *   37. (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
559  *   38. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_ARRAY4)
560  *   39. (DATA_TYPE* INPLACE_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
561  *   40. (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_FARRAY4)
562  *
563  *   41. (DATA_TYPE ARGOUT_ARRAY1[ANY])
564  *   42. (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
565  *   43. (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
566  *
567  *   44. (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
568  *
569  *   45. (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
570  *
571  *   46. (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY])
572  *
573  *   47. (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1)
574  *   48. (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
575  *
576  *   49. (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
577  *   50. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
578  *   51. (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
579  *   52. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2)
580  *
581  *   53. (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
582  *   54. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
583  *   55. (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
584  *   56. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3)
585  *
586  *   57. (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
587  *   58. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_ARRAY4)
588  *   59. (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
589  *   60. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_FARRAY4)
590  *
591  *   61. (DATA_TYPE** ARGOUTVIEWM_ARRAY1, DIM_TYPE* DIM1)
592  *   62. (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEWM_ARRAY1)
593  *
594  *   63. (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
595  *   64. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_ARRAY2)
596  *   65. (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
597  *   66. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_FARRAY2)
598  *
599  *   67. (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
600  *   68. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_ARRAY3)
601  *   69. (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
602  *   70. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_FARRAY3)
603  *
604  *   71. (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
605  *   72. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_ARRAY4)
606  *   73. (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
607  *   74. (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_FARRAY4)
608  *
609  * where "DATA_TYPE" is any type supported by the NumPy module, and
610  * "DIM_TYPE" is any int-like type suitable for specifying dimensions.
611  * The difference between "ARRAY" typemaps and "FARRAY" typemaps is
612  * that the "FARRAY" typemaps expect Fortran ordering of
613  * multidimensional arrays.  In python, the dimensions will not need
614  * to be specified (except for the "DATA_TYPE* ARGOUT_ARRAY1"
615  * typemaps).  The IN_ARRAYs can be a numpy array or any sequence that
616  * can be converted to a numpy array of the specified type.  The
617  * INPLACE_ARRAYs must be numpy arrays of the appropriate type.  The
618  * ARGOUT_ARRAYs will be returned as new numpy arrays of the
619  * appropriate type.
620  *
621  * These typemaps can be applied to existing functions using the
622  * %apply directive.  For example:
623  *
624  *     %apply (double* IN_ARRAY1, int DIM1) {(double* series, int length)};
625  *     double prod(double* series, int length);
626  *
627  *     %apply (int DIM1, int DIM2, double* INPLACE_ARRAY2)
628  *           {(int rows, int cols, double* matrix        )};
629  *     void floor(int rows, int cols, double* matrix, double f);
630  *
631  *     %apply (double IN_ARRAY3[ANY][ANY][ANY])
632  *           {(double tensor[2][2][2]         )};
633  *     %apply (double ARGOUT_ARRAY3[ANY][ANY][ANY])
634  *           {(double low[2][2][2]                )};
635  *     %apply (double ARGOUT_ARRAY3[ANY][ANY][ANY])
636  *           {(double upp[2][2][2]                )};
637  *     void luSplit(double tensor[2][2][2],
638  *                  double low[2][2][2],
639  *                  double upp[2][2][2]    );
640  *
641  * or directly with
642  *
643  *     double prod(double* IN_ARRAY1, int DIM1);
644  *
645  *     void floor(int DIM1, int DIM2, double* INPLACE_ARRAY2, double f);
646  *
647  *     void luSplit(double IN_ARRAY3[ANY][ANY][ANY],
648  *                  double ARGOUT_ARRAY3[ANY][ANY][ANY],
649  *                  double ARGOUT_ARRAY3[ANY][ANY][ANY]);
650  */
651
652 %define %numpy_typemaps(DATA_TYPE, DATA_TYPECODE, DIM_TYPE)
653
654 /************************/
655 /* Input Array Typemaps */
656 /************************/
657
658 /* Typemap suite for (DATA_TYPE IN_ARRAY1[ANY])
659  */
660 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
661            fragment="NumPy_Macros")
662   (DATA_TYPE IN_ARRAY1[ANY])
663 {
664   $1 = is_array($input) || PySequence_Check($input);
665 }
666 %typemap(in,
667          fragment="NumPy_Fragments")
668   (DATA_TYPE IN_ARRAY1[ANY])
669   (PyArrayObject* array=NULL, int is_new_object=0)
670 {
671   npy_intp size[1] = { $1_dim0 };
672   array = obj_to_array_contiguous_allow_conversion($input,
673                                                    DATA_TYPECODE,
674                                                    &is_new_object);
675   if (!array || !require_dimensions(array, 1) ||
676       !require_size(array, size, 1)) SWIG_fail;
677   $1 = ($1_ltype) array_data(array);
678 }
679 %typemap(freearg)
680   (DATA_TYPE IN_ARRAY1[ANY])
681 {
682   if (is_new_object$argnum && array$argnum)
683     { Py_DECREF(array$argnum); }
684 }
685
686 /* Typemap suite for (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
687  */
688 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
689            fragment="NumPy_Macros")
690   (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
691 {
692   $1 = is_array($input) || PySequence_Check($input);
693 }
694 %typemap(in,
695          fragment="NumPy_Fragments")
696   (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
697   (PyArrayObject* array=NULL, int is_new_object=0)
698 {
699   npy_intp size[1] = { -1 };
700   array = obj_to_array_contiguous_allow_conversion($input,
701                                                    DATA_TYPECODE,
702                                                    &is_new_object);
703   if (!array || !require_dimensions(array, 1) ||
704       !require_size(array, size, 1)) SWIG_fail;
705   $1 = (DATA_TYPE*) array_data(array);
706   $2 = (DIM_TYPE) array_size(array,0);
707 }
708 %typemap(freearg)
709   (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1)
710 {
711   if (is_new_object$argnum && array$argnum)
712     { Py_DECREF(array$argnum); }
713 }
714
715 /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
716  */
717 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
718            fragment="NumPy_Macros")
719   (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
720 {
721   $1 = is_array($input) || PySequence_Check($input);
722 }
723 %typemap(in,
724          fragment="NumPy_Fragments")
725   (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
726   (PyArrayObject* array=NULL, int is_new_object=0)
727 {
728   npy_intp size[1] = {-1};
729   array = obj_to_array_contiguous_allow_conversion($input,
730                                                    DATA_TYPECODE,
731                                                    &is_new_object);
732   if (!array || !require_dimensions(array, 1) ||
733       !require_size(array, size, 1)) SWIG_fail;
734   $1 = (DIM_TYPE) array_size(array,0);
735   $2 = (DATA_TYPE*) array_data(array);
736 }
737 %typemap(freearg)
738   (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1)
739 {
740   if (is_new_object$argnum && array$argnum)
741     { Py_DECREF(array$argnum); }
742 }
743
744 /* Typemap suite for (DATA_TYPE IN_ARRAY2[ANY][ANY])
745  */
746 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
747            fragment="NumPy_Macros")
748   (DATA_TYPE IN_ARRAY2[ANY][ANY])
749 {
750   $1 = is_array($input) || PySequence_Check($input);
751 }
752 %typemap(in,
753          fragment="NumPy_Fragments")
754   (DATA_TYPE IN_ARRAY2[ANY][ANY])
755   (PyArrayObject* array=NULL, int is_new_object=0)
756 {
757   npy_intp size[2] = { $1_dim0, $1_dim1 };
758   array = obj_to_array_contiguous_allow_conversion($input,
759                                                    DATA_TYPECODE,
760                                                    &is_new_object);
761   if (!array || !require_dimensions(array, 2) ||
762       !require_size(array, size, 2)) SWIG_fail;
763   $1 = ($1_ltype) array_data(array);
764 }
765 %typemap(freearg)
766   (DATA_TYPE IN_ARRAY2[ANY][ANY])
767 {
768   if (is_new_object$argnum && array$argnum)
769     { Py_DECREF(array$argnum); }
770 }
771
772 /* Typemap suite for (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
773  */
774 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
775            fragment="NumPy_Macros")
776   (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
777 {
778   $1 = is_array($input) || PySequence_Check($input);
779 }
780 %typemap(in,
781          fragment="NumPy_Fragments")
782   (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
783   (PyArrayObject* array=NULL, int is_new_object=0)
784 {
785   npy_intp size[2] = { -1, -1 };
786   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
787                                                    &is_new_object);
788   if (!array || !require_dimensions(array, 2) ||
789       !require_size(array, size, 2)) SWIG_fail;
790   $1 = (DATA_TYPE*) array_data(array);
791   $2 = (DIM_TYPE) array_size(array,0);
792   $3 = (DIM_TYPE) array_size(array,1);
793 }
794 %typemap(freearg)
795   (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
796 {
797   if (is_new_object$argnum && array$argnum)
798     { Py_DECREF(array$argnum); }
799 }
800
801 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
802  */
803 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
804            fragment="NumPy_Macros")
805   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
806 {
807   $1 = is_array($input) || PySequence_Check($input);
808 }
809 %typemap(in,
810          fragment="NumPy_Fragments")
811   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
812   (PyArrayObject* array=NULL, int is_new_object=0)
813 {
814   npy_intp size[2] = { -1, -1 };
815   array = obj_to_array_contiguous_allow_conversion($input,
816                                                    DATA_TYPECODE,
817                                                    &is_new_object);
818   if (!array || !require_dimensions(array, 2) ||
819       !require_size(array, size, 2)) SWIG_fail;
820   $1 = (DIM_TYPE) array_size(array,0);
821   $2 = (DIM_TYPE) array_size(array,1);
822   $3 = (DATA_TYPE*) array_data(array);
823 }
824 %typemap(freearg)
825   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2)
826 {
827   if (is_new_object$argnum && array$argnum)
828     { Py_DECREF(array$argnum); }
829 }
830
831 /* Typemap suite for (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
832  */
833 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
834            fragment="NumPy_Macros")
835   (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
836 {
837   $1 = is_array($input) || PySequence_Check($input);
838 }
839 %typemap(in,
840          fragment="NumPy_Fragments")
841   (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
842   (PyArrayObject* array=NULL, int is_new_object=0)
843 {
844   npy_intp size[2] = { -1, -1 };
845   array = obj_to_array_fortran_allow_conversion($input,
846                                                 DATA_TYPECODE,
847                                                 &is_new_object);
848   if (!array || !require_dimensions(array, 2) ||
849       !require_size(array, size, 2) || !require_fortran(array)) SWIG_fail;
850   $1 = (DATA_TYPE*) array_data(array);
851   $2 = (DIM_TYPE) array_size(array,0);
852   $3 = (DIM_TYPE) array_size(array,1);
853 }
854 %typemap(freearg)
855   (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
856 {
857   if (is_new_object$argnum && array$argnum)
858     { Py_DECREF(array$argnum); }
859 }
860
861 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
862  */
863 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
864            fragment="NumPy_Macros")
865   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
866 {
867   $1 = is_array($input) || PySequence_Check($input);
868 }
869 %typemap(in,
870          fragment="NumPy_Fragments")
871   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
872   (PyArrayObject* array=NULL, int is_new_object=0)
873 {
874   npy_intp size[2] = { -1, -1 };
875   array = obj_to_array_contiguous_allow_conversion($input,
876                                                    DATA_TYPECODE,
877                                                    &is_new_object);
878   if (!array || !require_dimensions(array, 2) ||
879       !require_size(array, size, 2) || !require_fortran(array)) SWIG_fail;
880   $1 = (DIM_TYPE) array_size(array,0);
881   $2 = (DIM_TYPE) array_size(array,1);
882   $3 = (DATA_TYPE*) array_data(array);
883 }
884 %typemap(freearg)
885   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2)
886 {
887   if (is_new_object$argnum && array$argnum)
888     { Py_DECREF(array$argnum); }
889 }
890
891 /* Typemap suite for (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
892  */
893 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
894            fragment="NumPy_Macros")
895   (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
896 {
897   $1 = is_array($input) || PySequence_Check($input);
898 }
899 %typemap(in,
900          fragment="NumPy_Fragments")
901   (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
902   (PyArrayObject* array=NULL, int is_new_object=0)
903 {
904   npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 };
905   array = obj_to_array_contiguous_allow_conversion($input,
906                                                    DATA_TYPECODE,
907                                                    &is_new_object);
908   if (!array || !require_dimensions(array, 3) ||
909       !require_size(array, size, 3)) SWIG_fail;
910   $1 = ($1_ltype) array_data(array);
911 }
912 %typemap(freearg)
913   (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY])
914 {
915   if (is_new_object$argnum && array$argnum)
916     { Py_DECREF(array$argnum); }
917 }
918
919 /* Typemap suite for (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
920  *                    DIM_TYPE DIM3)
921  */
922 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
923            fragment="NumPy_Macros")
924   (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
925 {
926   $1 = is_array($input) || PySequence_Check($input);
927 }
928 %typemap(in,
929          fragment="NumPy_Fragments")
930   (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
931   (PyArrayObject* array=NULL, int is_new_object=0)
932 {
933   npy_intp size[3] = { -1, -1, -1 };
934   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
935                                                    &is_new_object);
936   if (!array || !require_dimensions(array, 3) ||
937       !require_size(array, size, 3)) SWIG_fail;
938   $1 = (DATA_TYPE*) array_data(array);
939   $2 = (DIM_TYPE) array_size(array,0);
940   $3 = (DIM_TYPE) array_size(array,1);
941   $4 = (DIM_TYPE) array_size(array,2);
942 }
943 %typemap(freearg)
944   (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
945 {
946   if (is_new_object$argnum && array$argnum)
947     { Py_DECREF(array$argnum); }
948 }
949
950 /* Typemap suite for (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
951  *                    DIM_TYPE DIM3)
952  */
953 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
954            fragment="NumPy_Macros")
955   (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
956 {
957   /* for now, only concerned with lists */
958   $1 = PySequence_Check($input);
959 }
960 %typemap(in,
961          fragment="NumPy_Fragments")
962   (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
963   (DATA_TYPE** array=NULL, PyArrayObject** object_array=NULL, int* is_new_object_array=NULL)
964 {
965   npy_intp size[2] = { -1, -1 };
966   PyArrayObject* temp_array;
967   Py_ssize_t i;
968   int is_new_object;
969
970   /* length of the list */
971   $2 = PyList_Size($input);
972
973   /* the arrays */
974   array = (DATA_TYPE **)malloc($2*sizeof(DATA_TYPE *));
975   object_array = (PyArrayObject **)calloc($2,sizeof(PyArrayObject *));
976   is_new_object_array = (int *)calloc($2,sizeof(int));
977
978   if (array == NULL || object_array == NULL || is_new_object_array == NULL)
979   {
980     SWIG_fail;
981   }
982
983   for (i=0; i<$2; i++)
984   {
985     temp_array = obj_to_array_contiguous_allow_conversion(PySequence_GetItem($input,i), DATA_TYPECODE, &is_new_object);
986
987     /* the new array must be stored so that it can be destroyed in freearg */
988     object_array[i] = temp_array;
989     is_new_object_array[i] = is_new_object;
990
991     if (!temp_array || !require_dimensions(temp_array, 2)) SWIG_fail;
992
993     /* store the size of the first array in the list, then use that for comparison. */
994     if (i == 0)
995     {
996       size[0] = array_size(temp_array,0);
997       size[1] = array_size(temp_array,1);
998     }
999     
1000     if (!require_size(temp_array, size, 2)) SWIG_fail;
1001
1002     array[i] = (DATA_TYPE*) array_data(temp_array);
1003   }
1004
1005   $1 = (DATA_TYPE**) array;
1006   $3 = (DIM_TYPE) size[0];
1007   $4 = (DIM_TYPE) size[1];
1008 }
1009 %typemap(freearg)
1010   (DATA_TYPE** IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1011 {
1012   Py_ssize_t i;
1013
1014   if (array$argnum!=NULL) free(array$argnum);
1015
1016   /*freeing the individual arrays if needed */
1017   if (object_array$argnum!=NULL)
1018   {
1019     if (is_new_object_array$argnum!=NULL)
1020     {
1021       for (i=0; i<$2; i++)
1022       {
1023         if (object_array$argnum[i] != NULL && is_new_object_array$argnum[i])
1024         { Py_DECREF(object_array$argnum[i]); }
1025       }
1026       free(is_new_object_array$argnum);
1027     }
1028     free(object_array$argnum);
1029   }
1030 }
1031
1032 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
1033  *                    DATA_TYPE* IN_ARRAY3)
1034  */
1035 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1036            fragment="NumPy_Macros")
1037   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
1038 {
1039   $1 = is_array($input) || PySequence_Check($input);
1040 }
1041 %typemap(in,
1042          fragment="NumPy_Fragments")
1043   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
1044   (PyArrayObject* array=NULL, int is_new_object=0)
1045 {
1046   npy_intp size[3] = { -1, -1, -1 };
1047   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
1048                                                    &is_new_object);
1049   if (!array || !require_dimensions(array, 3) ||
1050       !require_size(array, size, 3)) SWIG_fail;
1051   $1 = (DIM_TYPE) array_size(array,0);
1052   $2 = (DIM_TYPE) array_size(array,1);
1053   $3 = (DIM_TYPE) array_size(array,2);
1054   $4 = (DATA_TYPE*) array_data(array);
1055 }
1056 %typemap(freearg)
1057   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3)
1058 {
1059   if (is_new_object$argnum && array$argnum)
1060     { Py_DECREF(array$argnum); }
1061 }
1062
1063 /* Typemap suite for (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
1064  *                    DIM_TYPE DIM3)
1065  */
1066 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1067            fragment="NumPy_Macros")
1068   (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1069 {
1070   $1 = is_array($input) || PySequence_Check($input);
1071 }
1072 %typemap(in,
1073          fragment="NumPy_Fragments")
1074   (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1075   (PyArrayObject* array=NULL, int is_new_object=0)
1076 {
1077   npy_intp size[3] = { -1, -1, -1 };
1078   array = obj_to_array_fortran_allow_conversion($input, DATA_TYPECODE,
1079                                                 &is_new_object);
1080   if (!array || !require_dimensions(array, 3) ||
1081       !require_size(array, size, 3) | !require_fortran(array)) SWIG_fail;
1082   $1 = (DATA_TYPE*) array_data(array);
1083   $2 = (DIM_TYPE) array_size(array,0);
1084   $3 = (DIM_TYPE) array_size(array,1);
1085   $4 = (DIM_TYPE) array_size(array,2);
1086 }
1087 %typemap(freearg)
1088   (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1089 {
1090   if (is_new_object$argnum && array$argnum)
1091     { Py_DECREF(array$argnum); }
1092 }
1093
1094 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
1095  *                    DATA_TYPE* IN_FARRAY3)
1096  */
1097 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1098            fragment="NumPy_Macros")
1099   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
1100 {
1101   $1 = is_array($input) || PySequence_Check($input);
1102 }
1103 %typemap(in,
1104          fragment="NumPy_Fragments")
1105   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
1106   (PyArrayObject* array=NULL, int is_new_object=0)
1107 {
1108   npy_intp size[3] = { -1, -1, -1 };
1109   array = obj_to_array_contiguous_allow_conversion($input,
1110                                                    DATA_TYPECODE,
1111                                                    &is_new_object);
1112   if (!array || !require_dimensions(array, 3) ||
1113       !require_size(array, size, 3) || !require_fortran(array)) SWIG_fail;
1114   $1 = (DIM_TYPE) array_size(array,0);
1115   $2 = (DIM_TYPE) array_size(array,1);
1116   $3 = (DIM_TYPE) array_size(array,2);
1117   $4 = (DATA_TYPE*) array_data(array);
1118 }
1119 %typemap(freearg)
1120   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3)
1121 {
1122   if (is_new_object$argnum && array$argnum)
1123     { Py_DECREF(array$argnum); }
1124 }
1125
1126 /* Typemap suite for (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
1127  */
1128 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1129            fragment="NumPy_Macros")
1130   (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
1131 {
1132   $1 = is_array($input) || PySequence_Check($input);
1133 }
1134 %typemap(in,
1135          fragment="NumPy_Fragments")
1136   (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
1137   (PyArrayObject* array=NULL, int is_new_object=0)
1138 {
1139   npy_intp size[4] = { $1_dim0, $1_dim1, $1_dim2 , $1_dim3};
1140   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
1141                                                    &is_new_object);
1142   if (!array || !require_dimensions(array, 4) ||
1143       !require_size(array, size, 4)) SWIG_fail;
1144   $1 = ($1_ltype) array_data(array);
1145 }
1146 %typemap(freearg)
1147   (DATA_TYPE IN_ARRAY4[ANY][ANY][ANY][ANY])
1148 {
1149   if (is_new_object$argnum && array$argnum)
1150     { Py_DECREF(array$argnum); }
1151 }
1152
1153 /* Typemap suite for (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
1154  *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
1155  */
1156 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1157            fragment="NumPy_Macros")
1158   (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1159 {
1160   $1 = is_array($input) || PySequence_Check($input);
1161 }
1162 %typemap(in,
1163          fragment="NumPy_Fragments")
1164   (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1165   (PyArrayObject* array=NULL, int is_new_object=0)
1166 {
1167   npy_intp size[4] = { -1, -1, -1, -1 };
1168   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
1169                                                    &is_new_object);
1170   if (!array || !require_dimensions(array, 4) ||
1171       !require_size(array, size, 4)) SWIG_fail;
1172   $1 = (DATA_TYPE*) array_data(array);
1173   $2 = (DIM_TYPE) array_size(array,0);
1174   $3 = (DIM_TYPE) array_size(array,1);
1175   $4 = (DIM_TYPE) array_size(array,2);
1176   $5 = (DIM_TYPE) array_size(array,3);
1177 }
1178 %typemap(freearg)
1179   (DATA_TYPE* IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1180 {
1181   if (is_new_object$argnum && array$argnum)
1182     { Py_DECREF(array$argnum); }
1183 }
1184
1185 /* Typemap suite for (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
1186  *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
1187  */
1188 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1189            fragment="NumPy_Macros")
1190   (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1191 {
1192   /* for now, only concerned with lists */
1193   $1 = PySequence_Check($input);
1194 }
1195 %typemap(in,
1196          fragment="NumPy_Fragments")
1197   (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1198   (DATA_TYPE** array=NULL, PyArrayObject** object_array=NULL, int* is_new_object_array=NULL)
1199 {
1200   npy_intp size[3] = { -1, -1, -1 };
1201   PyArrayObject* temp_array;
1202   Py_ssize_t i;
1203   int is_new_object;
1204
1205   /* length of the list */
1206   $2 = PyList_Size($input);
1207
1208   /* the arrays */
1209   array = (DATA_TYPE **)malloc($2*sizeof(DATA_TYPE *));
1210   object_array = (PyArrayObject **)calloc($2,sizeof(PyArrayObject *));
1211   is_new_object_array = (int *)calloc($2,sizeof(int));
1212
1213   if (array == NULL || object_array == NULL || is_new_object_array == NULL)
1214   {
1215     SWIG_fail;
1216   }
1217
1218   for (i=0; i<$2; i++)
1219   {
1220     temp_array = obj_to_array_contiguous_allow_conversion(PySequence_GetItem($input,i), DATA_TYPECODE, &is_new_object);
1221
1222     /* the new array must be stored so that it can be destroyed in freearg */
1223     object_array[i] = temp_array;
1224     is_new_object_array[i] = is_new_object;
1225
1226     if (!temp_array || !require_dimensions(temp_array, 3)) SWIG_fail;
1227
1228     /* store the size of the first array in the list, then use that for comparison. */
1229     if (i == 0)
1230     {
1231       size[0] = array_size(temp_array,0);
1232       size[1] = array_size(temp_array,1);
1233       size[2] = array_size(temp_array,2);
1234     }
1235     
1236     if (!require_size(temp_array, size, 3)) SWIG_fail;
1237
1238     array[i] = (DATA_TYPE*) array_data(temp_array);
1239   }
1240
1241   $1 = (DATA_TYPE**) array;
1242   $3 = (DIM_TYPE) size[0];
1243   $4 = (DIM_TYPE) size[1];
1244   $5 = (DIM_TYPE) size[2];
1245 }
1246 %typemap(freearg)
1247   (DATA_TYPE** IN_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1248 {
1249   Py_ssize_t i;
1250
1251   if (array$argnum!=NULL) free(array$argnum);
1252
1253   /*freeing the individual arrays if needed */
1254   if (object_array$argnum!=NULL)
1255   {
1256     if (is_new_object_array$argnum!=NULL)
1257     {
1258       for (i=0; i<$2; i++)
1259       {
1260         if (object_array$argnum[i] != NULL && is_new_object_array$argnum[i])
1261         { Py_DECREF(object_array$argnum[i]); }
1262       }
1263       free(is_new_object_array$argnum);
1264     }
1265     free(object_array$argnum);
1266   }
1267 }
1268
1269 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4,
1270  *                    DATA_TYPE* IN_ARRAY4)
1271  */
1272 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1273            fragment="NumPy_Macros")
1274   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_ARRAY4)
1275 {
1276   $1 = is_array($input) || PySequence_Check($input);
1277 }
1278 %typemap(in,
1279          fragment="NumPy_Fragments")
1280   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_ARRAY4)
1281   (PyArrayObject* array=NULL, int is_new_object=0)
1282 {
1283   npy_intp size[4] = { -1, -1, -1 , -1};
1284   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
1285                                                    &is_new_object);
1286   if (!array || !require_dimensions(array, 4) ||
1287       !require_size(array, size, 4)) SWIG_fail;
1288   $1 = (DIM_TYPE) array_size(array,0);
1289   $2 = (DIM_TYPE) array_size(array,1);
1290   $3 = (DIM_TYPE) array_size(array,2);
1291   $4 = (DIM_TYPE) array_size(array,3);
1292   $5 = (DATA_TYPE*) array_data(array);
1293 }
1294 %typemap(freearg)
1295   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_ARRAY4)
1296 {
1297   if (is_new_object$argnum && array$argnum)
1298     { Py_DECREF(array$argnum); }
1299 }
1300
1301 /* Typemap suite for (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
1302  *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
1303  */
1304 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1305            fragment="NumPy_Macros")
1306   (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1307 {
1308   $1 = is_array($input) || PySequence_Check($input);
1309 }
1310 %typemap(in,
1311          fragment="NumPy_Fragments")
1312   (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1313   (PyArrayObject* array=NULL, int is_new_object=0)
1314 {
1315   npy_intp size[4] = { -1, -1, -1, -1 };
1316   array = obj_to_array_fortran_allow_conversion($input, DATA_TYPECODE,
1317                                                 &is_new_object);
1318   if (!array || !require_dimensions(array, 4) ||
1319       !require_size(array, size, 4) | !require_fortran(array)) SWIG_fail;
1320   $1 = (DATA_TYPE*) array_data(array);
1321   $2 = (DIM_TYPE) array_size(array,0);
1322   $3 = (DIM_TYPE) array_size(array,1);
1323   $4 = (DIM_TYPE) array_size(array,2);
1324   $5 = (DIM_TYPE) array_size(array,3);
1325 }
1326 %typemap(freearg)
1327   (DATA_TYPE* IN_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1328 {
1329   if (is_new_object$argnum && array$argnum)
1330     { Py_DECREF(array$argnum); }
1331 }
1332
1333 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4,
1334  *                    DATA_TYPE* IN_FARRAY4)
1335  */
1336 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1337            fragment="NumPy_Macros")
1338   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_FARRAY4)
1339 {
1340   $1 = is_array($input) || PySequence_Check($input);
1341 }
1342 %typemap(in,
1343          fragment="NumPy_Fragments")
1344   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_FARRAY4)
1345   (PyArrayObject* array=NULL, int is_new_object=0)
1346 {
1347   npy_intp size[4] = { -1, -1, -1 , -1 };
1348   array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
1349                                                    &is_new_object);
1350   if (!array || !require_dimensions(array, 4) ||
1351       !require_size(array, size, 4) || !require_fortran(array)) SWIG_fail;
1352   $1 = (DIM_TYPE) array_size(array,0);
1353   $2 = (DIM_TYPE) array_size(array,1);
1354   $3 = (DIM_TYPE) array_size(array,2);
1355   $4 = (DIM_TYPE) array_size(array,3);
1356   $5 = (DATA_TYPE*) array_data(array);
1357 }
1358 %typemap(freearg)
1359   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* IN_FARRAY4)
1360 {
1361   if (is_new_object$argnum && array$argnum)
1362     { Py_DECREF(array$argnum); }
1363 }
1364
1365 /***************************/
1366 /* In-Place Array Typemaps */
1367 /***************************/
1368
1369 /* Typemap suite for (DATA_TYPE INPLACE_ARRAY1[ANY])
1370  */
1371 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1372            fragment="NumPy_Macros")
1373   (DATA_TYPE INPLACE_ARRAY1[ANY])
1374 {
1375   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1376                                                  DATA_TYPECODE);
1377 }
1378 %typemap(in,
1379          fragment="NumPy_Fragments")
1380   (DATA_TYPE INPLACE_ARRAY1[ANY])
1381   (PyArrayObject* array=NULL)
1382 {
1383   npy_intp size[1] = { $1_dim0 };
1384   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1385   if (!array || !require_dimensions(array,1) || !require_size(array, size, 1) ||
1386       !require_contiguous(array) || !require_native(array)) SWIG_fail;
1387   $1 = ($1_ltype) array_data(array);
1388 }
1389
1390 /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
1391  */
1392 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1393            fragment="NumPy_Macros")
1394   (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
1395 {
1396   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1397                                                  DATA_TYPECODE);
1398 }
1399 %typemap(in,
1400          fragment="NumPy_Fragments")
1401   (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1)
1402   (PyArrayObject* array=NULL, int i=1)
1403 {
1404   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1405   if (!array || !require_dimensions(array,1) || !require_contiguous(array)
1406       || !require_native(array)) SWIG_fail;
1407   $1 = (DATA_TYPE*) array_data(array);
1408   $2 = 1;
1409   for (i=0; i < array_numdims(array); ++i) $2 *= array_size(array,i);
1410 }
1411
1412 /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
1413  */
1414 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1415            fragment="NumPy_Macros")
1416   (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
1417 {
1418   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1419                                                  DATA_TYPECODE);
1420 }
1421 %typemap(in,
1422          fragment="NumPy_Fragments")
1423   (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1)
1424   (PyArrayObject* array=NULL, int i=0)
1425 {
1426   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1427   if (!array || !require_dimensions(array,1) || !require_contiguous(array)
1428       || !require_native(array)) SWIG_fail;
1429   $1 = 1;
1430   for (i=0; i < array_numdims(array); ++i) $1 *= array_size(array,i);
1431   $2 = (DATA_TYPE*) array_data(array);
1432 }
1433
1434 /* Typemap suite for (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
1435  */
1436 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1437            fragment="NumPy_Macros")
1438   (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
1439 {
1440   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1441                                                  DATA_TYPECODE);
1442 }
1443 %typemap(in,
1444          fragment="NumPy_Fragments")
1445   (DATA_TYPE INPLACE_ARRAY2[ANY][ANY])
1446   (PyArrayObject* array=NULL)
1447 {
1448   npy_intp size[2] = { $1_dim0, $1_dim1 };
1449   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1450   if (!array || !require_dimensions(array,2) || !require_size(array, size, 2) ||
1451       !require_contiguous(array) || !require_native(array)) SWIG_fail;
1452   $1 = ($1_ltype) array_data(array);
1453 }
1454
1455 /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1456  */
1457 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1458            fragment="NumPy_Macros")
1459   (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1460 {
1461   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1462                                                  DATA_TYPECODE);
1463 }
1464 %typemap(in,
1465          fragment="NumPy_Fragments")
1466   (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1467   (PyArrayObject* array=NULL)
1468 {
1469   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1470   if (!array || !require_dimensions(array,2) || !require_contiguous(array)
1471       || !require_native(array)) SWIG_fail;
1472   $1 = (DATA_TYPE*) array_data(array);
1473   $2 = (DIM_TYPE) array_size(array,0);
1474   $3 = (DIM_TYPE) array_size(array,1);
1475 }
1476
1477 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
1478  */
1479 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1480            fragment="NumPy_Macros")
1481   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
1482 {
1483   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1484                                                  DATA_TYPECODE);
1485 }
1486 %typemap(in,
1487          fragment="NumPy_Fragments")
1488   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2)
1489   (PyArrayObject* array=NULL)
1490 {
1491   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1492   if (!array || !require_dimensions(array,2) || !require_contiguous(array) ||
1493       !require_native(array)) SWIG_fail;
1494   $1 = (DIM_TYPE) array_size(array,0);
1495   $2 = (DIM_TYPE) array_size(array,1);
1496   $3 = (DATA_TYPE*) array_data(array);
1497 }
1498
1499 /* Typemap suite for (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1500  */
1501 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1502            fragment="NumPy_Macros")
1503   (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1504 {
1505   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1506                                                  DATA_TYPECODE);
1507 }
1508 %typemap(in,
1509          fragment="NumPy_Fragments")
1510   (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2)
1511   (PyArrayObject* array=NULL)
1512 {
1513   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1514   if (!array || !require_dimensions(array,2) || !require_contiguous(array)
1515       || !require_native(array) || !require_fortran(array)) SWIG_fail;
1516   $1 = (DATA_TYPE*) array_data(array);
1517   $2 = (DIM_TYPE) array_size(array,0);
1518   $3 = (DIM_TYPE) array_size(array,1);
1519 }
1520
1521 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
1522  */
1523 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1524            fragment="NumPy_Macros")
1525   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
1526 {
1527   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1528                                                  DATA_TYPECODE);
1529 }
1530 %typemap(in,
1531          fragment="NumPy_Fragments")
1532   (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2)
1533   (PyArrayObject* array=NULL)
1534 {
1535   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1536   if (!array || !require_dimensions(array,2) || !require_contiguous(array) ||
1537       !require_native(array) || !require_fortran(array)) SWIG_fail;
1538   $1 = (DIM_TYPE) array_size(array,0);
1539   $2 = (DIM_TYPE) array_size(array,1);
1540   $3 = (DATA_TYPE*) array_data(array);
1541 }
1542
1543 /* Typemap suite for (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
1544  */
1545 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1546            fragment="NumPy_Macros")
1547   (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
1548 {
1549   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1550                                                  DATA_TYPECODE);
1551 }
1552 %typemap(in,
1553          fragment="NumPy_Fragments")
1554   (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY])
1555   (PyArrayObject* array=NULL)
1556 {
1557   npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 };
1558   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1559   if (!array || !require_dimensions(array,3) || !require_size(array, size, 3) ||
1560       !require_contiguous(array) || !require_native(array)) SWIG_fail;
1561   $1 = ($1_ltype) array_data(array);
1562 }
1563
1564 /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
1565  *                    DIM_TYPE DIM3)
1566  */
1567 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1568            fragment="NumPy_Macros")
1569   (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1570 {
1571   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1572                                                  DATA_TYPECODE);
1573 }
1574 %typemap(in,
1575          fragment="NumPy_Fragments")
1576   (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1577   (PyArrayObject* array=NULL)
1578 {
1579   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1580   if (!array || !require_dimensions(array,3) || !require_contiguous(array) ||
1581       !require_native(array)) SWIG_fail;
1582   $1 = (DATA_TYPE*) array_data(array);
1583   $2 = (DIM_TYPE) array_size(array,0);
1584   $3 = (DIM_TYPE) array_size(array,1);
1585   $4 = (DIM_TYPE) array_size(array,2);
1586 }
1587
1588 /* Typemap suite for (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
1589  *                    DIM_TYPE DIM3)
1590  */
1591 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1592            fragment="NumPy_Macros")
1593   (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1594 {
1595   $1 = PySequence_Check($input);
1596 }
1597 %typemap(in,
1598          fragment="NumPy_Fragments")
1599   (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1600   (DATA_TYPE** array=NULL, PyArrayObject** object_array=NULL)
1601 {
1602   npy_intp size[2] = { -1, -1 };
1603   PyArrayObject* temp_array;
1604   Py_ssize_t i;
1605
1606   /* length of the list */
1607   $2 = PyList_Size($input);
1608
1609   /* the arrays */
1610   array = (DATA_TYPE **)malloc($2*sizeof(DATA_TYPE *));
1611   object_array = (PyArrayObject **)calloc($2,sizeof(PyArrayObject *));
1612
1613   if (array == NULL || object_array == NULL)
1614   {
1615     SWIG_fail;
1616   }
1617
1618   for (i=0; i<$2; i++)
1619   {
1620     temp_array = obj_to_array_no_conversion(PySequence_GetItem($input,i), DATA_TYPECODE);
1621
1622     /* the new array must be stored so that it can be destroyed in freearg */
1623     object_array[i] = temp_array;
1624
1625     if ( !temp_array || !require_dimensions(temp_array, 2) ||
1626       !require_contiguous(temp_array) ||
1627       !require_native(temp_array) ||
1628       !PyArray_EquivTypenums(array_type(temp_array), DATA_TYPECODE)
1629     ) SWIG_fail;
1630
1631     /* store the size of the first array in the list, then use that for comparison. */
1632     if (i == 0)
1633     {
1634       size[0] = array_size(temp_array,0);
1635       size[1] = array_size(temp_array,1);
1636     }
1637     
1638     if (!require_size(temp_array, size, 2)) SWIG_fail;
1639
1640     array[i] = (DATA_TYPE*) array_data(temp_array);
1641   }
1642
1643   $1 = (DATA_TYPE**) array;
1644   $3 = (DIM_TYPE) size[0];
1645   $4 = (DIM_TYPE) size[1];
1646 }
1647 %typemap(freearg)
1648   (DATA_TYPE** INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1649 {
1650   if (array$argnum!=NULL) free(array$argnum);
1651   if (object_array$argnum!=NULL) free(object_array$argnum);
1652 }
1653
1654 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
1655  *                    DATA_TYPE* INPLACE_ARRAY3)
1656  */
1657 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1658            fragment="NumPy_Macros")
1659   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
1660 {
1661   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1662                                                  DATA_TYPECODE);
1663 }
1664 %typemap(in,
1665          fragment="NumPy_Fragments")
1666   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3)
1667   (PyArrayObject* array=NULL)
1668 {
1669   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1670   if (!array || !require_dimensions(array,3) || !require_contiguous(array)
1671       || !require_native(array)) SWIG_fail;
1672   $1 = (DIM_TYPE) array_size(array,0);
1673   $2 = (DIM_TYPE) array_size(array,1);
1674   $3 = (DIM_TYPE) array_size(array,2);
1675   $4 = (DATA_TYPE*) array_data(array);
1676 }
1677
1678 /* Typemap suite for (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2,
1679  *                    DIM_TYPE DIM3)
1680  */
1681 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1682            fragment="NumPy_Macros")
1683   (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1684 {
1685   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1686                                                  DATA_TYPECODE);
1687 }
1688 %typemap(in,
1689          fragment="NumPy_Fragments")
1690   (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3)
1691   (PyArrayObject* array=NULL)
1692 {
1693   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1694   if (!array || !require_dimensions(array,3) || !require_contiguous(array) ||
1695       !require_native(array) || !require_fortran(array)) SWIG_fail;
1696   $1 = (DATA_TYPE*) array_data(array);
1697   $2 = (DIM_TYPE) array_size(array,0);
1698   $3 = (DIM_TYPE) array_size(array,1);
1699   $4 = (DIM_TYPE) array_size(array,2);
1700 }
1701
1702 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
1703  *                    DATA_TYPE* INPLACE_FARRAY3)
1704  */
1705 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1706            fragment="NumPy_Macros")
1707   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3)
1708 {
1709   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1710                                                  DATA_TYPECODE);
1711 }
1712 %typemap(in,
1713          fragment="NumPy_Fragments")
1714   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3)
1715   (PyArrayObject* array=NULL)
1716 {
1717   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1718   if (!array || !require_dimensions(array,3) || !require_contiguous(array)
1719       || !require_native(array) || !require_fortran(array)) SWIG_fail;
1720   $1 = (DIM_TYPE) array_size(array,0);
1721   $2 = (DIM_TYPE) array_size(array,1);
1722   $3 = (DIM_TYPE) array_size(array,2);
1723   $4 = (DATA_TYPE*) array_data(array);
1724 }
1725
1726 /* Typemap suite for (DATA_TYPE INPLACE_ARRAY4[ANY][ANY][ANY][ANY])
1727  */
1728 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1729            fragment="NumPy_Macros")
1730   (DATA_TYPE INPLACE_ARRAY4[ANY][ANY][ANY][ANY])
1731 {
1732   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1733                                                  DATA_TYPECODE);
1734 }
1735 %typemap(in,
1736          fragment="NumPy_Fragments")
1737   (DATA_TYPE INPLACE_ARRAY4[ANY][ANY][ANY][ANY])
1738   (PyArrayObject* array=NULL)
1739 {
1740   npy_intp size[4] = { $1_dim0, $1_dim1, $1_dim2 , $1_dim3 };
1741   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1742   if (!array || !require_dimensions(array,4) || !require_size(array, size, 4) ||
1743       !require_contiguous(array) || !require_native(array)) SWIG_fail;
1744   $1 = ($1_ltype) array_data(array);
1745 }
1746
1747 /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
1748  *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
1749  */
1750 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1751            fragment="NumPy_Macros")
1752   (DATA_TYPE* INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1753 {
1754   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1755                                                  DATA_TYPECODE);
1756 }
1757 %typemap(in,
1758          fragment="NumPy_Fragments")
1759   (DATA_TYPE* INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1760   (PyArrayObject* array=NULL)
1761 {
1762   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1763   if (!array || !require_dimensions(array,4) || !require_contiguous(array) ||
1764       !require_native(array)) SWIG_fail;
1765   $1 = (DATA_TYPE*) array_data(array);
1766   $2 = (DIM_TYPE) array_size(array,0);
1767   $3 = (DIM_TYPE) array_size(array,1);
1768   $4 = (DIM_TYPE) array_size(array,2);
1769   $5 = (DIM_TYPE) array_size(array,3);
1770 }
1771
1772 /* Typemap suite for (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
1773  *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
1774  */
1775 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1776            fragment="NumPy_Macros")
1777   (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1778 {
1779   $1 = PySequence_Check($input);
1780 }
1781 %typemap(in,
1782          fragment="NumPy_Fragments")
1783   (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1784   (DATA_TYPE** array=NULL, PyArrayObject** object_array=NULL)
1785 {
1786   npy_intp size[3] = { -1, -1, -1 };
1787   PyArrayObject* temp_array;
1788   Py_ssize_t i;
1789
1790   /* length of the list */
1791   $2 = PyList_Size($input);
1792
1793   /* the arrays */
1794   array = (DATA_TYPE **)malloc($2*sizeof(DATA_TYPE *));
1795   object_array = (PyArrayObject **)calloc($2,sizeof(PyArrayObject *));
1796
1797   if (array == NULL || object_array == NULL)
1798   {
1799     SWIG_fail;
1800   }
1801
1802   for (i=0; i<$2; i++)
1803   {
1804     temp_array = obj_to_array_no_conversion(PySequence_GetItem($input,i), DATA_TYPECODE);
1805
1806     /* the new array must be stored so that it can be destroyed in freearg */
1807     object_array[i] = temp_array;
1808
1809     if ( !temp_array || !require_dimensions(temp_array, 3) ||
1810       !require_contiguous(temp_array) ||
1811       !require_native(temp_array) ||
1812       !PyArray_EquivTypenums(array_type(temp_array), DATA_TYPECODE)
1813     ) SWIG_fail;
1814
1815     /* store the size of the first array in the list, then use that for comparison. */
1816     if (i == 0)
1817     {
1818       size[0] = array_size(temp_array,0);
1819       size[1] = array_size(temp_array,1);
1820       size[2] = array_size(temp_array,2);
1821     }
1822     
1823     if (!require_size(temp_array, size, 3)) SWIG_fail;
1824
1825     array[i] = (DATA_TYPE*) array_data(temp_array);
1826   }
1827
1828   $1 = (DATA_TYPE**) array;
1829   $3 = (DIM_TYPE) size[0];
1830   $4 = (DIM_TYPE) size[1];
1831   $5 = (DIM_TYPE) size[2];
1832 }
1833 %typemap(freearg)
1834   (DATA_TYPE** INPLACE_ARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1835 {
1836   if (array$argnum!=NULL) free(array$argnum);
1837   if (object_array$argnum!=NULL) free(object_array$argnum);
1838 }
1839
1840 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4,
1841  *                    DATA_TYPE* INPLACE_ARRAY4)
1842  */
1843 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1844            fragment="NumPy_Macros")
1845   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_ARRAY4)
1846 {
1847   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1848                                                  DATA_TYPECODE);
1849 }
1850 %typemap(in,
1851          fragment="NumPy_Fragments")
1852   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_ARRAY4)
1853   (PyArrayObject* array=NULL)
1854 {
1855   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1856   if (!array || !require_dimensions(array,4) || !require_contiguous(array)
1857       || !require_native(array)) SWIG_fail;
1858   $1 = (DIM_TYPE) array_size(array,0);
1859   $2 = (DIM_TYPE) array_size(array,1);
1860   $3 = (DIM_TYPE) array_size(array,2);
1861   $4 = (DIM_TYPE) array_size(array,3);
1862   $5 = (DATA_TYPE*) array_data(array);
1863 }
1864
1865 /* Typemap suite for (DATA_TYPE* INPLACE_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2,
1866  *                    DIM_TYPE DIM3, DIM_TYPE DIM4)
1867  */
1868 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1869            fragment="NumPy_Macros")
1870   (DATA_TYPE* INPLACE_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1871 {
1872   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1873                                                  DATA_TYPECODE);
1874 }
1875 %typemap(in,
1876          fragment="NumPy_Fragments")
1877   (DATA_TYPE* INPLACE_FARRAY4, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4)
1878   (PyArrayObject* array=NULL)
1879 {
1880   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1881   if (!array || !require_dimensions(array,4) || !require_contiguous(array) ||
1882       !require_native(array) || !require_fortran(array)) SWIG_fail;
1883   $1 = (DATA_TYPE*) array_data(array);
1884   $2 = (DIM_TYPE) array_size(array,0);
1885   $3 = (DIM_TYPE) array_size(array,1);
1886   $4 = (DIM_TYPE) array_size(array,2);
1887   $5 = (DIM_TYPE) array_size(array,3);
1888 }
1889
1890 /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3,
1891  *                    DATA_TYPE* INPLACE_FARRAY4)
1892  */
1893 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
1894            fragment="NumPy_Macros")
1895   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_FARRAY4)
1896 {
1897   $1 = is_array($input) && PyArray_EquivTypenums(array_type($input),
1898                                                  DATA_TYPECODE);
1899 }
1900 %typemap(in,
1901          fragment="NumPy_Fragments")
1902   (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DIM_TYPE DIM4, DATA_TYPE* INPLACE_FARRAY4)
1903   (PyArrayObject* array=NULL)
1904 {
1905   array = obj_to_array_no_conversion($input, DATA_TYPECODE);
1906   if (!array || !require_dimensions(array,4) || !require_contiguous(array)
1907       || !require_native(array) || !require_fortran(array)) SWIG_fail;
1908   $1 = (DIM_TYPE) array_size(array,0);
1909   $2 = (DIM_TYPE) array_size(array,1);
1910   $3 = (DIM_TYPE) array_size(array,2);
1911   $4 = (DIM_TYPE) array_size(array,3);
1912   $5 = (DATA_TYPE*) array_data(array);
1913 }
1914
1915 /*************************/
1916 /* Argout Array Typemaps */
1917 /*************************/
1918
1919 /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY1[ANY])
1920  */
1921 %typemap(in,numinputs=0,
1922          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
1923   (DATA_TYPE ARGOUT_ARRAY1[ANY])
1924   (PyObject* array = NULL)
1925 {
1926   npy_intp dims[1] = { $1_dim0 };
1927   array = PyArray_SimpleNew(1, dims, DATA_TYPECODE);
1928   if (!array) SWIG_fail;
1929   $1 = ($1_ltype) array_data(array);
1930 }
1931 %typemap(argout)
1932   (DATA_TYPE ARGOUT_ARRAY1[ANY])
1933 {
1934   $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
1935 }
1936
1937 /* Typemap suite for (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
1938  */
1939 %typemap(in,numinputs=1,
1940          fragment="NumPy_Fragments")
1941   (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
1942   (PyObject* array = NULL)
1943 {
1944   npy_intp dims[1];
1945   if (!PyInt_Check($input))
1946   {
1947     const char* typestring = pytype_string($input);
1948     PyErr_Format(PyExc_TypeError,
1949                  "Int dimension expected.  '%s' given.",
1950                  typestring);
1951     SWIG_fail;
1952   }
1953   $2 = (DIM_TYPE) PyInt_AsLong($input);
1954   dims[0] = (npy_intp) $2;
1955   array = PyArray_SimpleNew(1, dims, DATA_TYPECODE);
1956   if (!array) SWIG_fail;
1957   $1 = (DATA_TYPE*) array_data(array);
1958 }
1959 %typemap(argout)
1960   (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1)
1961 {
1962   $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
1963 }
1964
1965 /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
1966  */
1967 %typemap(in,numinputs=1,
1968          fragment="NumPy_Fragments")
1969   (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
1970   (PyObject* array = NULL)
1971 {
1972   npy_intp dims[1];
1973   if (!PyInt_Check($input))
1974   {
1975     const char* typestring = pytype_string($input);
1976     PyErr_Format(PyExc_TypeError,
1977                  "Int dimension expected.  '%s' given.",
1978                  typestring);
1979     SWIG_fail;
1980   }
1981   $1 = (DIM_TYPE) PyInt_AsLong($input);
1982   dims[0] = (npy_intp) $1;
1983   array = PyArray_SimpleNew(1, dims, DATA_TYPECODE);
1984   if (!array) SWIG_fail;
1985   $2 = (DATA_TYPE*) array_data(array);
1986 }
1987 %typemap(argout)
1988   (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1)
1989 {
1990   $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
1991 }
1992
1993 /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
1994  */
1995 %typemap(in,numinputs=0,
1996          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
1997   (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
1998   (PyObject* array = NULL)
1999 {
2000   npy_intp dims[2] = { $1_dim0, $1_dim1 };
2001   array = PyArray_SimpleNew(2, dims, DATA_TYPECODE);
2002   if (!array) SWIG_fail;
2003   $1 = ($1_ltype) array_data(array);
2004 }
2005 %typemap(argout)
2006   (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY])
2007 {
2008   $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
2009 }
2010
2011 /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
2012  */
2013 %typemap(in,numinputs=0,
2014          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
2015   (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
2016   (PyObject* array = NULL)
2017 {
2018   npy_intp dims[3] = { $1_dim0, $1_dim1, $1_dim2 };
2019   array = PyArray_SimpleNew(3, dims, DATA_TYPECODE);
2020   if (!array) SWIG_fail;
2021   $1 = ($1_ltype) array_data(array);
2022 }
2023 %typemap(argout)
2024   (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY])
2025 {
2026   $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
2027 }
2028
2029 /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY])
2030  */
2031 %typemap(in,numinputs=0,
2032          fragment="NumPy_Backward_Compatibility,NumPy_Macros")
2033   (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY])
2034   (PyObject* array = NULL)
2035 {
2036   npy_intp dims[4] = { $1_dim0, $1_dim1, $1_dim2, $1_dim3 };
2037   array = PyArray_SimpleNew(4, dims, DATA_TYPECODE);
2038   if (!array) SWIG_fail;
2039   $1 = ($1_ltype) array_data(array);
2040 }
2041 %typemap(argout)
2042   (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY])
2043 {
2044   $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
2045 }
2046
2047 /*****************************/
2048 /* Argoutview Array Typemaps */
2049 /*****************************/
2050
2051 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1)
2052  */
2053 %typemap(in,numinputs=0)
2054   (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1    )
2055   (DATA_TYPE*  data_temp = NULL , DIM_TYPE  dim_temp)
2056 {
2057   $1 = &data_temp;
2058   $2 = &dim_temp;
2059 }
2060 %typemap(argout,
2061          fragment="NumPy_Backward_Compatibility")
2062   (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1)
2063 {
2064   npy_intp dims[1] = { *$2 };
2065   PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$1));
2066   PyArrayObject* array = (PyArrayObject*) obj;
2067
2068   if (!array) SWIG_fail;
2069   $result = SWIG_Python_AppendOutput($result,obj);
2070 }
2071
2072 /* Typemap suite for (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
2073  */
2074 %typemap(in,numinputs=0)
2075   (DIM_TYPE* DIM1    , DATA_TYPE** ARGOUTVIEW_ARRAY1)
2076   (DIM_TYPE  dim_temp, DATA_TYPE*  data_temp = NULL )
2077 {
2078   $1 = &dim_temp;
2079   $2 = &data_temp;
2080 }
2081 %typemap(argout,
2082          fragment="NumPy_Backward_Compatibility")
2083   (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1)
2084 {
2085   npy_intp dims[1] = { *$1 };
2086   PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$2));
2087   PyArrayObject* array = (PyArrayObject*) obj;
2088
2089   if (!array) SWIG_fail;
2090   $result = SWIG_Python_AppendOutput($result,obj);
2091 }
2092
2093 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
2094  */
2095 %typemap(in,numinputs=0)
2096   (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
2097   (DATA_TYPE*  data_temp = NULL , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
2098 {
2099   $1 = &data_temp;
2100   $2 = &dim1_temp;
2101   $3 = &dim2_temp;
2102 }
2103 %typemap(argout,
2104          fragment="NumPy_Backward_Compatibility")
2105   (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
2106 {
2107   npy_intp dims[2] = { *$2, *$3 };
2108   PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
2109   PyArrayObject* array = (PyArrayObject*) obj;
2110
2111   if (!array) SWIG_fail;
2112   $result = SWIG_Python_AppendOutput($result,obj);
2113 }
2114
2115 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
2116  */
2117 %typemap(in,numinputs=0)
2118   (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEW_ARRAY2)
2119   (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp = NULL )
2120 {
2121   $1 = &dim1_temp;
2122   $2 = &dim2_temp;
2123   $3 = &data_temp;
2124 }
2125 %typemap(argout,
2126          fragment="NumPy_Backward_Compatibility")
2127   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2)
2128 {
2129   npy_intp dims[2] = { *$1, *$2 };
2130   PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
2131   PyArrayObject* array = (PyArrayObject*) obj;
2132
2133   if (!array) SWIG_fail;
2134   $result = SWIG_Python_AppendOutput($result,obj);
2135 }
2136
2137 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
2138  */
2139 %typemap(in,numinputs=0)
2140   (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
2141   (DATA_TYPE*  data_temp = NULL  , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
2142 {
2143   $1 = &data_temp;
2144   $2 = &dim1_temp;
2145   $3 = &dim2_temp;
2146 }
2147 %typemap(argout,
2148          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2149   (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
2150 {
2151   npy_intp dims[2] = { *$2, *$3 };
2152   PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
2153   PyArrayObject* array = (PyArrayObject*) obj;
2154
2155   if (!array || !require_fortran(array)) SWIG_fail;
2156   $result = SWIG_Python_AppendOutput($result,obj);
2157 }
2158
2159 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2)
2160  */
2161 %typemap(in,numinputs=0)
2162   (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEW_FARRAY2)
2163   (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp = NULL  )
2164 {
2165   $1 = &dim1_temp;
2166   $2 = &dim2_temp;
2167   $3 = &data_temp;
2168 }
2169 %typemap(argout,
2170          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2171   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2)
2172 {
2173   npy_intp dims[2] = { *$1, *$2 };
2174   PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
2175   PyArrayObject* array = (PyArrayObject*) obj;
2176
2177   if (!array || !require_fortran(array)) SWIG_fail;
2178   $result = SWIG_Python_AppendOutput($result,obj);
2179 }
2180
2181 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2182                       DIM_TYPE* DIM3)
2183  */
2184 %typemap(in,numinputs=0)
2185   (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    )
2186   (DATA_TYPE* data_temp = NULL  , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
2187 {
2188   $1 = &data_temp;
2189   $2 = &dim1_temp;
2190   $3 = &dim2_temp;
2191   $4 = &dim3_temp;
2192 }
2193 %typemap(argout,
2194          fragment="NumPy_Backward_Compatibility")
2195   (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
2196 {
2197   npy_intp dims[3] = { *$2, *$3, *$4 };
2198   PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
2199   PyArrayObject* array = (PyArrayObject*) obj;
2200
2201   if (!array) SWIG_fail;
2202   $result = SWIG_Python_AppendOutput($result,obj);
2203 }
2204
2205 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3,
2206                       DATA_TYPE** ARGOUTVIEW_ARRAY3)
2207  */
2208 %typemap(in,numinputs=0)
2209   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
2210   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp = NULL)
2211 {
2212   $1 = &dim1_temp;
2213   $2 = &dim2_temp;
2214   $3 = &dim3_temp;
2215   $4 = &data_temp;
2216 }
2217 %typemap(argout,
2218          fragment="NumPy_Backward_Compatibility")
2219   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3)
2220 {
2221   npy_intp dims[3] = { *$1, *$2, *$3 };
2222   PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4));
2223   PyArrayObject* array = (PyArrayObject*) obj;
2224
2225   if (!array) SWIG_fail;
2226   $result = SWIG_Python_AppendOutput($result,obj);
2227 }
2228
2229 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2230                       DIM_TYPE* DIM3)
2231  */
2232 %typemap(in,numinputs=0)
2233   (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    )
2234   (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
2235 {
2236   $1 = &data_temp;
2237   $2 = &dim1_temp;
2238   $3 = &dim2_temp;
2239   $4 = &dim3_temp;
2240 }
2241 %typemap(argout,
2242          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2243   (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
2244 {
2245   npy_intp dims[3] = { *$2, *$3, *$4 };
2246   PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
2247   PyArrayObject* array = (PyArrayObject*) obj;
2248
2249   if (!array || require_fortran(array)) SWIG_fail;
2250   $result = SWIG_Python_AppendOutput($result,obj);
2251 }
2252
2253 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3,
2254                       DATA_TYPE** ARGOUTVIEW_FARRAY3)
2255  */
2256 %typemap(in,numinputs=0)
2257   (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DATA_TYPE** ARGOUTVIEW_FARRAY3)
2258   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp = NULL   )
2259 {
2260   $1 = &dim1_temp;
2261   $2 = &dim2_temp;
2262   $3 = &dim3_temp;
2263   $4 = &data_temp;
2264 }
2265 %typemap(argout,
2266          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2267   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3)
2268 {
2269   npy_intp dims[3] = { *$1, *$2, *$3 };
2270   PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4));
2271   PyArrayObject* array = (PyArrayObject*) obj;
2272
2273   if (!array || require_fortran(array)) SWIG_fail;
2274   $result = SWIG_Python_AppendOutput($result,obj);
2275 }
2276
2277 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2278                       DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2279  */
2280 %typemap(in,numinputs=0)
2281   (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
2282   (DATA_TYPE* data_temp = NULL  , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
2283 {
2284   $1 = &data_temp;
2285   $2 = &dim1_temp;
2286   $3 = &dim2_temp;
2287   $4 = &dim3_temp;
2288   $5 = &dim4_temp;
2289 }
2290 %typemap(argout,
2291          fragment="NumPy_Backward_Compatibility")
2292   (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2293 {
2294   npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
2295   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
2296   PyArrayObject* array = (PyArrayObject*) obj;
2297
2298   if (!array) SWIG_fail;
2299   $result = SWIG_Python_AppendOutput($result,obj);
2300 }
2301
2302 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
2303                       DATA_TYPE** ARGOUTVIEW_ARRAY4)
2304  */
2305 %typemap(in,numinputs=0)
2306   (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEW_ARRAY4)
2307   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL  )
2308 {
2309   $1 = &dim1_temp;
2310   $2 = &dim2_temp;
2311   $3 = &dim3_temp;
2312   $4 = &dim4_temp;
2313   $5 = &data_temp;
2314 }
2315 %typemap(argout,
2316          fragment="NumPy_Backward_Compatibility")
2317   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_ARRAY4)
2318 {
2319   npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
2320   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
2321   PyArrayObject* array = (PyArrayObject*) obj;
2322
2323   if (!array) SWIG_fail;
2324   $result = SWIG_Python_AppendOutput($result,obj);
2325 }
2326
2327 /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2328                       DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2329  */
2330 %typemap(in,numinputs=0)
2331   (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
2332   (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
2333 {
2334   $1 = &data_temp;
2335   $2 = &dim1_temp;
2336   $3 = &dim2_temp;
2337   $4 = &dim3_temp;
2338   $5 = &dim4_temp;
2339 }
2340 %typemap(argout,
2341          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2342   (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2343 {
2344   npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
2345   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
2346   PyArrayObject* array = (PyArrayObject*) obj;
2347
2348   if (!array || require_fortran(array)) SWIG_fail;
2349   $result = SWIG_Python_AppendOutput($result,obj);
2350 }
2351
2352 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
2353                       DATA_TYPE** ARGOUTVIEW_FARRAY4)
2354  */
2355 %typemap(in,numinputs=0)
2356   (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEW_FARRAY4)
2357   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL   )
2358 {
2359   $1 = &dim1_temp;
2360   $2 = &dim2_temp;
2361   $3 = &dim3_temp;
2362   $4 = &dim4_temp;
2363   $5 = &data_temp;
2364 }
2365 %typemap(argout,
2366          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2367   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEW_FARRAY4)
2368 {
2369   npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
2370   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
2371   PyArrayObject* array = (PyArrayObject*) obj;
2372
2373   if (!array || require_fortran(array)) SWIG_fail;
2374   $result = SWIG_Python_AppendOutput($result,obj);
2375 }
2376
2377 /*************************************/
2378 /* Managed Argoutview Array Typemaps */
2379 /*************************************/
2380
2381 /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY1, DIM_TYPE* DIM1)
2382  */
2383 %typemap(in,numinputs=0)
2384   (DATA_TYPE** ARGOUTVIEWM_ARRAY1, DIM_TYPE* DIM1    )
2385   (DATA_TYPE*  data_temp = NULL  , DIM_TYPE  dim_temp)
2386 {
2387   $1 = &data_temp;
2388   $2 = &dim_temp;
2389 }
2390 %typemap(argout,
2391          fragment="NumPy_Backward_Compatibility")
2392   (DATA_TYPE** ARGOUTVIEWM_ARRAY1, DIM_TYPE* DIM1)
2393 {
2394   npy_intp dims[1] = { *$2 };
2395   PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$1));
2396   PyArrayObject* array = (PyArrayObject*) obj;
2397
2398   if (!array) SWIG_fail;
2399
2400 %#ifdef SWIGPY_USE_CAPSULE
2401     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2402 %#else
2403     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2404 %#endif
2405   
2406 %#if NPY_API_VERSION < 0x00000007
2407   PyArray_BASE(array) = cap;
2408 %#else
2409   PyArray_SetBaseObject(array,cap);
2410 %#endif
2411
2412   $result = SWIG_Python_AppendOutput($result,obj);
2413 }
2414
2415 /* Typemap suite for (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEWM_ARRAY1)
2416  */
2417 %typemap(in,numinputs=0)
2418   (DIM_TYPE* DIM1    , DATA_TYPE** ARGOUTVIEWM_ARRAY1)
2419   (DIM_TYPE  dim_temp, DATA_TYPE*  data_temp = NULL  )
2420 {
2421   $1 = &dim_temp;
2422   $2 = &data_temp;
2423 }
2424 %typemap(argout,
2425          fragment="NumPy_Backward_Compatibility")
2426   (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEWM_ARRAY1)
2427 {
2428   npy_intp dims[1] = { *$1 };
2429   PyObject* obj = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$2));
2430   PyArrayObject* array = (PyArrayObject*) obj;
2431
2432   if (!array) SWIG_fail;
2433
2434 %#ifdef SWIGPY_USE_CAPSULE
2435     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2436 %#else
2437     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2438 %#endif
2439   
2440 %#if NPY_API_VERSION < 0x00000007
2441   PyArray_BASE(array) = cap;
2442 %#else
2443   PyArray_SetBaseObject(array,cap);
2444 %#endif
2445
2446   $result = SWIG_Python_AppendOutput($result,obj);
2447 }
2448
2449 /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
2450  */
2451 %typemap(in,numinputs=0)
2452   (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
2453   (DATA_TYPE*  data_temp = NULL  , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
2454 {
2455   $1 = &data_temp;
2456   $2 = &dim1_temp;
2457   $3 = &dim2_temp;
2458 }
2459 %typemap(argout,
2460          fragment="NumPy_Backward_Compatibility")
2461   (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
2462 {
2463   npy_intp dims[2] = { *$2, *$3 };
2464   PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
2465   PyArrayObject* array = (PyArrayObject*) obj;
2466
2467   if (!array) SWIG_fail;
2468
2469 %#ifdef SWIGPY_USE_CAPSULE
2470     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2471 %#else
2472     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2473 %#endif
2474
2475 %#if NPY_API_VERSION < 0x00000007
2476   PyArray_BASE(array) = cap;
2477 %#else
2478   PyArray_SetBaseObject(array,cap);
2479 %#endif
2480
2481   $result = SWIG_Python_AppendOutput($result,obj);
2482 }
2483
2484 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_ARRAY2)
2485  */
2486 %typemap(in,numinputs=0)
2487   (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEWM_ARRAY2)
2488   (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp = NULL  )
2489 {
2490   $1 = &dim1_temp;
2491   $2 = &dim2_temp;
2492   $3 = &data_temp;
2493 }
2494 %typemap(argout,
2495          fragment="NumPy_Backward_Compatibility")
2496   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_ARRAY2)
2497 {
2498   npy_intp dims[2] = { *$1, *$2 };
2499   PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
2500   PyArrayObject* array = (PyArrayObject*) obj;
2501
2502   if (!array) SWIG_fail;
2503
2504 %#ifdef SWIGPY_USE_CAPSULE
2505     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2506 %#else
2507     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2508 %#endif
2509
2510 %#if NPY_API_VERSION < 0x00000007
2511   PyArray_BASE(array) = cap;
2512 %#else
2513   PyArray_SetBaseObject(array,cap);
2514 %#endif
2515
2516   $result = SWIG_Python_AppendOutput($result,obj);
2517 }
2518
2519 /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
2520  */
2521 %typemap(in,numinputs=0)
2522   (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1     , DIM_TYPE* DIM2     )
2523   (DATA_TYPE*  data_temp = NULL   , DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp)
2524 {
2525   $1 = &data_temp;
2526   $2 = &dim1_temp;
2527   $3 = &dim2_temp;
2528 }
2529 %typemap(argout,
2530          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2531   (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2)
2532 {
2533   npy_intp dims[2] = { *$2, *$3 };
2534   PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1));
2535   PyArrayObject* array = (PyArrayObject*) obj;
2536
2537   if (!array || !require_fortran(array)) SWIG_fail;
2538
2539 %#ifdef SWIGPY_USE_CAPSULE
2540     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2541 %#else
2542     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2543 %#endif
2544
2545 %#if NPY_API_VERSION < 0x00000007
2546   PyArray_BASE(array) = cap;
2547 %#else
2548   PyArray_SetBaseObject(array,cap);
2549 %#endif
2550
2551   $result = SWIG_Python_AppendOutput($result,obj);
2552 }
2553
2554 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_FARRAY2)
2555  */
2556 %typemap(in,numinputs=0)
2557   (DIM_TYPE* DIM1     , DIM_TYPE* DIM2     , DATA_TYPE** ARGOUTVIEWM_FARRAY2)
2558   (DIM_TYPE  dim1_temp, DIM_TYPE  dim2_temp, DATA_TYPE*  data_temp = NULL   )
2559 {
2560   $1 = &dim1_temp;
2561   $2 = &dim2_temp;
2562   $3 = &data_temp;
2563 }
2564 %typemap(argout,
2565          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2566   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_FARRAY2)
2567 {
2568   npy_intp dims[2] = { *$1, *$2 };
2569   PyObject* obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3));
2570   PyArrayObject* array = (PyArrayObject*) obj;
2571
2572   if (!array || !require_fortran(array)) SWIG_fail;
2573
2574 %#ifdef SWIGPY_USE_CAPSULE
2575     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2576 %#else
2577     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2578 %#endif
2579
2580 %#if NPY_API_VERSION < 0x00000007
2581   PyArray_BASE(array) = cap;
2582 %#else
2583   PyArray_SetBaseObject(array,cap);
2584 %#endif
2585
2586   $result = SWIG_Python_AppendOutput($result,obj);
2587 }
2588
2589 /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2590                       DIM_TYPE* DIM3)
2591  */
2592 %typemap(in,numinputs=0)
2593   (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    )
2594   (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
2595 {
2596   $1 = &data_temp;
2597   $2 = &dim1_temp;
2598   $3 = &dim2_temp;
2599   $4 = &dim3_temp;
2600 }
2601 %typemap(argout,
2602          fragment="NumPy_Backward_Compatibility")
2603   (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
2604 {
2605   npy_intp dims[3] = { *$2, *$3, *$4 };
2606   PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
2607   PyArrayObject* array = (PyArrayObject*) obj;
2608
2609   if (!array) SWIG_fail;
2610
2611 %#ifdef SWIGPY_USE_CAPSULE
2612     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2613 %#else
2614     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2615 %#endif
2616
2617 %#if NPY_API_VERSION < 0x00000007
2618   PyArray_BASE(array) = cap;
2619 %#else
2620   PyArray_SetBaseObject(array,cap);
2621 %#endif
2622
2623   $result = SWIG_Python_AppendOutput($result,obj);
2624 }
2625
2626 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3,
2627                       DATA_TYPE** ARGOUTVIEWM_ARRAY3)
2628  */
2629 %typemap(in,numinputs=0)
2630   (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DATA_TYPE** ARGOUTVIEWM_ARRAY3)
2631   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp = NULL   )
2632 {
2633   $1 = &dim1_temp;
2634   $2 = &dim2_temp;
2635   $3 = &dim3_temp;
2636   $4 = &data_temp;
2637 }
2638 %typemap(argout,
2639          fragment="NumPy_Backward_Compatibility")
2640   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_ARRAY3)
2641 {
2642   npy_intp dims[3] = { *$1, *$2, *$3 };
2643   PyObject* obj= PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4));
2644   PyArrayObject* array = (PyArrayObject*) obj;
2645
2646   if (!array) SWIG_fail;
2647
2648 %#ifdef SWIGPY_USE_CAPSULE
2649     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2650 %#else
2651     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2652 %#endif
2653
2654 %#if NPY_API_VERSION < 0x00000007
2655   PyArray_BASE(array) = cap;
2656 %#else
2657   PyArray_SetBaseObject(array,cap);
2658 %#endif
2659
2660   $result = SWIG_Python_AppendOutput($result,obj);
2661 }
2662
2663 /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2664                       DIM_TYPE* DIM3)
2665  */
2666 %typemap(in,numinputs=0)
2667   (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    )
2668   (DATA_TYPE* data_temp = NULL    , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp)
2669 {
2670   $1 = &data_temp;
2671   $2 = &dim1_temp;
2672   $3 = &dim2_temp;
2673   $4 = &dim3_temp;
2674 }
2675 %typemap(argout,
2676          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2677   (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
2678 {
2679   npy_intp dims[3] = { *$2, *$3, *$4 };
2680   PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1));
2681   PyArrayObject* array = (PyArrayObject*) obj;
2682
2683   if (!array || require_fortran(array)) SWIG_fail;
2684
2685 %#ifdef SWIGPY_USE_CAPSULE
2686     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2687 %#else
2688     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2689 %#endif
2690
2691 %#if NPY_API_VERSION < 0x00000007
2692   PyArray_BASE(array) = cap;
2693 %#else
2694   PyArray_SetBaseObject(array,cap);
2695 %#endif
2696
2697   $result = SWIG_Python_AppendOutput($result,obj);
2698 }
2699
2700 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3,
2701                       DATA_TYPE** ARGOUTVIEWM_FARRAY3)
2702  */
2703 %typemap(in,numinputs=0)
2704   (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DATA_TYPE** ARGOUTVIEWM_FARRAY3)
2705   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp = NULL    )
2706 {
2707   $1 = &dim1_temp;
2708   $2 = &dim2_temp;
2709   $3 = &dim3_temp;
2710   $4 = &data_temp;
2711 }
2712 %typemap(argout,
2713          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2714   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEWM_FARRAY3)
2715 {
2716   npy_intp dims[3] = { *$1, *$2, *$3 };
2717   PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$4));
2718   PyArrayObject* array = (PyArrayObject*) obj;
2719
2720   if (!array || require_fortran(array)) SWIG_fail;
2721
2722 %#ifdef SWIGPY_USE_CAPSULE
2723     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2724 %#else
2725     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2726 %#endif
2727
2728 %#if NPY_API_VERSION < 0x00000007
2729   PyArray_BASE(array) = cap;
2730 %#else
2731   PyArray_SetBaseObject(array,cap);
2732 %#endif
2733
2734   $result = SWIG_Python_AppendOutput($result,obj);
2735 }
2736
2737 /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2738                       DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2739  */
2740 %typemap(in,numinputs=0)
2741   (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
2742   (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
2743 {
2744   $1 = &data_temp;
2745   $2 = &dim1_temp;
2746   $3 = &dim2_temp;
2747   $4 = &dim3_temp;
2748   $5 = &dim4_temp;
2749 }
2750 %typemap(argout,
2751          fragment="NumPy_Backward_Compatibility")
2752   (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2753 {
2754   npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
2755   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
2756   PyArrayObject* array = (PyArrayObject*) obj;
2757
2758   if (!array) SWIG_fail;
2759
2760 %#ifdef SWIGPY_USE_CAPSULE
2761     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2762 %#else
2763     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2764 %#endif
2765
2766 %#if NPY_API_VERSION < 0x00000007
2767   PyArray_BASE(array) = cap;
2768 %#else
2769   PyArray_SetBaseObject(array,cap);
2770 %#endif
2771
2772   $result = SWIG_Python_AppendOutput($result,obj);
2773 }
2774
2775 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
2776                       DATA_TYPE** ARGOUTVIEWM_ARRAY4)
2777  */
2778 %typemap(in,numinputs=0)
2779   (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEWM_ARRAY4)
2780   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL   )
2781 {
2782   $1 = &dim1_temp;
2783   $2 = &dim2_temp;
2784   $3 = &dim3_temp;
2785   $4 = &dim4_temp;
2786   $5 = &data_temp;
2787 }
2788 %typemap(argout,
2789          fragment="NumPy_Backward_Compatibility")
2790   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_ARRAY4)
2791 {
2792   npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
2793   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
2794   PyArrayObject* array = (PyArrayObject*) obj;
2795
2796   if (!array) SWIG_fail;
2797
2798 %#ifdef SWIGPY_USE_CAPSULE
2799     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2800 %#else
2801     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2802 %#endif
2803
2804 %#if NPY_API_VERSION < 0x00000007
2805   PyArray_BASE(array) = cap;
2806 %#else
2807   PyArray_SetBaseObject(array,cap);
2808 %#endif
2809
2810   $result = SWIG_Python_AppendOutput($result,obj);
2811 }
2812
2813 /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2814                       DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2815  */
2816 %typemap(in,numinputs=0)
2817   (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
2818   (DATA_TYPE* data_temp = NULL    , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
2819 {
2820   $1 = &data_temp;
2821   $2 = &dim1_temp;
2822   $3 = &dim2_temp;
2823   $4 = &dim3_temp;
2824   $5 = &dim4_temp;
2825 }
2826 %typemap(argout,
2827          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2828   (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3)
2829 {
2830   npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
2831   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
2832   PyArrayObject* array = (PyArrayObject*) obj;
2833
2834   if (!array || require_fortran(array)) SWIG_fail;
2835
2836 %#ifdef SWIGPY_USE_CAPSULE
2837     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2838 %#else
2839     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2840 %#endif
2841
2842 %#if NPY_API_VERSION < 0x00000007
2843   PyArray_BASE(array) = cap;
2844 %#else
2845   PyArray_SetBaseObject(array,cap);
2846 %#endif
2847
2848   $result = SWIG_Python_AppendOutput($result,obj);
2849 }
2850
2851 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
2852                       DATA_TYPE** ARGOUTVIEWM_FARRAY4)
2853  */
2854 %typemap(in,numinputs=0)
2855   (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEWM_FARRAY4)
2856   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL    )
2857 {
2858   $1 = &dim1_temp;
2859   $2 = &dim2_temp;
2860   $3 = &dim3_temp;
2861   $4 = &dim4_temp;
2862   $5 = &data_temp;
2863 }
2864 %typemap(argout,
2865          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2866   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_FARRAY4)
2867 {
2868   npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
2869   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
2870   PyArrayObject* array = (PyArrayObject*) obj;
2871
2872   if (!array || require_fortran(array)) SWIG_fail;
2873
2874 %#ifdef SWIGPY_USE_CAPSULE
2875     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2876 %#else
2877     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2878 %#endif
2879
2880 %#if NPY_API_VERSION < 0x00000007
2881   PyArray_BASE(array) = cap;
2882 %#else
2883   PyArray_SetBaseObject(array,cap);
2884 %#endif
2885
2886   $result = SWIG_Python_AppendOutput($result,obj);
2887 }
2888
2889 /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2890                       DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2891  */
2892 %typemap(in,numinputs=0)
2893   (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
2894   (DATA_TYPE* data_temp = NULL   , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
2895 {
2896   $1 = &data_temp;
2897   $2 = &dim1_temp;
2898   $3 = &dim2_temp;
2899   $4 = &dim3_temp;
2900   $5 = &dim4_temp;
2901 }
2902 %typemap(argout,
2903          fragment="NumPy_Backward_Compatibility")
2904   (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2905 {
2906   npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
2907   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
2908   PyArrayObject* array = (PyArrayObject*) obj;
2909
2910   if (!array) SWIG_fail;
2911
2912 %#ifdef SWIGPY_USE_CAPSULE
2913     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2914 %#else
2915     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2916 %#endif
2917
2918 %#if NPY_API_VERSION < 0x00000007
2919   PyArray_BASE(array) = cap;
2920 %#else
2921   PyArray_SetBaseObject(array,cap);
2922 %#endif
2923
2924   $result = SWIG_Python_AppendOutput($result,obj);
2925 }
2926
2927 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
2928                       DATA_TYPE** ARGOUTVIEWM_ARRAY4)
2929  */
2930 %typemap(in,numinputs=0)
2931   (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEWM_ARRAY4)
2932   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL   )
2933 {
2934   $1 = &dim1_temp;
2935   $2 = &dim2_temp;
2936   $3 = &dim3_temp;
2937   $4 = &dim4_temp;
2938   $5 = &data_temp;
2939 }
2940 %typemap(argout,
2941          fragment="NumPy_Backward_Compatibility")
2942   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_ARRAY4)
2943 {
2944   npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
2945   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
2946   PyArrayObject* array = (PyArrayObject*) obj;
2947
2948   if (!array) SWIG_fail;
2949
2950 %#ifdef SWIGPY_USE_CAPSULE
2951     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2952 %#else
2953     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2954 %#endif
2955
2956 %#if NPY_API_VERSION < 0x00000007
2957   PyArray_BASE(array) = cap;
2958 %#else
2959   PyArray_SetBaseObject(array,cap);
2960 %#endif
2961
2962   $result = SWIG_Python_AppendOutput($result,obj);
2963 }
2964
2965 /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2,
2966                       DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2967  */
2968 %typemap(in,numinputs=0)
2969   (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    )
2970   (DATA_TYPE* data_temp = NULL    , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp)
2971 {
2972   $1 = &data_temp;
2973   $2 = &dim1_temp;
2974   $3 = &dim2_temp;
2975   $4 = &dim3_temp;
2976   $5 = &dim4_temp;
2977 }
2978 %typemap(argout,
2979          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
2980   (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4)
2981 {
2982   npy_intp dims[4] = { *$2, *$3, *$4 , *$5 };
2983   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$1));
2984   PyArrayObject* array = (PyArrayObject*) obj;
2985
2986   if (!array || require_fortran(array)) SWIG_fail;
2987
2988 %#ifdef SWIGPY_USE_CAPSULE
2989     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
2990 %#else
2991     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
2992 %#endif
2993
2994 %#if NPY_API_VERSION < 0x00000007
2995   PyArray_BASE(array) = cap;
2996 %#else
2997   PyArray_SetBaseObject(array,cap);
2998 %#endif
2999
3000   $result = SWIG_Python_AppendOutput($result,obj);
3001 }
3002
3003 /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4,
3004                       DATA_TYPE** ARGOUTVIEWM_FARRAY4)
3005  */
3006 %typemap(in,numinputs=0)
3007   (DIM_TYPE* DIM1    , DIM_TYPE* DIM2    , DIM_TYPE* DIM3    , DIM_TYPE* DIM4    , DATA_TYPE** ARGOUTVIEWM_FARRAY4)
3008   (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DIM_TYPE dim4_temp, DATA_TYPE* data_temp = NULL    )
3009 {
3010   $1 = &dim1_temp;
3011   $2 = &dim2_temp;
3012   $3 = &dim3_temp;
3013   $4 = &dim4_temp;
3014   $5 = &data_temp;
3015 }
3016 %typemap(argout,
3017          fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements")
3018   (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, DATA_TYPE** ARGOUTVIEWM_FARRAY4)
3019 {
3020   npy_intp dims[4] = { *$1, *$2, *$3 , *$4 };
3021   PyObject* obj = PyArray_SimpleNewFromData(4, dims, DATA_TYPECODE, (void*)(*$5));
3022   PyArrayObject* array = (PyArrayObject*) obj;
3023
3024   if (!array || require_fortran(array)) SWIG_fail;
3025
3026 %#ifdef SWIGPY_USE_CAPSULE
3027     PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, free_cap);
3028 %#else
3029     PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), free);
3030 %#endif
3031
3032 %#if NPY_API_VERSION < 0x00000007
3033   PyArray_BASE(array) = cap;
3034 %#else
3035   PyArray_SetBaseObject(array,cap);
3036 %#endif
3037
3038   $result = SWIG_Python_AppendOutput($result,obj);
3039 }
3040
3041 %enddef    /* %numpy_typemaps() macro */
3042 /* *************************************************************** */
3043
3044 /* Concrete instances of the %numpy_typemaps() macro: Each invocation
3045  * below applies all of the typemaps above to the specified data type.
3046  */
3047 %numpy_typemaps(signed char       , NPY_BYTE     , int)
3048 %numpy_typemaps(unsigned char     , NPY_UBYTE    , int)
3049 %numpy_typemaps(short             , NPY_SHORT    , int)
3050 %numpy_typemaps(unsigned short    , NPY_USHORT   , int)
3051 %numpy_typemaps(int               , NPY_INT      , int)
3052 %numpy_typemaps(unsigned int      , NPY_UINT     , int)
3053 %numpy_typemaps(long              , NPY_LONG     , int)
3054 %numpy_typemaps(unsigned long     , NPY_ULONG    , int)
3055 %numpy_typemaps(long long         , NPY_LONGLONG , int)
3056 %numpy_typemaps(unsigned long long, NPY_ULONGLONG, int)
3057 %numpy_typemaps(float             , NPY_FLOAT    , int)
3058 %numpy_typemaps(double            , NPY_DOUBLE   , int)
3059
3060 /* ***************************************************************
3061  * The follow macro expansion does not work, because C++ bool is 4
3062  * bytes and NPY_BOOL is 1 byte
3063  *
3064  *    %numpy_typemaps(bool, NPY_BOOL, int)
3065  */
3066
3067 /* ***************************************************************
3068  * On my Mac, I get the following warning for this macro expansion:
3069  * 'swig/python detected a memory leak of type 'long double *', no destructor found.'
3070  *
3071  *    %numpy_typemaps(long double, NPY_LONGDOUBLE, int)
3072  */
3073
3074 /* ***************************************************************
3075  * Swig complains about a syntax error for the following macro
3076  * expansions:
3077  *
3078  *    %numpy_typemaps(complex float,  NPY_CFLOAT , int)
3079  *
3080  *    %numpy_typemaps(complex double, NPY_CDOUBLE, int)
3081  *
3082  *    %numpy_typemaps(complex long double, NPY_CLONGDOUBLE, int)
3083  */
3084
3085 #endif /* SWIGPYTHON */