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