Debian Codegraph @

tools/swig/numpy.i

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