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 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774
|
/* Generated by Cython 0.15 on Tue Nov 1 18:19:53 2011 */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
#error Python headers needed to compile C extensions, please install development version of Python.
#else
#include <stddef.h> /* For offsetof */
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
#ifndef __stdcall
#define __stdcall
#endif
#ifndef __cdecl
#define __cdecl
#endif
#ifndef __fastcall
#define __fastcall
#endif
#endif
#ifndef DL_IMPORT
#define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
#define DL_EXPORT(t) t
#endif
#ifndef PY_LONG_LONG
#define PY_LONG_LONG LONG_LONG
#endif
#if PY_VERSION_HEX < 0x02040000
#define METH_COEXIST 0
#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
#define PyDict_Contains(d,o) PySequence_Contains(d,o)
#endif
#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#define PY_FORMAT_SIZE_T ""
#define PyInt_FromSsize_t(z) PyInt_FromLong(z)
#define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
#define PyNumber_Index(o) PyNumber_Int(o)
#define PyIndex_Check(o) PyNumber_Check(o)
#define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#endif
#if PY_VERSION_HEX < 0x02060000
#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
#define PyVarObject_HEAD_INIT(type, size) \
PyObject_HEAD_INIT(type) size,
#define PyType_Modified(t)
typedef struct {
void *buf;
PyObject *obj;
Py_ssize_t len;
Py_ssize_t itemsize;
int readonly;
int ndim;
char *format;
Py_ssize_t *shape;
Py_ssize_t *strides;
Py_ssize_t *suboffsets;
void *internal;
} Py_buffer;
#define PyBUF_SIMPLE 0
#define PyBUF_WRITABLE 0x0001
#define PyBUF_FORMAT 0x0004
#define PyBUF_ND 0x0008
#define PyBUF_STRIDES (0x0010 | PyBUF_ND)
#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
#endif
#if PY_MAJOR_VERSION < 3
#define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
#define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif
#if PY_MAJOR_VERSION >= 3
#define Py_TPFLAGS_CHECKTYPES 0
#define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_MAJOR_VERSION >= 3
#define PyBaseString_Type PyUnicode_Type
#define PyStringObject PyUnicodeObject
#define PyString_Type PyUnicode_Type
#define PyString_Check PyUnicode_Check
#define PyString_CheckExact PyUnicode_CheckExact
#endif
#if PY_VERSION_HEX < 0x02060000
#define PyBytesObject PyStringObject
#define PyBytes_Type PyString_Type
#define PyBytes_Check PyString_Check
#define PyBytes_CheckExact PyString_CheckExact
#define PyBytes_FromString PyString_FromString
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
#define PyBytes_FromFormat PyString_FromFormat
#define PyBytes_DecodeEscape PyString_DecodeEscape
#define PyBytes_AsString PyString_AsString
#define PyBytes_AsStringAndSize PyString_AsStringAndSize
#define PyBytes_Size PyString_Size
#define PyBytes_AS_STRING PyString_AS_STRING
#define PyBytes_GET_SIZE PyString_GET_SIZE
#define PyBytes_Repr PyString_Repr
#define PyBytes_Concat PyString_Concat
#define PyBytes_ConcatAndDel PyString_ConcatAndDel
#endif
#if PY_VERSION_HEX < 0x02060000
#define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
#define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#endif
#ifndef PySet_CheckExact
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
#define PyIntObject PyLongObject
#define PyInt_Type PyLong_Type
#define PyInt_Check(op) PyLong_Check(op)
#define PyInt_CheckExact(op) PyLong_CheckExact(op)
#define PyInt_FromString PyLong_FromString
#define PyInt_FromUnicode PyLong_FromUnicode
#define PyInt_FromLong PyLong_FromLong
#define PyInt_FromSize_t PyLong_FromSize_t
#define PyInt_FromSsize_t PyLong_FromSsize_t
#define PyInt_AsLong PyLong_AsLong
#define PyInt_AS_LONG PyLong_AS_LONG
#define PyInt_AsSsize_t PyLong_AsSsize_t
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#endif
#if PY_MAJOR_VERSION >= 3
#define PyBoolObject PyLongObject
#endif
#if PY_VERSION_HEX < 0x03020000
typedef long Py_hash_t;
#define __Pyx_PyInt_FromHash_t PyInt_FromLong
#define __Pyx_PyInt_AsHash_t PyInt_AsLong
#else
#define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
#define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
#else
#define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
#endif
#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
#define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
#define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
#define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
#define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
(PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
(likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
(PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
#define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
(PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
(likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
(PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
#define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
(PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
(likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
(PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif
#if PY_MAJOR_VERSION >= 3
#define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif
#if PY_VERSION_HEX < 0x02050000
#define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n)))
#define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
#define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n)))
#else
#define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))
#define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
#define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000
#define __Pyx_NAMESTR(n) ((char *)(n))
#define __Pyx_DOCSTR(n) ((char *)(n))
#else
#define __Pyx_NAMESTR(n) (n)
#define __Pyx_DOCSTR(n) (n)
#endif
#ifndef __PYX_EXTERN_C
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#endif
#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE__scipy__special__lambertw
#define __PYX_HAVE_API__scipy__special__lambertw
#include "math.h"
#include "numpy/npy_math.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */
#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif
/* inline attribute */
#ifndef CYTHON_INLINE
#if defined(__GNUC__)
#define CYTHON_INLINE __inline__
#elif defined(_MSC_VER)
#define CYTHON_INLINE __inline
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define CYTHON_INLINE inline
#else
#define CYTHON_INLINE
#endif
#endif
/* unused attribute */
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
# define CYTHON_UNUSED __attribute__ ((__unused__))
# else
# define CYTHON_UNUSED
# endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
# define CYTHON_UNUSED __attribute__ ((__unused__))
# else
# define CYTHON_UNUSED
# endif
#endif
typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
/* Type Conversion Predeclarations */
#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s))
#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x) (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x) (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
#if !defined(CYTHON_CCOMPLEX)
#if defined(__cplusplus)
#define CYTHON_CCOMPLEX 1
#elif defined(_Complex_I)
#define CYTHON_CCOMPLEX 1
#else
#define CYTHON_CCOMPLEX 0
#endif
#endif
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
#include <complex>
#else
#include <complex.h>
#endif
#endif
#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
#undef _Complex_I
#define _Complex_I 1.0fj
#endif
static const char *__pyx_f[] = {
"lambertw.pyx",
};
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
typedef ::std::complex< double > __pyx_t_double_complex;
#else
typedef double _Complex __pyx_t_double_complex;
#endif
#else
typedef struct { double real, imag; } __pyx_t_double_complex;
#endif
/*--- Type declarations ---*/
#ifndef CYTHON_REFNANNY
#define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
typedef struct {
void (*INCREF)(void*, PyObject*, int);
void (*DECREF)(void*, PyObject*, int);
void (*GOTREF)(void*, PyObject*, int);
void (*GIVEREF)(void*, PyObject*, int);
void* (*SetupContext)(const char*, int, const char*);
void (*FinishContext)(void**);
} __Pyx_RefNannyAPIStruct;
static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
#define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#define __Pyx_RefNannySetupContext(name) __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#define __Pyx_RefNannyFinishContext() __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
#define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
#define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
#define __Pyx_RefNannyDeclarations
#define __Pyx_RefNannySetupContext(name)
#define __Pyx_RefNannyFinishContext()
#define __Pyx_INCREF(r) Py_INCREF(r)
#define __Pyx_DECREF(r) Py_DECREF(r)
#define __Pyx_GOTREF(r)
#define __Pyx_GIVEREF(r)
#define __Pyx_XINCREF(r) Py_XINCREF(r)
#define __Pyx_XDECREF(r) Py_XDECREF(r)
#define __Pyx_XGOTREF(r)
#define __Pyx_XGIVEREF(r)
#endif /* CYTHON_REFNANNY */
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
#ifndef __PYX_FORCE_INIT_THREADS
#if PY_VERSION_HEX < 0x02040200
#define __PYX_FORCE_INIT_THREADS 1
#else
#define __PYX_FORCE_INIT_THREADS 0
#endif
#endif
static void __Pyx_RaiseDoubleKeywordsError(
const char* func_name, PyObject* kw_name); /*proto*/
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
#define __Pyx_CREAL(z) ((z).real())
#define __Pyx_CIMAG(z) ((z).imag())
#else
#define __Pyx_CREAL(z) (__real__(z))
#define __Pyx_CIMAG(z) (__imag__(z))
#endif
#else
#define __Pyx_CREAL(z) ((z).real)
#define __Pyx_CIMAG(z) ((z).imag)
#endif
#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX
#define __Pyx_SET_CREAL(z,x) ((z).real(x))
#define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
#define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
#define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif
static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);
#if CYTHON_CCOMPLEX
#define __Pyx_c_eq(a, b) ((a)==(b))
#define __Pyx_c_sum(a, b) ((a)+(b))
#define __Pyx_c_diff(a, b) ((a)-(b))
#define __Pyx_c_prod(a, b) ((a)*(b))
#define __Pyx_c_quot(a, b) ((a)/(b))
#define __Pyx_c_neg(a) (-(a))
#ifdef __cplusplus
#define __Pyx_c_is_zero(z) ((z)==(double)0)
#define __Pyx_c_conj(z) (::std::conj(z))
#if 1
#define __Pyx_c_abs(z) (::std::abs(z))
#define __Pyx_c_pow(a, b) (::std::pow(a, b))
#endif
#else
#define __Pyx_c_is_zero(z) ((z)==0)
#define __Pyx_c_conj(z) (conj(z))
#if 1
#define __Pyx_c_abs(z) (cabs(z))
#define __Pyx_c_pow(a, b) (cpow(a, b))
#endif
#endif
#else
static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex);
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex);
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex);
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex);
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex);
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex);
static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex);
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex);
#if 1
static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex);
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex, __pyx_t_double_complex);
#endif
#endif
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/
#define __pyx_PyComplex_FromComplex(z) \
PyComplex_FromDoubles((double)__Pyx_CREAL(z), \
(double)__Pyx_CIMAG(z))
static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_intp(npy_intp);
static CYTHON_INLINE npy_intp __Pyx_PyInt_from_py_npy_intp(PyObject *);
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);
static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);
static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);
static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);
static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);
static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);
static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);
static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
static void __Pyx_WriteUnraisable(const char *name, int clineno,
int lineno, const char *filename); /*proto*/
static int __Pyx_check_binary_version(void);
static void __Pyx_AddTraceback(const char *funcname, int __pyx_clineno,
int __pyx_lineno, const char *__pyx_filename); /*proto*/
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from 'cython.cython.view' */
/* Module declarations from 'cython' */
/* Module declarations from 'scipy.special.lambertw' */
static PyUFuncGenericFunction __pyx_v_5scipy_7special_8lambertw__loop_funcs[1];
static char __pyx_v_5scipy_7special_8lambertw__inp_outp_types[4];
static void *__pyx_v_5scipy_7special_8lambertw_the_func_to_apply[1];
static CYTHON_INLINE int __pyx_f_5scipy_7special_8lambertw_zisnan(__pyx_t_double_complex); /*proto*/
static CYTHON_INLINE double __pyx_f_5scipy_7special_8lambertw_zabs(__pyx_t_double_complex); /*proto*/
static CYTHON_INLINE __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_zlog(__pyx_t_double_complex); /*proto*/
static CYTHON_INLINE __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_zexp(__pyx_t_double_complex); /*proto*/
static void __pyx_f_5scipy_7special_8lambertw_lambertw_raise_warning(__pyx_t_double_complex); /*proto*/
static __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_lambertw_scalar(__pyx_t_double_complex, long, double); /*proto*/
static void __pyx_f_5scipy_7special_8lambertw__apply_func_to_1d_vec(char **, npy_intp *, npy_intp *, void *); /*proto*/
#define __Pyx_MODULE_NAME "scipy.special.lambertw"
int __pyx_module_is_main_scipy__special__lambertw = 0;
/* Implementation of 'scipy.special.lambertw' */
static PyObject *__pyx_builtin_range;
static char __pyx_k_1[] = "Lambert W iteration failed to converge: %r";
static char __pyx_k_3[] = "";
static char __pyx_k_4[] = "scipy.special.lambertw";
static char __pyx_k_5[] = "lambertw (line 193)";
static char __pyx_k_6[] = "\n lambertw(z, k=0, tol=1e-8)\n\n Lambert W function.\n\n The Lambert W function `W(z)` is defined as the inverse function\n of :math:`w \\exp(w)`. In other words, the value of :math:`W(z)` is\n such that :math:`z = W(z) \\exp(W(z))` for any complex number\n :math:`z`.\n\n The Lambert W function is a multivalued function with infinitely\n many branches. Each branch gives a separate solution of the\n equation :math:`w \\exp(w)`. Here, the branches are indexed by the\n integer `k`.\n \n Parameters\n ----------\n z : array_like\n Input argument\n k : integer, optional\n Branch index\n tol : float\n Evaluation tolerance\n\n Notes\n -----\n All branches are supported by `lambertw`:\n\n * ``lambertw(z)`` gives the principal solution (branch 0)\n * ``lambertw(z, k)`` gives the solution on branch `k`\n\n The Lambert W function has two partially real branches: the\n principal branch (`k = 0`) is real for real `z > -1/e`, and the\n `k = -1` branch is real for `-1/e < z < 0`. All branches except\n `k = 0` have a logarithmic singularity at `z = 0`.\n\n .. rubric:: Possible issues\n \n The evaluation can become inaccurate very close to the branch point\n at `-1/e`. In some corner cases, :func:`lambertw` might currently\n fail to converge, or can end up on the wrong branch.\n\n .. rubric:: Algorithm\n\n Halley's iteration is used to invert `w \\exp(w)`, using a first-order\n asymptotic approximation (`O(\\log(w))` or `O(w)`) as the initial\n estimate.\n\n The definition, implementation and choice of branches is based\n on Corless et al, \"On the Lambert W function\", Adv. Comp. Math. 5\n (1996) 329-359, available online here:\n http://www.apmaths.uwo.ca/~djeffrey/Offprints/W-adv-cm.pdf\n \n TODO: use a series expansion when extremely close to the branch point\n at `-1/e` and make sure that the proper branch is chosen there\n\n Examples""\n --------\n The Lambert W function is the inverse of `w \\exp(w)`::\n\n >>> from scipy.special import lambertw\n >>> w = lambertw(1)\n >>> w\n 0.56714329040978387299996866221035555\n >>> w*exp(w)\n 1.0\n\n Any branch gives a valid inverse::\n\n >>> w = lambertw(1, k=3)\n >>> w\n (-2.8535817554090378072068187234910812 +\n 17.113535539412145912607826671159289j)\n >>> w*exp(w)\n (1.0 + 3.5075477124212226194278700785075126e-36j)\n\n .. rubric:: Applications to equation-solving\n\n The Lambert W function may be used to solve various kinds of\n equations, such as finding the value of the infinite power\n tower `z^{z^{z^{\\ldots}}}`::\n\n >>> def tower(z, n):\n ... if n == 0:\n ... return z\n ... return z ** tower(z, n-1)\n ...\n >>> tower(0.5, 100)\n 0.641185744504986\n >>> -lambertw(-log(0.5))/log(0.5)\n 0.6411857445049859844862004821148236665628209571911\n\n .. rubric:: Properties\n\n The Lambert W function grows roughly like the natural logarithm\n for large arguments::\n\n >>> lambertw(1000)\n 5.2496028524016\n >>> log(1000)\n 6.90775527898214\n >>> lambertw(10**100)\n 224.843106445119\n >>> log(10**100)\n 230.258509299405\n \n The principal branch of the Lambert W function has a rational\n Taylor series expansion around `z = 0`::\n \n >>> nprint(taylor(lambertw, 0, 6), 10)\n [0.0, 1.0, -1.0, 1.5, -2.666666667, 5.208333333, -10.8]\n \n Some special values and limits are::\n \n >>> lambertw(0)\n 0.0\n >>> lambertw(1)\n 0.567143290409784\n >>> lambertw(e)\n 1.0\n >>> lambertw(inf)\n +inf\n >>> lambertw(0, k=-1)\n -inf\n >>> lambertw(0, k=3)\n -inf\n >>> lambertw(inf, k=3)\n (+inf + 18.8495559215388j)\n\n The `k = 0` and `k = -1` branches join at `z = -1/e` where\n `W(z) = -1` for both branches. Since `-1/e` can only be represented\n approximately with mpmath numbers, evaluatin""g the Lambert W function\n at this point only gives `-1` approximately::\n\n >>> lambertw(-1/e, 0)\n -0.999999999999837133022867\n >>> lambertw(-1/e, -1)\n -1.00000000000016286697718\n \n If `-1/e` happens to round in the negative direction, there might be\n a small imaginary part::\n \n >>> lambertw(-1/e)\n (-1.0 + 8.22007971511612e-9j)\n\n ";
static char __pyx_k__k[] = "k";
static char __pyx_k__z[] = "z";
static char __pyx_k__tol[] = "tol";
static char __pyx_k__warn[] = "warn";
static char __pyx_k__range[] = "range";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__lambertw[] = "lambertw";
static char __pyx_k__warnings[] = "warnings";
static char __pyx_k___lambertw[] = "_lambertw";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_n_s_4;
static PyObject *__pyx_kp_u_5;
static PyObject *__pyx_kp_u_6;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s___lambertw;
static PyObject *__pyx_n_s__k;
static PyObject *__pyx_n_s__lambertw;
static PyObject *__pyx_n_s__range;
static PyObject *__pyx_n_s__tol;
static PyObject *__pyx_n_s__warn;
static PyObject *__pyx_n_s__warnings;
static PyObject *__pyx_n_s__z;
static PyObject *__pyx_int_0;
static PyObject *__pyx_k_2;
/* "scipy/special/lambertw.pyx":44
* double NPY_PI
*
* cdef inline bint zisnan(double complex x) nogil: # <<<<<<<<<<<<<<
* return npy_isnan(x.real) or npy_isnan(x.imag)
*
*/
static CYTHON_INLINE int __pyx_f_5scipy_7special_8lambertw_zisnan(__pyx_t_double_complex __pyx_v_x) {
int __pyx_r;
int __pyx_t_1;
int __pyx_t_2;
int __pyx_t_3;
/* "scipy/special/lambertw.pyx":45
*
* cdef inline bint zisnan(double complex x) nogil:
* return npy_isnan(x.real) or npy_isnan(x.imag) # <<<<<<<<<<<<<<
*
* cdef inline double zabs(double complex x) nogil:
*/
__pyx_t_1 = npy_isnan(__Pyx_CREAL(__pyx_v_x));
if (!__pyx_t_1) {
__pyx_t_2 = npy_isnan(__Pyx_CIMAG(__pyx_v_x));
__pyx_t_3 = __pyx_t_2;
} else {
__pyx_t_3 = __pyx_t_1;
}
__pyx_r = __pyx_t_3;
goto __pyx_L0;
__pyx_r = 0;
__pyx_L0:;
return __pyx_r;
}
/* "scipy/special/lambertw.pyx":47
* return npy_isnan(x.real) or npy_isnan(x.imag)
*
* cdef inline double zabs(double complex x) nogil: # <<<<<<<<<<<<<<
* cdef double r
* r = npy_cabs((<npy_cdouble*>&x)[0])
*/
static CYTHON_INLINE double __pyx_f_5scipy_7special_8lambertw_zabs(__pyx_t_double_complex __pyx_v_x) {
double __pyx_v_r;
double __pyx_r;
/* "scipy/special/lambertw.pyx":49
* cdef inline double zabs(double complex x) nogil:
* cdef double r
* r = npy_cabs((<npy_cdouble*>&x)[0]) # <<<<<<<<<<<<<<
* return r
*
*/
__pyx_v_r = npy_cabs((((npy_cdouble *)(&__pyx_v_x))[0]));
/* "scipy/special/lambertw.pyx":50
* cdef double r
* r = npy_cabs((<npy_cdouble*>&x)[0])
* return r # <<<<<<<<<<<<<<
*
* cdef inline double complex zlog(double complex x) nogil:
*/
__pyx_r = __pyx_v_r;
goto __pyx_L0;
__pyx_r = 0;
__pyx_L0:;
return __pyx_r;
}
/* "scipy/special/lambertw.pyx":52
* return r
*
* cdef inline double complex zlog(double complex x) nogil: # <<<<<<<<<<<<<<
* cdef npy_cdouble r
* r = npy_clog((<npy_cdouble*>&x)[0])
*/
static CYTHON_INLINE __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_zlog(__pyx_t_double_complex __pyx_v_x) {
npy_cdouble __pyx_v_r;
__pyx_t_double_complex __pyx_r;
/* "scipy/special/lambertw.pyx":54
* cdef inline double complex zlog(double complex x) nogil:
* cdef npy_cdouble r
* r = npy_clog((<npy_cdouble*>&x)[0]) # <<<<<<<<<<<<<<
* return (<double complex*>&r)[0]
*
*/
__pyx_v_r = npy_clog((((npy_cdouble *)(&__pyx_v_x))[0]));
/* "scipy/special/lambertw.pyx":55
* cdef npy_cdouble r
* r = npy_clog((<npy_cdouble*>&x)[0])
* return (<double complex*>&r)[0] # <<<<<<<<<<<<<<
*
* cdef inline double complex zexp(double complex x) nogil:
*/
__pyx_r = (((__pyx_t_double_complex *)(&__pyx_v_r))[0]);
goto __pyx_L0;
__pyx_r = __pyx_t_double_complex_from_parts(0, 0);
__pyx_L0:;
return __pyx_r;
}
/* "scipy/special/lambertw.pyx":57
* return (<double complex*>&r)[0]
*
* cdef inline double complex zexp(double complex x) nogil: # <<<<<<<<<<<<<<
* cdef npy_cdouble r
* r = npy_cexp((<npy_cdouble*>&x)[0])
*/
static CYTHON_INLINE __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_zexp(__pyx_t_double_complex __pyx_v_x) {
npy_cdouble __pyx_v_r;
__pyx_t_double_complex __pyx_r;
/* "scipy/special/lambertw.pyx":59
* cdef inline double complex zexp(double complex x) nogil:
* cdef npy_cdouble r
* r = npy_cexp((<npy_cdouble*>&x)[0]) # <<<<<<<<<<<<<<
* return (<double complex*>&r)[0]
*
*/
__pyx_v_r = npy_cexp((((npy_cdouble *)(&__pyx_v_x))[0]));
/* "scipy/special/lambertw.pyx":60
* cdef npy_cdouble r
* r = npy_cexp((<npy_cdouble*>&x)[0])
* return (<double complex*>&r)[0] # <<<<<<<<<<<<<<
*
* cdef void lambertw_raise_warning(double complex z) with gil:
*/
__pyx_r = (((__pyx_t_double_complex *)(&__pyx_v_r))[0]);
goto __pyx_L0;
__pyx_r = __pyx_t_double_complex_from_parts(0, 0);
__pyx_L0:;
return __pyx_r;
}
/* "scipy/special/lambertw.pyx":62
* return (<double complex*>&r)[0]
*
* cdef void lambertw_raise_warning(double complex z) with gil: # <<<<<<<<<<<<<<
* warnings.warn("Lambert W iteration failed to converge: %r" % z)
*
*/
static void __pyx_f_5scipy_7special_8lambertw_lambertw_raise_warning(__pyx_t_double_complex __pyx_v_z) {
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
#ifdef WITH_THREAD
PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
#endif
__Pyx_RefNannySetupContext("lambertw_raise_warning");
/* "scipy/special/lambertw.pyx":63
*
* cdef void lambertw_raise_warning(double complex z) with gil:
* warnings.warn("Lambert W iteration failed to converge: %r" % z) # <<<<<<<<<<<<<<
*
* # Heavy lifting is here:
*/
__pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__warnings); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__warn); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __pyx_PyComplex_FromComplex(__pyx_v_z); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
__pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_3));
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
__pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3));
__Pyx_GIVEREF(((PyObject *)__pyx_t_3));
__pyx_t_3 = 0;
__pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_WriteUnraisable("scipy.special.lambertw.lambertw_raise_warning", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_L0:;
__Pyx_RefNannyFinishContext();
#ifdef WITH_THREAD
PyGILState_Release(__pyx_gilstate_save);
#endif
}
/* "scipy/special/lambertw.pyx":68
*
* @cython.cdivision(True)
* cdef double complex lambertw_scalar(double complex z, long k, double tol) nogil: # <<<<<<<<<<<<<<
* """
* This is just the implementation of W for a single input z.
*/
static __pyx_t_double_complex __pyx_f_5scipy_7special_8lambertw_lambertw_scalar(__pyx_t_double_complex __pyx_v_z, long __pyx_v_k, double __pyx_v_tol) {
__pyx_t_double_complex __pyx_v_w;
double __pyx_v_u;
double __pyx_v_absz;
__pyx_t_double_complex __pyx_v_ew;
__pyx_t_double_complex __pyx_v_wew;
__pyx_t_double_complex __pyx_v_wewz;
__pyx_t_double_complex __pyx_v_wn;
int __pyx_v_i;
__pyx_t_double_complex __pyx_r;
int __pyx_t_1;
int __pyx_t_2;
int __pyx_t_3;
int __pyx_t_4;
int __pyx_t_5;
/* "scipy/special/lambertw.pyx":74
* """
* # Comments copied verbatim from [2] are marked with '>'
* if zisnan(z): # <<<<<<<<<<<<<<
* return z
*
*/
__pyx_t_1 = __pyx_f_5scipy_7special_8lambertw_zisnan(__pyx_v_z);
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":75
* # Comments copied verbatim from [2] are marked with '>'
* if zisnan(z):
* return z # <<<<<<<<<<<<<<
*
* # Return value:
*/
__pyx_r = __pyx_v_z;
goto __pyx_L0;
goto __pyx_L3;
}
__pyx_L3:;
/* "scipy/special/lambertw.pyx":82
* #> We must be extremely careful near the singularities at -1/e and 0
* cdef double u
* u = exp(-1) # <<<<<<<<<<<<<<
*
* cdef double absz
*/
__pyx_v_u = exp(-1.0);
/* "scipy/special/lambertw.pyx":85
*
* cdef double absz
* absz = zabs(z) # <<<<<<<<<<<<<<
* if absz <= u:
* if z == 0:
*/
__pyx_v_absz = __pyx_f_5scipy_7special_8lambertw_zabs(__pyx_v_z);
/* "scipy/special/lambertw.pyx":86
* cdef double absz
* absz = zabs(z)
* if absz <= u: # <<<<<<<<<<<<<<
* if z == 0:
* #> w(0,0) = 0; for all other branches we hit the pole
*/
__pyx_t_1 = (__pyx_v_absz <= __pyx_v_u);
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":87
* absz = zabs(z)
* if absz <= u:
* if z == 0: # <<<<<<<<<<<<<<
* #> w(0,0) = 0; for all other branches we hit the pole
* if k == 0:
*/
__pyx_t_1 = (__Pyx_c_eq(__pyx_v_z, __pyx_t_double_complex_from_parts(0, 0)));
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":89
* if z == 0:
* #> w(0,0) = 0; for all other branches we hit the pole
* if k == 0: # <<<<<<<<<<<<<<
* return z
* return -NPY_INFINITY
*/
__pyx_t_1 = (__pyx_v_k == 0);
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":90
* #> w(0,0) = 0; for all other branches we hit the pole
* if k == 0:
* return z # <<<<<<<<<<<<<<
* return -NPY_INFINITY
*
*/
__pyx_r = __pyx_v_z;
goto __pyx_L0;
goto __pyx_L6;
}
__pyx_L6:;
/* "scipy/special/lambertw.pyx":91
* if k == 0:
* return z
* return -NPY_INFINITY # <<<<<<<<<<<<<<
*
* if k == 0:
*/
__pyx_r = __pyx_t_double_complex_from_parts((-NPY_INFINITY), 0);
goto __pyx_L0;
goto __pyx_L5;
}
__pyx_L5:;
/* "scipy/special/lambertw.pyx":93
* return -NPY_INFINITY
*
* if k == 0: # <<<<<<<<<<<<<<
* w = z # Initial guess for iteration
* #> For small real z < 0, the -1 branch beaves roughly like log(-z)
*/
__pyx_t_1 = (__pyx_v_k == 0);
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":94
*
* if k == 0:
* w = z # Initial guess for iteration # <<<<<<<<<<<<<<
* #> For small real z < 0, the -1 branch beaves roughly like log(-z)
* elif k == -1 and z.imag ==0 and z.real < 0:
*/
__pyx_v_w = __pyx_v_z;
goto __pyx_L7;
}
/* "scipy/special/lambertw.pyx":96
* w = z # Initial guess for iteration
* #> For small real z < 0, the -1 branch beaves roughly like log(-z)
* elif k == -1 and z.imag ==0 and z.real < 0: # <<<<<<<<<<<<<<
* w = log(-z.real)
* #> Use a simple asymptotic approximation.
*/
__pyx_t_1 = (__pyx_v_k == -1);
if (__pyx_t_1) {
__pyx_t_2 = (__Pyx_CIMAG(__pyx_v_z) == 0.0);
if (__pyx_t_2) {
__pyx_t_3 = (__Pyx_CREAL(__pyx_v_z) < 0.0);
__pyx_t_4 = __pyx_t_3;
} else {
__pyx_t_4 = __pyx_t_2;
}
__pyx_t_2 = __pyx_t_4;
} else {
__pyx_t_2 = __pyx_t_1;
}
if (__pyx_t_2) {
/* "scipy/special/lambertw.pyx":97
* #> For small real z < 0, the -1 branch beaves roughly like log(-z)
* elif k == -1 and z.imag ==0 and z.real < 0:
* w = log(-z.real) # <<<<<<<<<<<<<<
* #> Use a simple asymptotic approximation.
* else:
*/
__pyx_v_w = __pyx_t_double_complex_from_parts(log((-__Pyx_CREAL(__pyx_v_z))), 0);
goto __pyx_L7;
}
/*else*/ {
/* "scipy/special/lambertw.pyx":100
* #> Use a simple asymptotic approximation.
* else:
* w = zlog(z) # <<<<<<<<<<<<<<
* #> The branches are roughly logarithmic. This approximation
* #> gets better for large |k|; need to check that this always
*/
__pyx_v_w = __pyx_f_5scipy_7special_8lambertw_zlog(__pyx_v_z);
/* "scipy/special/lambertw.pyx":104
* #> gets better for large |k|; need to check that this always
* #> works for k ~= -1, 0, 1.
* if k: w = w + k*2*NPY_PI*1j # <<<<<<<<<<<<<<
*
* elif k == 0 and z.imag and zabs(z) <= 0.7:
*/
if (__pyx_v_k) {
__pyx_v_w = __Pyx_c_sum(__pyx_v_w, __Pyx_c_prod(__pyx_t_double_complex_from_parts(((__pyx_v_k * 2) * NPY_PI), 0), __pyx_t_double_complex_from_parts(0, 1.0)));
goto __pyx_L8;
}
__pyx_L8:;
}
__pyx_L7:;
goto __pyx_L4;
}
/* "scipy/special/lambertw.pyx":106
* if k: w = w + k*2*NPY_PI*1j
*
* elif k == 0 and z.imag and zabs(z) <= 0.7: # <<<<<<<<<<<<<<
* #> Both the W(z) ~= z and W(z) ~= ln(z) approximations break
* #> down around z ~= -0.5 (converging to the wrong branch), so patch
*/
__pyx_t_2 = (__pyx_v_k == 0);
if (__pyx_t_2) {
if ((__Pyx_CIMAG(__pyx_v_z) != 0)) {
__pyx_t_1 = (__pyx_f_5scipy_7special_8lambertw_zabs(__pyx_v_z) <= 0.7);
__pyx_t_4 = __pyx_t_1;
} else {
__pyx_t_4 = (__Pyx_CIMAG(__pyx_v_z) != 0);
}
__pyx_t_1 = __pyx_t_4;
} else {
__pyx_t_1 = __pyx_t_2;
}
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":110
* #> down around z ~= -0.5 (converging to the wrong branch), so patch
* #> with a constant approximation (adjusted for sign)
* if zabs(z+0.5) < 0.1: # <<<<<<<<<<<<<<
* if z.imag > 0:
* w = 0.7 + 0.7j
*/
__pyx_t_1 = (__pyx_f_5scipy_7special_8lambertw_zabs(__Pyx_c_sum(__pyx_v_z, __pyx_t_double_complex_from_parts(0.5, 0))) < 0.1);
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":111
* #> with a constant approximation (adjusted for sign)
* if zabs(z+0.5) < 0.1:
* if z.imag > 0: # <<<<<<<<<<<<<<
* w = 0.7 + 0.7j
* else:
*/
__pyx_t_1 = (__Pyx_CIMAG(__pyx_v_z) > 0.0);
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":112
* if zabs(z+0.5) < 0.1:
* if z.imag > 0:
* w = 0.7 + 0.7j # <<<<<<<<<<<<<<
* else:
* w = 0.7 - 0.7j
*/
__pyx_v_w = __Pyx_c_sum(__pyx_t_double_complex_from_parts(0.7, 0), __pyx_t_double_complex_from_parts(0, 0.69999999999999996));
goto __pyx_L10;
}
/*else*/ {
/* "scipy/special/lambertw.pyx":114
* w = 0.7 + 0.7j
* else:
* w = 0.7 - 0.7j # <<<<<<<<<<<<<<
* else:
* w = z
*/
__pyx_v_w = __Pyx_c_diff(__pyx_t_double_complex_from_parts(0.7, 0), __pyx_t_double_complex_from_parts(0, 0.69999999999999996));
}
__pyx_L10:;
goto __pyx_L9;
}
/*else*/ {
/* "scipy/special/lambertw.pyx":116
* w = 0.7 - 0.7j
* else:
* w = z # <<<<<<<<<<<<<<
*
* else:
*/
__pyx_v_w = __pyx_v_z;
}
__pyx_L9:;
goto __pyx_L4;
}
/*else*/ {
/* "scipy/special/lambertw.pyx":119
*
* else:
* if z.real == NPY_INFINITY: # <<<<<<<<<<<<<<
* if k == 0:
* return z
*/
__pyx_t_1 = (__Pyx_CREAL(__pyx_v_z) == NPY_INFINITY);
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":120
* else:
* if z.real == NPY_INFINITY:
* if k == 0: # <<<<<<<<<<<<<<
* return z
* else:
*/
__pyx_t_1 = (__pyx_v_k == 0);
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":121
* if z.real == NPY_INFINITY:
* if k == 0:
* return z # <<<<<<<<<<<<<<
* else:
* return z + 2*k*NPY_PI*1j
*/
__pyx_r = __pyx_v_z;
goto __pyx_L0;
goto __pyx_L12;
}
/*else*/ {
/* "scipy/special/lambertw.pyx":123
* return z
* else:
* return z + 2*k*NPY_PI*1j # <<<<<<<<<<<<<<
*
* if z.real == -NPY_INFINITY:
*/
__pyx_r = __Pyx_c_sum(__pyx_v_z, __Pyx_c_prod(__pyx_t_double_complex_from_parts(((2 * __pyx_v_k) * NPY_PI), 0), __pyx_t_double_complex_from_parts(0, 1.0)));
goto __pyx_L0;
}
__pyx_L12:;
goto __pyx_L11;
}
__pyx_L11:;
/* "scipy/special/lambertw.pyx":125
* return z + 2*k*NPY_PI*1j
*
* if z.real == -NPY_INFINITY: # <<<<<<<<<<<<<<
* return (-z) + (2*k+1)*NPY_PI*1j
*
*/
__pyx_t_1 = (__Pyx_CREAL(__pyx_v_z) == (-NPY_INFINITY));
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":126
*
* if z.real == -NPY_INFINITY:
* return (-z) + (2*k+1)*NPY_PI*1j # <<<<<<<<<<<<<<
*
* #> Simple asymptotic approximation as above
*/
__pyx_r = __Pyx_c_sum(__Pyx_c_neg(__pyx_v_z), __Pyx_c_prod(__pyx_t_double_complex_from_parts((((2 * __pyx_v_k) + 1) * NPY_PI), 0), __pyx_t_double_complex_from_parts(0, 1.0)));
goto __pyx_L0;
goto __pyx_L13;
}
__pyx_L13:;
/* "scipy/special/lambertw.pyx":129
*
* #> Simple asymptotic approximation as above
* w = zlog(z) # <<<<<<<<<<<<<<
* if k: w = w + k*2*NPY_PI*1j
*
*/
__pyx_v_w = __pyx_f_5scipy_7special_8lambertw_zlog(__pyx_v_z);
/* "scipy/special/lambertw.pyx":130
* #> Simple asymptotic approximation as above
* w = zlog(z)
* if k: w = w + k*2*NPY_PI*1j # <<<<<<<<<<<<<<
*
* #> Use Halley iteration to solve w*exp(w) = z
*/
if (__pyx_v_k) {
__pyx_v_w = __Pyx_c_sum(__pyx_v_w, __Pyx_c_prod(__pyx_t_double_complex_from_parts(((__pyx_v_k * 2) * NPY_PI), 0), __pyx_t_double_complex_from_parts(0, 1.0)));
goto __pyx_L14;
}
__pyx_L14:;
}
__pyx_L4:;
/* "scipy/special/lambertw.pyx":135
* cdef double complex ew, wew, wewz, wn
* cdef int i
* for i in range(100): # <<<<<<<<<<<<<<
* ew = zexp(w)
* wew = w*ew
*/
for (__pyx_t_5 = 0; __pyx_t_5 < 100; __pyx_t_5+=1) {
__pyx_v_i = __pyx_t_5;
/* "scipy/special/lambertw.pyx":136
* cdef int i
* for i in range(100):
* ew = zexp(w) # <<<<<<<<<<<<<<
* wew = w*ew
* wewz = wew-z
*/
__pyx_v_ew = __pyx_f_5scipy_7special_8lambertw_zexp(__pyx_v_w);
/* "scipy/special/lambertw.pyx":137
* for i in range(100):
* ew = zexp(w)
* wew = w*ew # <<<<<<<<<<<<<<
* wewz = wew-z
* wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2))
*/
__pyx_v_wew = __Pyx_c_prod(__pyx_v_w, __pyx_v_ew);
/* "scipy/special/lambertw.pyx":138
* ew = zexp(w)
* wew = w*ew
* wewz = wew-z # <<<<<<<<<<<<<<
* wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2))
* if zabs(wn-w) < tol*zabs(wn):
*/
__pyx_v_wewz = __Pyx_c_diff(__pyx_v_wew, __pyx_v_z);
/* "scipy/special/lambertw.pyx":139
* wew = w*ew
* wewz = wew-z
* wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2)) # <<<<<<<<<<<<<<
* if zabs(wn-w) < tol*zabs(wn):
* return wn
*/
__pyx_v_wn = __Pyx_c_diff(__pyx_v_w, __Pyx_c_quot(__pyx_v_wewz, __Pyx_c_diff(__Pyx_c_sum(__pyx_v_wew, __pyx_v_ew), __Pyx_c_quot(__Pyx_c_prod(__Pyx_c_sum(__pyx_v_w, __pyx_t_double_complex_from_parts(2, 0)), __pyx_v_wewz), __Pyx_c_sum(__Pyx_c_prod(__pyx_t_double_complex_from_parts(2, 0), __pyx_v_w), __pyx_t_double_complex_from_parts(2, 0))))));
/* "scipy/special/lambertw.pyx":140
* wewz = wew-z
* wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2))
* if zabs(wn-w) < tol*zabs(wn): # <<<<<<<<<<<<<<
* return wn
* else:
*/
__pyx_t_1 = (__pyx_f_5scipy_7special_8lambertw_zabs(__Pyx_c_diff(__pyx_v_wn, __pyx_v_w)) < (__pyx_v_tol * __pyx_f_5scipy_7special_8lambertw_zabs(__pyx_v_wn)));
if (__pyx_t_1) {
/* "scipy/special/lambertw.pyx":141
* wn = w - wewz / (wew + ew - (w + 2)*wewz/(2*w + 2))
* if zabs(wn-w) < tol*zabs(wn):
* return wn # <<<<<<<<<<<<<<
* else:
* w = wn
*/
__pyx_r = __pyx_v_wn;
goto __pyx_L0;
goto __pyx_L17;
}
/*else*/ {
/* "scipy/special/lambertw.pyx":143
* return wn
* else:
* w = wn # <<<<<<<<<<<<<<
*
* lambertw_raise_warning(z)
*/
__pyx_v_w = __pyx_v_wn;
}
__pyx_L17:;
}
/* "scipy/special/lambertw.pyx":145
* w = wn
*
* lambertw_raise_warning(z) # <<<<<<<<<<<<<<
* return wn
*
*/
__pyx_f_5scipy_7special_8lambertw_lambertw_raise_warning(__pyx_v_z);
/* "scipy/special/lambertw.pyx":146
*
* lambertw_raise_warning(z)
* return wn # <<<<<<<<<<<<<<
*
*
*/
__pyx_r = __pyx_v_wn;
goto __pyx_L0;
__pyx_r = __pyx_t_double_complex_from_parts(0, 0);
__pyx_L0:;
return __pyx_r;
}
/* "scipy/special/lambertw.pyx":166
* int identity, char* name, char* doc, int c)
*
* cdef void _apply_func_to_1d_vec(char **args, npy_intp *dimensions, npy_intp *steps, # <<<<<<<<<<<<<<
* void *func) nogil:
* cdef npy_intp i
*/
static void __pyx_f_5scipy_7special_8lambertw__apply_func_to_1d_vec(char **__pyx_v_args, npy_intp *__pyx_v_dimensions, npy_intp *__pyx_v_steps, void *__pyx_v_func) {
npy_intp __pyx_v_i;
char *__pyx_v_ip1;
char *__pyx_v_ip2;
char *__pyx_v_ip3;
char *__pyx_v_op;
npy_intp __pyx_t_1;
npy_intp __pyx_t_2;
/* "scipy/special/lambertw.pyx":169
* void *func) nogil:
* cdef npy_intp i
* cdef char *ip1=args[0], *ip2=args[1], *ip3=args[2], *op=args[3] # <<<<<<<<<<<<<<
* for i in range(0, dimensions[0]):
* (<double complex*>op)[0] = (<double complex(*)(double complex, long, double) nogil>func)(
*/
__pyx_v_ip1 = (__pyx_v_args[0]);
__pyx_v_ip2 = (__pyx_v_args[1]);
__pyx_v_ip3 = (__pyx_v_args[2]);
__pyx_v_op = (__pyx_v_args[3]);
/* "scipy/special/lambertw.pyx":170
* cdef npy_intp i
* cdef char *ip1=args[0], *ip2=args[1], *ip3=args[2], *op=args[3]
* for i in range(0, dimensions[0]): # <<<<<<<<<<<<<<
* (<double complex*>op)[0] = (<double complex(*)(double complex, long, double) nogil>func)(
* (<double complex*>ip1)[0], (<long*>ip2)[0], (<double*>ip3)[0])
*/
__pyx_t_1 = (__pyx_v_dimensions[0]);
for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
__pyx_v_i = __pyx_t_2;
/* "scipy/special/lambertw.pyx":171
* cdef char *ip1=args[0], *ip2=args[1], *ip3=args[2], *op=args[3]
* for i in range(0, dimensions[0]):
* (<double complex*>op)[0] = (<double complex(*)(double complex, long, double) nogil>func)( # <<<<<<<<<<<<<<
* (<double complex*>ip1)[0], (<long*>ip2)[0], (<double*>ip3)[0])
* ip1 += steps[0]; ip2 += steps[1]; ip3 += steps[2]; op += steps[3]
*/
(((__pyx_t_double_complex *)__pyx_v_op)[0]) = ((__pyx_t_double_complex (*)(__pyx_t_double_complex, long, double))__pyx_v_func)((((__pyx_t_double_complex *)__pyx_v_ip1)[0]), (((long *)__pyx_v_ip2)[0]), (((double *)__pyx_v_ip3)[0]));
/* "scipy/special/lambertw.pyx":173
* (<double complex*>op)[0] = (<double complex(*)(double complex, long, double) nogil>func)(
* (<double complex*>ip1)[0], (<long*>ip2)[0], (<double*>ip3)[0])
* ip1 += steps[0]; ip2 += steps[1]; ip3 += steps[2]; op += steps[3] # <<<<<<<<<<<<<<
*
* cdef PyUFuncGenericFunction _loop_funcs[1]
*/
__pyx_v_ip1 = (__pyx_v_ip1 + (__pyx_v_steps[0]));
__pyx_v_ip2 = (__pyx_v_ip2 + (__pyx_v_steps[1]));
__pyx_v_ip3 = (__pyx_v_ip3 + (__pyx_v_steps[2]));
__pyx_v_op = (__pyx_v_op + (__pyx_v_steps[3]));
}
}
/* "scipy/special/lambertw.pyx":193
* _inp_outp_types, 1, 3, 1, 0, "", "", 0)
*
* def lambertw(z, k=0, tol=1e-8): # <<<<<<<<<<<<<<
* r"""
* lambertw(z, k=0, tol=1e-8)
*/
static PyObject *__pyx_pf_5scipy_7special_8lambertw_lambertw(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5scipy_7special_8lambertw_lambertw[] = "\n lambertw(z, k=0, tol=1e-8)\n\n Lambert W function.\n\n The Lambert W function `W(z)` is defined as the inverse function\n of :math:`w \\exp(w)`. In other words, the value of :math:`W(z)` is\n such that :math:`z = W(z) \\exp(W(z))` for any complex number\n :math:`z`.\n\n The Lambert W function is a multivalued function with infinitely\n many branches. Each branch gives a separate solution of the\n equation :math:`w \\exp(w)`. Here, the branches are indexed by the\n integer `k`.\n \n Parameters\n ----------\n z : array_like\n Input argument\n k : integer, optional\n Branch index\n tol : float\n Evaluation tolerance\n\n Notes\n -----\n All branches are supported by `lambertw`:\n\n * ``lambertw(z)`` gives the principal solution (branch 0)\n * ``lambertw(z, k)`` gives the solution on branch `k`\n\n The Lambert W function has two partially real branches: the\n principal branch (`k = 0`) is real for real `z > -1/e`, and the\n `k = -1` branch is real for `-1/e < z < 0`. All branches except\n `k = 0` have a logarithmic singularity at `z = 0`.\n\n .. rubric:: Possible issues\n \n The evaluation can become inaccurate very close to the branch point\n at `-1/e`. In some corner cases, :func:`lambertw` might currently\n fail to converge, or can end up on the wrong branch.\n\n .. rubric:: Algorithm\n\n Halley's iteration is used to invert `w \\exp(w)`, using a first-order\n asymptotic approximation (`O(\\log(w))` or `O(w)`) as the initial\n estimate.\n\n The definition, implementation and choice of branches is based\n on Corless et al, \"On the Lambert W function\", Adv. Comp. Math. 5\n (1996) 329-359, available online here:\n http://www.apmaths.uwo.ca/~djeffrey/Offprints/W-adv-cm.pdf\n \n TODO: use a series expansion when extremely close to the branch point\n at `-1/e` and make sure that the proper branch is chosen there\n\n Examples""\n --------\n The Lambert W function is the inverse of `w \\exp(w)`::\n\n >>> from scipy.special import lambertw\n >>> w = lambertw(1)\n >>> w\n 0.56714329040978387299996866221035555\n >>> w*exp(w)\n 1.0\n\n Any branch gives a valid inverse::\n\n >>> w = lambertw(1, k=3)\n >>> w\n (-2.8535817554090378072068187234910812 +\n 17.113535539412145912607826671159289j)\n >>> w*exp(w)\n (1.0 + 3.5075477124212226194278700785075126e-36j)\n\n .. rubric:: Applications to equation-solving\n\n The Lambert W function may be used to solve various kinds of\n equations, such as finding the value of the infinite power\n tower `z^{z^{z^{\\ldots}}}`::\n\n >>> def tower(z, n):\n ... if n == 0:\n ... return z\n ... return z ** tower(z, n-1)\n ...\n >>> tower(0.5, 100)\n 0.641185744504986\n >>> -lambertw(-log(0.5))/log(0.5)\n 0.6411857445049859844862004821148236665628209571911\n\n .. rubric:: Properties\n\n The Lambert W function grows roughly like the natural logarithm\n for large arguments::\n\n >>> lambertw(1000)\n 5.2496028524016\n >>> log(1000)\n 6.90775527898214\n >>> lambertw(10**100)\n 224.843106445119\n >>> log(10**100)\n 230.258509299405\n \n The principal branch of the Lambert W function has a rational\n Taylor series expansion around `z = 0`::\n \n >>> nprint(taylor(lambertw, 0, 6), 10)\n [0.0, 1.0, -1.0, 1.5, -2.666666667, 5.208333333, -10.8]\n \n Some special values and limits are::\n \n >>> lambertw(0)\n 0.0\n >>> lambertw(1)\n 0.567143290409784\n >>> lambertw(e)\n 1.0\n >>> lambertw(inf)\n +inf\n >>> lambertw(0, k=-1)\n -inf\n >>> lambertw(0, k=3)\n -inf\n >>> lambertw(inf, k=3)\n (+inf + 18.8495559215388j)\n\n The `k = 0` and `k = -1` branches join at `z = -1/e` where\n `W(z) = -1` for both branches. Since `-1/e` can only be represented\n approximately with mpmath numbers, evaluatin""g the Lambert W function\n at this point only gives `-1` approximately::\n\n >>> lambertw(-1/e, 0)\n -0.999999999999837133022867\n >>> lambertw(-1/e, -1)\n -1.00000000000016286697718\n \n If `-1/e` happens to round in the negative direction, there might be\n a small imaginary part::\n \n >>> lambertw(-1/e)\n (-1.0 + 8.22007971511612e-9j)\n\n ";
static PyMethodDef __pyx_mdef_5scipy_7special_8lambertw_lambertw = {__Pyx_NAMESTR("lambertw"), (PyCFunction)__pyx_pf_5scipy_7special_8lambertw_lambertw, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5scipy_7special_8lambertw_lambertw)};
static PyObject *__pyx_pf_5scipy_7special_8lambertw_lambertw(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_z = 0;
PyObject *__pyx_v_k = 0;
PyObject *__pyx_v_tol = 0;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__z,&__pyx_n_s__k,&__pyx_n_s__tol,0};
__Pyx_RefNannySetupContext("lambertw");
__pyx_self = __pyx_self;
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[3] = {0,0,0};
values[1] = ((PyObject *)__pyx_int_0);
values[2] = __pyx_k_2;
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__z);
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k);
if (value) { values[1] = value; kw_args--; }
}
case 2:
if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tol);
if (value) { values[2] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "lambertw") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_z = values[0];
__pyx_v_k = values[1];
__pyx_v_tol = values[2];
} else {
__pyx_v_k = ((PyObject *)__pyx_int_0);
__pyx_v_tol = __pyx_k_2;
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: __pyx_v_tol = PyTuple_GET_ITEM(__pyx_args, 2);
case 2: __pyx_v_k = PyTuple_GET_ITEM(__pyx_args, 1);
case 1: __pyx_v_z = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("lambertw", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("scipy.special.lambertw.lambertw", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
/* "scipy/special/lambertw.pyx":340
*
* """
* return _lambertw(z, k, tol) # <<<<<<<<<<<<<<
*
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___lambertw); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_v_z);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_z);
__Pyx_GIVEREF(__pyx_v_z);
__Pyx_INCREF(__pyx_v_k);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_k);
__Pyx_GIVEREF(__pyx_v_k);
__Pyx_INCREF(__pyx_v_tol);
PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_tol);
__Pyx_GIVEREF(__pyx_v_tol);
__pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("scipy.special.lambertw.lambertw", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyMethodDef __pyx_methods[] = {
{0, 0, 0, 0}
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
PyModuleDef_HEAD_INIT,
__Pyx_NAMESTR("lambertw"),
0, /* m_doc */
-1, /* m_size */
__pyx_methods /* m_methods */,
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL /* m_free */
};
#endif
static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
{&__pyx_n_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 1},
{&__pyx_kp_u_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 1, 0, 0},
{&__pyx_kp_u_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 1, 0, 0},
{&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
{&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
{&__pyx_n_s___lambertw, __pyx_k___lambertw, sizeof(__pyx_k___lambertw), 0, 0, 1, 1},
{&__pyx_n_s__k, __pyx_k__k, sizeof(__pyx_k__k), 0, 0, 1, 1},
{&__pyx_n_s__lambertw, __pyx_k__lambertw, sizeof(__pyx_k__lambertw), 0, 0, 1, 1},
{&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
{&__pyx_n_s__tol, __pyx_k__tol, sizeof(__pyx_k__tol), 0, 0, 1, 1},
{&__pyx_n_s__warn, __pyx_k__warn, sizeof(__pyx_k__warn), 0, 0, 1, 1},
{&__pyx_n_s__warnings, __pyx_k__warnings, sizeof(__pyx_k__warnings), 0, 0, 1, 1},
{&__pyx_n_s__z, __pyx_k__z, sizeof(__pyx_k__z), 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
__pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
return 0;
__pyx_L1_error:;
return -1;
}
static int __Pyx_InitCachedConstants(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");
__Pyx_RefNannyFinishContext();
return 0;
}
static int __Pyx_InitGlobals(void) {
if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
__pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
return 0;
__pyx_L1_error:;
return -1;
}
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initlambertw(void); /*proto*/
PyMODINIT_FUNC initlambertw(void)
#else
PyMODINIT_FUNC PyInit_lambertw(void); /*proto*/
PyMODINIT_FUNC PyInit_lambertw(void)
#endif
{
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannyDeclarations
#if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
PyErr_Clear();
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
if (!__Pyx_RefNanny)
Py_FatalError("failed to import 'refnanny' module");
}
#endif
__Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_lambertw(void)");
if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#ifdef __pyx_binding_PyCFunctionType_USED
if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
/*--- Library function declarations ---*/
/*--- Threads initialization code ---*/
#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
#ifdef WITH_THREAD /* Python build with threading support? */
PyEval_InitThreads();
#endif
#endif
/*--- Module creation code ---*/
#if PY_MAJOR_VERSION < 3
__pyx_m = Py_InitModule4(__Pyx_NAMESTR("lambertw"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
#else
__pyx_m = PyModule_Create(&__pyx_moduledef);
#endif
if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
#if PY_MAJOR_VERSION < 3
Py_INCREF(__pyx_m);
#endif
__pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
/*--- Initialize various global constants etc. ---*/
if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
if (__pyx_module_is_main_scipy__special__lambertw) {
if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
}
/*--- Builtin init code ---*/
if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
/*--- Constants init code ---*/
if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
/*--- Global init code ---*/
/*--- Variable export code ---*/
/*--- Function export code ---*/
/*--- Type init code ---*/
/*--- Type import code ---*/
/*--- Variable import code ---*/
/*--- Function import code ---*/
/*--- Execution code ---*/
/* "scipy/special/lambertw.pyx":24
*
* import cython
* import warnings # <<<<<<<<<<<<<<
*
* cdef extern from "math.h":
*/
__pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__warnings), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__warnings, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "scipy/special/lambertw.pyx":176
*
* cdef PyUFuncGenericFunction _loop_funcs[1]
* _loop_funcs[0] = _apply_func_to_1d_vec # <<<<<<<<<<<<<<
*
* cdef char _inp_outp_types[4]
*/
(__pyx_v_5scipy_7special_8lambertw__loop_funcs[0]) = __pyx_f_5scipy_7special_8lambertw__apply_func_to_1d_vec;
/* "scipy/special/lambertw.pyx":179
*
* cdef char _inp_outp_types[4]
* _inp_outp_types[0] = NPY_CDOUBLE # <<<<<<<<<<<<<<
* _inp_outp_types[1] = NPY_LONG
* _inp_outp_types[2] = NPY_DOUBLE
*/
(__pyx_v_5scipy_7special_8lambertw__inp_outp_types[0]) = NPY_CDOUBLE;
/* "scipy/special/lambertw.pyx":180
* cdef char _inp_outp_types[4]
* _inp_outp_types[0] = NPY_CDOUBLE
* _inp_outp_types[1] = NPY_LONG # <<<<<<<<<<<<<<
* _inp_outp_types[2] = NPY_DOUBLE
* _inp_outp_types[3] = NPY_CDOUBLE
*/
(__pyx_v_5scipy_7special_8lambertw__inp_outp_types[1]) = NPY_LONG;
/* "scipy/special/lambertw.pyx":181
* _inp_outp_types[0] = NPY_CDOUBLE
* _inp_outp_types[1] = NPY_LONG
* _inp_outp_types[2] = NPY_DOUBLE # <<<<<<<<<<<<<<
* _inp_outp_types[3] = NPY_CDOUBLE
*
*/
(__pyx_v_5scipy_7special_8lambertw__inp_outp_types[2]) = NPY_DOUBLE;
/* "scipy/special/lambertw.pyx":182
* _inp_outp_types[1] = NPY_LONG
* _inp_outp_types[2] = NPY_DOUBLE
* _inp_outp_types[3] = NPY_CDOUBLE # <<<<<<<<<<<<<<
*
* import_array()
*/
(__pyx_v_5scipy_7special_8lambertw__inp_outp_types[3]) = NPY_CDOUBLE;
/* "scipy/special/lambertw.pyx":184
* _inp_outp_types[3] = NPY_CDOUBLE
*
* import_array() # <<<<<<<<<<<<<<
* import_ufunc()
*
*/
import_array();
/* "scipy/special/lambertw.pyx":185
*
* import_array()
* import_ufunc() # <<<<<<<<<<<<<<
*
* # The actual ufunc declaration:
*/
import_ufunc();
/* "scipy/special/lambertw.pyx":189
* # The actual ufunc declaration:
* cdef void *the_func_to_apply[1]
* the_func_to_apply[0] = <void*>lambertw_scalar # <<<<<<<<<<<<<<
* _lambertw = PyUFunc_FromFuncAndData(_loop_funcs, the_func_to_apply,
* _inp_outp_types, 1, 3, 1, 0, "", "", 0)
*/
(__pyx_v_5scipy_7special_8lambertw_the_func_to_apply[0]) = ((void *)__pyx_f_5scipy_7special_8lambertw_lambertw_scalar);
/* "scipy/special/lambertw.pyx":191
* the_func_to_apply[0] = <void*>lambertw_scalar
* _lambertw = PyUFunc_FromFuncAndData(_loop_funcs, the_func_to_apply,
* _inp_outp_types, 1, 3, 1, 0, "", "", 0) # <<<<<<<<<<<<<<
*
* def lambertw(z, k=0, tol=1e-8):
*/
__pyx_t_1 = PyUFunc_FromFuncAndData(__pyx_v_5scipy_7special_8lambertw__loop_funcs, __pyx_v_5scipy_7special_8lambertw_the_func_to_apply, __pyx_v_5scipy_7special_8lambertw__inp_outp_types, 1, 3, 1, 0, __pyx_k_3, __pyx_k_3, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
if (PyObject_SetAttr(__pyx_m, __pyx_n_s___lambertw, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "scipy/special/lambertw.pyx":193
* _inp_outp_types, 1, 3, 1, 0, "", "", 0)
*
* def lambertw(z, k=0, tol=1e-8): # <<<<<<<<<<<<<<
* r"""
* lambertw(z, k=0, tol=1e-8)
*/
__pyx_t_1 = PyFloat_FromDouble(1e-8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_k_2 = __pyx_t_1;
__Pyx_GIVEREF(__pyx_t_1);
__pyx_t_1 = 0;
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5scipy_7special_8lambertw_lambertw, NULL, __pyx_n_s_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
if (PyObject_SetAttr(__pyx_m, __pyx_n_s__lambertw, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "scipy/special/lambertw.pyx":1
* # Implementation of the Lambert W function [1]. Based on the MPMath # <<<<<<<<<<<<<<
* # implementation [2], and documentaion [3].
* #
*/
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_5), ((PyObject *)__pyx_kp_u_6)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
if (__pyx_m) {
__Pyx_AddTraceback("init scipy.special.lambertw", __pyx_clineno, __pyx_lineno, __pyx_filename);
Py_DECREF(__pyx_m); __pyx_m = 0;
} else if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_ImportError, "init scipy.special.lambertw");
}
__pyx_L0:;
__Pyx_RefNannyFinishContext();
#if PY_MAJOR_VERSION < 3
return;
#else
return __pyx_m;
#endif
}
/* Runtime support code */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
PyObject *m = NULL, *p = NULL;
void *r = NULL;
m = PyImport_ImportModule((char *)modname);
if (!m) goto end;
p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
if (!p) goto end;
r = PyLong_AsVoidPtr(p);
end:
Py_XDECREF(p);
Py_XDECREF(m);
return (__Pyx_RefNannyAPIStruct *)r;
}
#endif /* CYTHON_REFNANNY */
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
PyObject *result;
result = PyObject_GetAttr(dict, name);
if (!result) {
if (dict != __pyx_b) {
PyErr_Clear();
result = PyObject_GetAttr(__pyx_b, name);
}
if (!result) {
PyErr_SetObject(PyExc_NameError, name);
}
}
return result;
}
static void __Pyx_RaiseDoubleKeywordsError(
const char* func_name,
PyObject* kw_name)
{
PyErr_Format(PyExc_TypeError,
#if PY_MAJOR_VERSION >= 3
"%s() got multiple values for keyword argument '%U'", func_name, kw_name);
#else
"%s() got multiple values for keyword argument '%s'", func_name,
PyString_AS_STRING(kw_name));
#endif
}
static int __Pyx_ParseOptionalKeywords(
PyObject *kwds,
PyObject **argnames[],
PyObject *kwds2,
PyObject *values[],
Py_ssize_t num_pos_args,
const char* function_name)
{
PyObject *key = 0, *value = 0;
Py_ssize_t pos = 0;
PyObject*** name;
PyObject*** first_kw_arg = argnames + num_pos_args;
while (PyDict_Next(kwds, &pos, &key, &value)) {
name = first_kw_arg;
while (*name && (**name != key)) name++;
if (*name) {
values[name-argnames] = value;
} else {
#if PY_MAJOR_VERSION < 3
if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
#else
if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
#endif
goto invalid_keyword_type;
} else {
for (name = first_kw_arg; *name; name++) {
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
PyUnicode_Compare(**name, key) == 0) break;
#else
if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
_PyString_Eq(**name, key)) break;
#endif
}
if (*name) {
values[name-argnames] = value;
} else {
/* unexpected keyword found */
for (name=argnames; name != first_kw_arg; name++) {
if (**name == key) goto arg_passed_twice;
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
#else
if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
_PyString_Eq(**name, key)) goto arg_passed_twice;
#endif
}
if (kwds2) {
if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
} else {
goto invalid_keyword;
}
}
}
}
}
return 0;
arg_passed_twice:
__Pyx_RaiseDoubleKeywordsError(function_name, **name);
goto bad;
invalid_keyword_type:
PyErr_Format(PyExc_TypeError,
"%s() keywords must be strings", function_name);
goto bad;
invalid_keyword:
PyErr_Format(PyExc_TypeError,
#if PY_MAJOR_VERSION < 3
"%s() got an unexpected keyword argument '%s'",
function_name, PyString_AsString(key));
#else
"%s() got an unexpected keyword argument '%U'",
function_name, key);
#endif
bad:
return -1;
}
static void __Pyx_RaiseArgtupleInvalid(
const char* func_name,
int exact,
Py_ssize_t num_min,
Py_ssize_t num_max,
Py_ssize_t num_found)
{
Py_ssize_t num_expected;
const char *more_or_less;
if (num_found < num_min) {
num_expected = num_min;
more_or_less = "at least";
} else {
num_expected = num_max;
more_or_less = "at most";
}
if (exact) {
more_or_less = "exactly";
}
PyErr_Format(PyExc_TypeError,
"%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)",
func_name, more_or_less, num_expected,
(num_expected == 1) ? "" : "s", num_found);
}
#if CYTHON_CCOMPLEX
#ifdef __cplusplus
static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
return ::std::complex< double >(x, y);
}
#else
static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
return x + y*(__pyx_t_double_complex)_Complex_I;
}
#endif
#else
static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
__pyx_t_double_complex z;
z.real = x;
z.imag = y;
return z;
}
#endif
#if CYTHON_CCOMPLEX
#else
static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) {
return (a.real == b.real) && (a.imag == b.imag);
}
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) {
__pyx_t_double_complex z;
z.real = a.real + b.real;
z.imag = a.imag + b.imag;
return z;
}
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) {
__pyx_t_double_complex z;
z.real = a.real - b.real;
z.imag = a.imag - b.imag;
return z;
}
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) {
__pyx_t_double_complex z;
z.real = a.real * b.real - a.imag * b.imag;
z.imag = a.real * b.imag + a.imag * b.real;
return z;
}
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) {
__pyx_t_double_complex z;
double denom = b.real * b.real + b.imag * b.imag;
z.real = (a.real * b.real + a.imag * b.imag) / denom;
z.imag = (a.imag * b.real - a.real * b.imag) / denom;
return z;
}
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) {
__pyx_t_double_complex z;
z.real = -a.real;
z.imag = -a.imag;
return z;
}
static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) {
return (a.real == 0) && (a.imag == 0);
}
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) {
__pyx_t_double_complex z;
z.real = a.real;
z.imag = -a.imag;
return z;
}
#if 1
static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) {
#if !defined(HAVE_HYPOT) || defined(_MSC_VER)
return sqrt(z.real*z.real + z.imag*z.imag);
#else
return hypot(z.real, z.imag);
#endif
}
static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex a, __pyx_t_double_complex b) {
__pyx_t_double_complex z;
double r, lnr, theta, z_r, z_theta;
if (b.imag == 0 && b.real == (int)b.real) {
if (b.real < 0) {
double denom = a.real * a.real + a.imag * a.imag;
a.real = a.real / denom;
a.imag = -a.imag / denom;
b.real = -b.real;
}
switch ((int)b.real) {
case 0:
z.real = 1;
z.imag = 0;
return z;
case 1:
return a;
case 2:
z = __Pyx_c_prod(a, a);
return __Pyx_c_prod(a, a);
case 3:
z = __Pyx_c_prod(a, a);
return __Pyx_c_prod(z, a);
case 4:
z = __Pyx_c_prod(a, a);
return __Pyx_c_prod(z, z);
}
}
if (a.imag == 0) {
if (a.real == 0) {
return a;
}
r = a.real;
theta = 0;
} else {
r = __Pyx_c_abs(a);
theta = atan2(a.imag, a.real);
}
lnr = log(r);
z_r = exp(lnr * b.real - theta * b.imag);
z_theta = theta * b.real + lnr * b.imag;
z.real = z_r * cos(z_theta);
z.imag = z_r * sin(z_theta);
return z;
}
#endif
#endif
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
PyObject *py_import = 0;
PyObject *empty_list = 0;
PyObject *module = 0;
PyObject *global_dict = 0;
PyObject *empty_dict = 0;
PyObject *list;
py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
if (!py_import)
goto bad;
if (from_list)
list = from_list;
else {
empty_list = PyList_New(0);
if (!empty_list)
goto bad;
list = empty_list;
}
global_dict = PyModule_GetDict(__pyx_m);
if (!global_dict)
goto bad;
empty_dict = PyDict_New();
if (!empty_dict)
goto bad;
#if PY_VERSION_HEX >= 0x02050000
{
PyObject *py_level = PyInt_FromLong(level);
if (!py_level)
goto bad;
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, py_level, NULL);
Py_DECREF(py_level);
}
#else
if (level>0) {
PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
goto bad;
}
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, NULL);
#endif
bad:
Py_XDECREF(empty_list);
Py_XDECREF(py_import);
Py_XDECREF(empty_dict);
return module;
}
static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_intp(npy_intp val) {
const npy_intp neg_one = (npy_intp)-1, const_zero = (npy_intp)0;
const int is_unsigned = const_zero < neg_one;
if ((sizeof(npy_intp) == sizeof(char)) ||
(sizeof(npy_intp) == sizeof(short))) {
return PyInt_FromLong((long)val);
} else if ((sizeof(npy_intp) == sizeof(int)) ||
(sizeof(npy_intp) == sizeof(long))) {
if (is_unsigned)
return PyLong_FromUnsignedLong((unsigned long)val);
else
return PyInt_FromLong((long)val);
} else if (sizeof(npy_intp) == sizeof(PY_LONG_LONG)) {
if (is_unsigned)
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
else
return PyLong_FromLongLong((PY_LONG_LONG)val);
} else {
int one = 1; int little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&val;
return _PyLong_FromByteArray(bytes, sizeof(npy_intp),
little, !is_unsigned);
}
}
static CYTHON_INLINE npy_intp __Pyx_PyInt_from_py_npy_intp(PyObject* x) {
const npy_intp neg_one = (npy_intp)-1, const_zero = (npy_intp)0;
const int is_unsigned = const_zero < neg_one;
if (sizeof(npy_intp) == sizeof(char)) {
if (is_unsigned)
return (npy_intp)__Pyx_PyInt_AsUnsignedChar(x);
else
return (npy_intp)__Pyx_PyInt_AsSignedChar(x);
} else if (sizeof(npy_intp) == sizeof(short)) {
if (is_unsigned)
return (npy_intp)__Pyx_PyInt_AsUnsignedShort(x);
else
return (npy_intp)__Pyx_PyInt_AsSignedShort(x);
} else if (sizeof(npy_intp) == sizeof(int)) {
if (is_unsigned)
return (npy_intp)__Pyx_PyInt_AsUnsignedInt(x);
else
return (npy_intp)__Pyx_PyInt_AsSignedInt(x);
} else if (sizeof(npy_intp) == sizeof(long)) {
if (is_unsigned)
return (npy_intp)__Pyx_PyInt_AsUnsignedLong(x);
else
return (npy_intp)__Pyx_PyInt_AsSignedLong(x);
} else if (sizeof(npy_intp) == sizeof(PY_LONG_LONG)) {
if (is_unsigned)
return (npy_intp)__Pyx_PyInt_AsUnsignedLongLong(x);
else
return (npy_intp)__Pyx_PyInt_AsSignedLongLong(x);
} else {
npy_intp val;
PyObject *v = __Pyx_PyNumber_Int(x);
#if PY_VERSION_HEX < 0x03000000
if (likely(v) && !PyLong_Check(v)) {
PyObject *tmp = v;
v = PyNumber_Long(tmp);
Py_DECREF(tmp);
}
#endif
if (likely(v)) {
int one = 1; int is_little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&val;
int ret = _PyLong_AsByteArray((PyLongObject *)v,
bytes, sizeof(val),
is_little, !is_unsigned);
Py_DECREF(v);
if (likely(!ret))
return val;
}
return (npy_intp)-1;
}
}
static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(unsigned char) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(unsigned char)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to unsigned char" :
"value too large to convert to unsigned char");
}
return (unsigned char)-1;
}
return (unsigned char)val;
}
return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}
static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(unsigned short) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(unsigned short)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to unsigned short" :
"value too large to convert to unsigned short");
}
return (unsigned short)-1;
}
return (unsigned short)val;
}
return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}
static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(unsigned int) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(unsigned int)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to unsigned int" :
"value too large to convert to unsigned int");
}
return (unsigned int)-1;
}
return (unsigned int)val;
}
return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}
static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
const char neg_one = (char)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(char) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(char)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to char" :
"value too large to convert to char");
}
return (char)-1;
}
return (char)val;
}
return (char)__Pyx_PyInt_AsLong(x);
}
static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
const short neg_one = (short)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(short) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(short)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to short" :
"value too large to convert to short");
}
return (short)-1;
}
return (short)val;
}
return (short)__Pyx_PyInt_AsLong(x);
}
static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
const int neg_one = (int)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(int) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(int)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to int" :
"value too large to convert to int");
}
return (int)-1;
}
return (int)val;
}
return (int)__Pyx_PyInt_AsLong(x);
}
static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
const signed char neg_one = (signed char)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(signed char) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(signed char)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to signed char" :
"value too large to convert to signed char");
}
return (signed char)-1;
}
return (signed char)val;
}
return (signed char)__Pyx_PyInt_AsSignedLong(x);
}
static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
const signed short neg_one = (signed short)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(signed short) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(signed short)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to signed short" :
"value too large to convert to signed short");
}
return (signed short)-1;
}
return (signed short)val;
}
return (signed short)__Pyx_PyInt_AsSignedLong(x);
}
static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
const signed int neg_one = (signed int)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(signed int) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(signed int)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to signed int" :
"value too large to convert to signed int");
}
return (signed int)-1;
}
return (signed int)val;
}
return (signed int)__Pyx_PyInt_AsSignedLong(x);
}
static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
const int neg_one = (int)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
if (sizeof(int) < sizeof(long)) {
long val = __Pyx_PyInt_AsLong(x);
if (unlikely(val != (long)(int)val)) {
if (!unlikely(val == -1 && PyErr_Occurred())) {
PyErr_SetString(PyExc_OverflowError,
(is_unsigned && unlikely(val < 0)) ?
"can't convert negative value to int" :
"value too large to convert to int");
}
return (int)-1;
}
return (int)val;
}
return (int)__Pyx_PyInt_AsLong(x);
}
static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
if (likely(PyInt_Check(x))) {
long val = PyInt_AS_LONG(x);
if (is_unsigned && unlikely(val < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to unsigned long");
return (unsigned long)-1;
}
return (unsigned long)val;
} else
#endif
if (likely(PyLong_Check(x))) {
if (is_unsigned) {
if (unlikely(Py_SIZE(x) < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to unsigned long");
return (unsigned long)-1;
}
return (unsigned long)PyLong_AsUnsignedLong(x);
} else {
return (unsigned long)PyLong_AsLong(x);
}
} else {
unsigned long val;
PyObject *tmp = __Pyx_PyNumber_Int(x);
if (!tmp) return (unsigned long)-1;
val = __Pyx_PyInt_AsUnsignedLong(tmp);
Py_DECREF(tmp);
return val;
}
}
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
if (likely(PyInt_Check(x))) {
long val = PyInt_AS_LONG(x);
if (is_unsigned && unlikely(val < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to unsigned PY_LONG_LONG");
return (unsigned PY_LONG_LONG)-1;
}
return (unsigned PY_LONG_LONG)val;
} else
#endif
if (likely(PyLong_Check(x))) {
if (is_unsigned) {
if (unlikely(Py_SIZE(x) < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to unsigned PY_LONG_LONG");
return (unsigned PY_LONG_LONG)-1;
}
return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
} else {
return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
}
} else {
unsigned PY_LONG_LONG val;
PyObject *tmp = __Pyx_PyNumber_Int(x);
if (!tmp) return (unsigned PY_LONG_LONG)-1;
val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
Py_DECREF(tmp);
return val;
}
}
static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
const long neg_one = (long)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
if (likely(PyInt_Check(x))) {
long val = PyInt_AS_LONG(x);
if (is_unsigned && unlikely(val < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to long");
return (long)-1;
}
return (long)val;
} else
#endif
if (likely(PyLong_Check(x))) {
if (is_unsigned) {
if (unlikely(Py_SIZE(x) < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to long");
return (long)-1;
}
return (long)PyLong_AsUnsignedLong(x);
} else {
return (long)PyLong_AsLong(x);
}
} else {
long val;
PyObject *tmp = __Pyx_PyNumber_Int(x);
if (!tmp) return (long)-1;
val = __Pyx_PyInt_AsLong(tmp);
Py_DECREF(tmp);
return val;
}
}
static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
if (likely(PyInt_Check(x))) {
long val = PyInt_AS_LONG(x);
if (is_unsigned && unlikely(val < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to PY_LONG_LONG");
return (PY_LONG_LONG)-1;
}
return (PY_LONG_LONG)val;
} else
#endif
if (likely(PyLong_Check(x))) {
if (is_unsigned) {
if (unlikely(Py_SIZE(x) < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to PY_LONG_LONG");
return (PY_LONG_LONG)-1;
}
return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
} else {
return (PY_LONG_LONG)PyLong_AsLongLong(x);
}
} else {
PY_LONG_LONG val;
PyObject *tmp = __Pyx_PyNumber_Int(x);
if (!tmp) return (PY_LONG_LONG)-1;
val = __Pyx_PyInt_AsLongLong(tmp);
Py_DECREF(tmp);
return val;
}
}
static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
const signed long neg_one = (signed long)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
if (likely(PyInt_Check(x))) {
long val = PyInt_AS_LONG(x);
if (is_unsigned && unlikely(val < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to signed long");
return (signed long)-1;
}
return (signed long)val;
} else
#endif
if (likely(PyLong_Check(x))) {
if (is_unsigned) {
if (unlikely(Py_SIZE(x) < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to signed long");
return (signed long)-1;
}
return (signed long)PyLong_AsUnsignedLong(x);
} else {
return (signed long)PyLong_AsLong(x);
}
} else {
signed long val;
PyObject *tmp = __Pyx_PyNumber_Int(x);
if (!tmp) return (signed long)-1;
val = __Pyx_PyInt_AsSignedLong(tmp);
Py_DECREF(tmp);
return val;
}
}
static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
if (likely(PyInt_Check(x))) {
long val = PyInt_AS_LONG(x);
if (is_unsigned && unlikely(val < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to signed PY_LONG_LONG");
return (signed PY_LONG_LONG)-1;
}
return (signed PY_LONG_LONG)val;
} else
#endif
if (likely(PyLong_Check(x))) {
if (is_unsigned) {
if (unlikely(Py_SIZE(x) < 0)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to signed PY_LONG_LONG");
return (signed PY_LONG_LONG)-1;
}
return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
} else {
return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
}
} else {
signed PY_LONG_LONG val;
PyObject *tmp = __Pyx_PyNumber_Int(x);
if (!tmp) return (signed PY_LONG_LONG)-1;
val = __Pyx_PyInt_AsSignedLongLong(tmp);
Py_DECREF(tmp);
return val;
}
}
static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
PyThreadState *tstate = PyThreadState_GET();
tmp_type = tstate->curexc_type;
tmp_value = tstate->curexc_value;
tmp_tb = tstate->curexc_traceback;
tstate->curexc_type = type;
tstate->curexc_value = value;
tstate->curexc_traceback = tb;
Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
PyThreadState *tstate = PyThreadState_GET();
*type = tstate->curexc_type;
*value = tstate->curexc_value;
*tb = tstate->curexc_traceback;
tstate->curexc_type = 0;
tstate->curexc_value = 0;
tstate->curexc_traceback = 0;
}
static void __Pyx_WriteUnraisable(const char *name, int clineno,
int lineno, const char *filename) {
PyObject *old_exc, *old_val, *old_tb;
PyObject *ctx;
__Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
#if PY_MAJOR_VERSION < 3
ctx = PyString_FromString(name);
#else
ctx = PyUnicode_FromString(name);
#endif
__Pyx_ErrRestore(old_exc, old_val, old_tb);
if (!ctx) {
PyErr_WriteUnraisable(Py_None);
} else {
PyErr_WriteUnraisable(ctx);
Py_DECREF(ctx);
}
}
static int __Pyx_check_binary_version(void) {
char ctversion[4], rtversion[4];
PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
char message[200];
PyOS_snprintf(message, sizeof(message),
"compiletime version %s of module '%.100s' "
"does not match runtime version %s",
ctversion, __Pyx_MODULE_NAME, rtversion);
#if PY_VERSION_HEX < 0x02050000
return PyErr_Warn(NULL, message);
#else
return PyErr_WarnEx(NULL, message, 1);
#endif
}
return 0;
}
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static void __Pyx_AddTraceback(const char *funcname, int __pyx_clineno,
int __pyx_lineno, const char *__pyx_filename) {
PyObject *py_srcfile = 0;
PyObject *py_funcname = 0;
PyObject *py_globals = 0;
PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0;
#if PY_MAJOR_VERSION < 3
py_srcfile = PyString_FromString(__pyx_filename);
#else
py_srcfile = PyUnicode_FromString(__pyx_filename);
#endif
if (!py_srcfile) goto bad;
if (__pyx_clineno) {
#if PY_MAJOR_VERSION < 3
py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
#else
py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
#endif
}
else {
#if PY_MAJOR_VERSION < 3
py_funcname = PyString_FromString(funcname);
#else
py_funcname = PyUnicode_FromString(funcname);
#endif
}
if (!py_funcname) goto bad;
py_globals = PyModule_GetDict(__pyx_m);
if (!py_globals) goto bad;
py_code = PyCode_New(
0, /*int argcount,*/
#if PY_MAJOR_VERSION >= 3
0, /*int kwonlyargcount,*/
#endif
0, /*int nlocals,*/
0, /*int stacksize,*/
0, /*int flags,*/
__pyx_empty_bytes, /*PyObject *code,*/
__pyx_empty_tuple, /*PyObject *consts,*/
__pyx_empty_tuple, /*PyObject *names,*/
__pyx_empty_tuple, /*PyObject *varnames,*/
__pyx_empty_tuple, /*PyObject *freevars,*/
__pyx_empty_tuple, /*PyObject *cellvars,*/
py_srcfile, /*PyObject *filename,*/
py_funcname, /*PyObject *name,*/
__pyx_lineno, /*int firstlineno,*/
__pyx_empty_bytes /*PyObject *lnotab*/
);
if (!py_code) goto bad;
py_frame = PyFrame_New(
PyThreadState_GET(), /*PyThreadState *tstate,*/
py_code, /*PyCodeObject *code,*/
py_globals, /*PyObject *globals,*/
0 /*PyObject *locals*/
);
if (!py_frame) goto bad;
py_frame->f_lineno = __pyx_lineno;
PyTraceBack_Here(py_frame);
bad:
Py_XDECREF(py_srcfile);
Py_XDECREF(py_funcname);
Py_XDECREF(py_code);
Py_XDECREF(py_frame);
}
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
while (t->p) {
#if PY_MAJOR_VERSION < 3
if (t->is_unicode) {
*t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
} else if (t->intern) {
*t->p = PyString_InternFromString(t->s);
} else {
*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
}
#else /* Python 3+ has unicode identifiers */
if (t->is_unicode | t->is_str) {
if (t->intern) {
*t->p = PyUnicode_InternFromString(t->s);
} else if (t->encoding) {
*t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
} else {
*t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
}
} else {
*t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
}
#endif
if (!*t->p)
return -1;
++t;
}
return 0;
}
/* Type Conversion Functions */
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
int is_true = x == Py_True;
if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
else return PyObject_IsTrue(x);
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
PyNumberMethods *m;
const char *name = NULL;
PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(x) || PyLong_Check(x))
#else
if (PyLong_Check(x))
#endif
return Py_INCREF(x), x;
m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
if (m && m->nb_int) {
name = "int";
res = PyNumber_Int(x);
}
else if (m && m->nb_long) {
name = "long";
res = PyNumber_Long(x);
}
#else
if (m && m->nb_int) {
name = "int";
res = PyNumber_Long(x);
}
#endif
if (res) {
#if PY_VERSION_HEX < 0x03000000
if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
if (!PyLong_Check(res)) {
#endif
PyErr_Format(PyExc_TypeError,
"__%s__ returned non-%s (type %.200s)",
name, name, Py_TYPE(res)->tp_name);
Py_DECREF(res);
return NULL;
}
}
else if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError,
"an integer is required");
}
return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
Py_ssize_t ival;
PyObject* x = PyNumber_Index(b);
if (!x) return -1;
ival = PyInt_AsSsize_t(x);
Py_DECREF(x);
return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
if (ival <= LONG_MAX)
return PyInt_FromLong((long)ival);
else {
unsigned char *bytes = (unsigned char *) &ival;
int one = 1; int little = (int)*(unsigned char*)&one;
return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
}
#else
return PyInt_FromSize_t(ival);
#endif
}
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
return (size_t)-1;
} else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
PyErr_SetString(PyExc_OverflowError,
"value too large to convert to size_t");
return (size_t)-1;
}
return (size_t)val;
}
#endif /* Py_PYTHON_H */
|