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