Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1745 lines
59KB

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