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