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 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390
|
#include "stdafx.h"
#include <sstream>
#include <math.h>
#include "alglibmisc.h"
#include "alglibinternal.h"
#include "linalg.h"
#include "statistics.h"
#include "dataanalysis.h"
#include "specialfunctions.h"
#include "solvers.h"
#include "optimization.h"
#include "diffequations.h"
#include "fasttransforms.h"
#include "integration.h"
#include "interpolation.h"
#if (AE_OS!=AE_WINDOWS) && (AE_OS!=AE_POSIX) && (AE_OS!=AE_LINUX) && !defined(AE_DEBUG4WINDOWS) && !defined(AE_DEBUG4POSIX)
#error X-test requires either AE_OS, AE_DEBUG4WINDOWS or AE_DEBUG4POSIX defined
#endif
#if AE_OS==AE_WINDOWS
#include <windows.h>
#elif AE_OS==AE_POSIX
#include <pthread.h>
#endif
using namespace alglib;
const char *fmt_str = "%-29s %s\n";
const char *fmt_speedup = "%-25s %5.1fx\n";
//
// Flag variables
//
bool issue505_passed = true;
bool issue478_passed = true;
bool issue528_passed = true;
bool issue591_passed = true;
bool issue594_passed = true;
bool issue764_passed = true;
bool issue813_passed = true;
bool issue824_passed = true;
//
// Service datatypes
//
typedef struct
{
alglib_impl::ae_complex cval;
double rval;
alglib_impl::ae_int_t ival;
ae_bool bval;
alglib_impl::ae_vector i1val;
} innerrec;
typedef struct
{
ae_bool bval;
innerrec recval;
alglib_impl::ae_shared_pool pool;
} seedrec;
void _innerrec_init(void* _p, alglib_impl::ae_state *_state, ae_bool make_automatic)
{
innerrec *p = (innerrec*)_p;
alglib_impl::ae_touch_ptr((void*)p);
alglib_impl::ae_vector_init(&p->i1val, 0, alglib_impl::DT_INT, _state, make_automatic);
}
void _innerrec_init_copy(void* _dst, const void* _src, alglib_impl::ae_state *_state, ae_bool make_automatic)
{
innerrec *dst = (innerrec*)_dst;
innerrec *src = (innerrec*)_src;
dst->cval = src->cval;
dst->rval = src->rval;
dst->ival = src->ival;
dst->bval = src->bval;
alglib_impl::ae_vector_init_copy(&dst->i1val, &src->i1val, _state, make_automatic);
}
void _innerrec_clear(void* _p)
{
innerrec *p = (innerrec*)_p;
alglib_impl::ae_touch_ptr((void*)p);
alglib_impl::ae_vector_clear(&p->i1val);
}
void _innerrec_destroy(void* _p)
{
innerrec *p = (innerrec*)_p;
alglib_impl::ae_touch_ptr((void*)p);
alglib_impl::ae_vector_destroy(&p->i1val);
}
void _seedrec_init(void* _p, alglib_impl::ae_state *_state, ae_bool make_automatic)
{
seedrec *p = (seedrec*)_p;
alglib_impl::ae_touch_ptr((void*)p);
_innerrec_init(&p->recval, _state, make_automatic);
alglib_impl::ae_shared_pool_init(&p->pool, _state, make_automatic);
}
void _seedrec_init_copy(void* _dst, const void* _src, alglib_impl::ae_state *_state, ae_bool make_automatic)
{
seedrec *dst = (seedrec*)_dst;
seedrec *src = (seedrec*)_src;
dst->bval = src->bval;
_innerrec_init_copy(&dst->recval, &src->recval, _state, make_automatic);
alglib_impl::ae_shared_pool_init_copy(&dst->pool, &src->pool, _state, make_automatic);
}
void _seedrec_clear(void* _p)
{
seedrec *p = (seedrec*)_p;
alglib_impl::ae_touch_ptr((void*)p);
_innerrec_clear(&p->recval);
alglib_impl::ae_shared_pool_clear(&p->pool);
}
void _seedrec_destroy(void* _p)
{
seedrec *p = (seedrec*)_p;
alglib_impl::ae_touch_ptr((void*)p);
_innerrec_destroy(&p->recval);
alglib_impl::ae_shared_pool_destroy(&p->pool);
}
int imin(int a, int b)
{
return a<b ? a : b;
}
void func505_grad(const real_1d_array &x, double &func, real_1d_array &grad, void *ptr)
{
double x0 = *((double*)ptr);
//
// This block assigns zero vector to gradient. Because gradient is a proxy vector
// (vector which uses another object as storage), sizes of gradient and vector being
// assigned must be equal. In this case data are copied in the memory linked with
// proxy.
//
// Early versions of ALGLIB failed to handle such assignment (it disrupted link
// between proxy vector and actual gradient stored in the internals of ALGLIB).
//
real_1d_array z = "[0]";
grad = "[0]";
grad = z;
//
// This block tries to perform operations which are forbidden for proxy vector:
// * assign vector of non-matching size
// * change length of the vector
// Correct implementation must throw an exception without breaking a link between
// proxy object and actual vector.
//
z = "[0,1]";
try
{
grad = "[0,1]";
issue505_passed = false;
}
catch(...) {}
try
{
grad = z;
issue505_passed = false;
}
catch(...) {}
try
{
grad.setlength(10);
issue505_passed = false;
}
catch(...) {}
try
{
grad.setlength(1);
issue505_passed = false;
}
catch(...) {}
//
// This block actually calculates function/gradient
//
func = pow(x[0]-x0,4);
grad[0] = 4*pow(x[0]-x0,3);
}
void func505_vec(const real_1d_array &x, real_1d_array &fi, void *ptr)
{
double x0 = *((double*)ptr);
fi[0] = x[0]-x0;
fi[1] = pow(x[0]-x0,2);
}
void func505_jac(const real_1d_array &x, real_1d_array &fi, real_2d_array &jac, void *ptr)
{
double x0 = *((double*)ptr);
//
// This block assigns zero matrix to Jacobian. Because Jacobian is a proxy matrix
// (matrix which uses another object as storage), sizes of Jacobian and matrix being
// assigned must be equal. In this case data are copied in the memory linked with
// proxy.
//
// Early versions of ALGLIB failed to handle such assignment (it discrupted link
// between proxy and actual matrix stored in the internals of ALGLIB).
//
real_2d_array z = "[[0],[0]]";
jac = "[[0],[0]]";
jac = z;
//
// This block tries to perform operations which are forbidden for proxy vector:
// * assign vector of non-matching size
// * change length of the vector
// Correct implementation must throw an exception without breaking a link between
// proxy object and actual vector.
//
try
{
jac = "[[0]]";
issue505_passed = false;
}
catch(...) {}
try
{
jac = "[[0,0],[1,1]]";
issue505_passed = false;
}
catch(...) {}
try
{
z = "[[0,1]]";
jac = z;
issue505_passed = false;
}
catch(...) {}
try
{
jac.setlength(10,6);
issue505_passed = false;
}
catch(...) {}
try
{
jac.setlength(2,1);
issue505_passed = false;
}
catch(...) {}
//
// This block actually calculates function/gradient
//
fi[0] = x[0]-x0;
fi[1] = pow(x[0]-x0,2);
jac[0][0] = 1.0;
jac[1][0] = 2*(x[0]-x0);
}
void issue813_callback(const alglib::real_1d_array&, alglib::real_1d_array&, void*)
{
throw 0;
}
void issue824_callback_i(const alglib::real_1d_array&, double&, void*)
{
throw (int*)(NULL);
}
void issue824_callback_d(const alglib::real_1d_array&, double&, void*)
{
throw (double*)(NULL);
}
void file_put_contents(const char *filename, const char *contents)
{
FILE *f = fopen(filename, "wb");
if( f==NULL )
throw alglib::ap_error("file_put_contents: failed opening file");
if( fwrite((void*)contents, 1, strlen(contents), f)!=strlen(contents) )
throw alglib::ap_error("file_put_contents: failed writing to file");
fclose(f);
}
#if AE_OS==AE_WINDOWS
struct async_rbf_record
{
alglib::rbfmodel *p_model;
alglib::rbfreport *p_report;
bool thread_finished;
};
DWORD WINAPI async_build_rbf_model(LPVOID T)
{
async_rbf_record *p = (async_rbf_record*)T;
alglib::rbfbuildmodel(*(p->p_model), *(p->p_report));
p->thread_finished = true;
return 0;
}
#elif AE_OS==AE_POSIX
struct async_rbf_record
{
alglib::rbfmodel *p_model;
alglib::rbfreport *p_report;
bool thread_finished;
};
void* async_build_rbf_model(void *T)
{
async_rbf_record *p = (async_rbf_record*)T;
alglib::rbfbuildmodel(*(p->p_model), *(p->p_report));
p->thread_finished = true;
return NULL;
}
#endif
class paracbck_rosenbrock_problem
{
public:
int n;
double parameter;
int countdown;
bool raise_aperror;
alglib_impl::ae_int_t delay;
int callbacks_running;
alglib_impl::ae_lock lock;
bool parallelism_detected;
paracbck_rosenbrock_problem(int _n, double _p):n(_n),parameter(_p),countdown(0),raise_aperror(true),delay(10),callbacks_running(0),parallelism_detected(false)
{
memset(&lock, 0x0, sizeof(lock));
alglib_impl::ae_init_lock(&lock, NULL, ae_false);
}
~paracbck_rosenbrock_problem()
{
ae_free_lock(&lock);
}
};
void paracbck_rosenbrock_func(const alglib::real_1d_array &vars, double &func, void *ptr)
{
paracbck_rosenbrock_problem &problem = *((paracbck_rosenbrock_problem*)ptr);
//
// Compute target
//
func = 0;
for(int i=0; i<problem.n-1; i++)
func += problem.parameter*pow(vars[i+1]-vars[i]*vars[i],2) + pow(1-vars[i],2);
//
// Decrease countdown counter, raise exception if needed
//
bool raise_exception = false;
ae_acquire_lock(&problem.lock);
if( problem.countdown>0 )
{
problem.countdown--;
raise_exception = problem.countdown==0;
}
ae_release_lock(&problem.lock);
if( raise_exception )
{
if( problem.raise_aperror )
throw alglib::ap_error("test ap_error");
else
throw std::string("test string");
}
//
// Increase number of running callbacks, delay, decrease number of running callbacks.
// Check that there are running callbacks while waiting.
//
alglib_impl::ae_int_t t0 = alglib_impl::ae_tickcount();
ae_acquire_lock(&problem.lock);
problem.callbacks_running++;
ae_release_lock(&problem.lock);
while( alglib_impl::ae_tickcount()-t0<problem.delay )
{
ae_acquire_lock(&problem.lock);
if( problem.callbacks_running>1 )
problem.parallelism_detected = true;
ae_release_lock(&problem.lock);
}
ae_acquire_lock(&problem.lock);
problem.callbacks_running--;
ae_release_lock(&problem.lock);
}
class paracbck_lsfit_f0_problem
{
public:
int nparams, ncoord;
alglib::real_2d_array a;
alglib::real_1d_array y;
int countdown;
bool raise_aperror;
alglib_impl::ae_int_t delay;
int callbacks_running;
alglib_impl::ae_lock lock;
bool parallelism_detected;
paracbck_lsfit_f0_problem(int params, int coord):ncoord(coord),nparams(params),countdown(0),raise_aperror(true),delay(10),callbacks_running(0),parallelism_detected(false)
{
alglib::hqrndstate rs;
alglib::real_1d_array c;
//
memset(&lock, 0x0, sizeof(lock));
alglib_impl::ae_init_lock(&lock, NULL, ae_false);
//
alglib::hqrndseed(436444, 935774, rs);
alglib::hqrndnormalm(rs, nparams, ncoord, a);
alglib::hqrndnormalv(rs, nparams, c);
y.setlength(nparams);
for(int i=0; i<nparams; i++)
{
y[i] = 0;
if( ncoord<=nparams )
{
for(int j=0; j<ncoord; j++)
y[i] += a[i][j]*c[j];
for(int j=ncoord; j<nparams; j++)
y[i] += c[j];
}
else
{
for(int j=0; j<nparams-1; j++)
y[i] += a[i][j]*c[j];
double v = 0;
for(int j=nparams-1; j<ncoord; j++)
v += a[i][j];
y[i] += c[nparams-1]*v;
}
}
}
~paracbck_lsfit_f0_problem()
{
ae_free_lock(&lock);
}
};
void paracbck_lsfitf0_func(const alglib::real_1d_array &vars, const alglib::real_1d_array &coord, double &func, void *ptr)
{
paracbck_lsfit_f0_problem &problem = *((paracbck_lsfit_f0_problem*)ptr);
//
// Compute target
//
func = 0;
if( problem.ncoord<=problem.nparams )
{
for(int j=0; j<problem.ncoord; j++)
func += coord[j]*vars[j];
for(int j=problem.ncoord; j<problem.nparams; j++)
func += vars[j];
}
else
{
for(int j=0; j<problem.nparams-1; j++)
func += coord[j]*vars[j];
double v = 0;
for(int j=problem.nparams-1; j<problem.ncoord; j++)
v += coord[j];
func += vars[problem.nparams-1]*v;
}
//
// Decrease countdown counter, raise exception if needed
//
bool raise_exception = false;
ae_acquire_lock(&problem.lock);
if( problem.countdown>0 )
{
problem.countdown--;
raise_exception = problem.countdown==0;
}
ae_release_lock(&problem.lock);
if( raise_exception )
{
if( problem.raise_aperror )
throw alglib::ap_error("test ap_error");
else
throw std::string("test string");
}
//
// Increase number of running callbacks, delay, decrease number of running callbacks.
// Check that there are running callbacks while waiting.
//
alglib_impl::ae_int_t t0 = alglib_impl::ae_tickcount();
ae_acquire_lock(&problem.lock);
problem.callbacks_running++;
ae_release_lock(&problem.lock);
while( alglib_impl::ae_tickcount()-t0<problem.delay )
{
ae_acquire_lock(&problem.lock);
if( problem.callbacks_running>1 )
problem.parallelism_detected = true;
ae_release_lock(&problem.lock);
}
ae_acquire_lock(&problem.lock);
problem.callbacks_running--;
ae_release_lock(&problem.lock);
}
void paracbck_lsfitf0_grad(const alglib::real_1d_array &vars, const alglib::real_1d_array &coord, double &func, alglib::real_1d_array &grad, void *ptr)
{
paracbck_lsfit_f0_problem &problem = *((paracbck_lsfit_f0_problem*)ptr);
//
// Compute target
//
func = 0;
if( problem.ncoord<=problem.nparams )
{
for(int j=0; j<problem.ncoord; j++)
{
func += coord[j]*vars[j];
grad[j] = coord[j];
}
for(int j=problem.ncoord; j<problem.nparams; j++)
{
func += vars[j];
grad[j] = 1;
}
}
else
{
for(int j=0; j<problem.nparams-1; j++)
{
func += coord[j]*vars[j];
grad[j] = coord[j];
}
double v = 0;
for(int j=problem.nparams-1; j<problem.ncoord; j++)
v += coord[j];
func += vars[problem.nparams-1]*v;
grad[problem.nparams-1] = v;
}
//
// Decrease countdown counter, raise exception if needed
//
bool raise_exception = false;
ae_acquire_lock(&problem.lock);
if( problem.countdown>0 )
{
problem.countdown--;
raise_exception = problem.countdown==0;
}
ae_release_lock(&problem.lock);
if( raise_exception )
{
if( problem.raise_aperror )
throw alglib::ap_error("test ap_error");
else
throw std::string("test string");
}
//
// Increase number of running callbacks, delay, decrease number of running callbacks.
// Check that there are running callbacks while waiting.
//
alglib_impl::ae_int_t t0 = alglib_impl::ae_tickcount();
ae_acquire_lock(&problem.lock);
problem.callbacks_running++;
ae_release_lock(&problem.lock);
while( alglib_impl::ae_tickcount()-t0<problem.delay )
{
ae_acquire_lock(&problem.lock);
if( problem.callbacks_running>1 )
problem.parallelism_detected = true;
ae_release_lock(&problem.lock);
}
ae_acquire_lock(&problem.lock);
problem.callbacks_running--;
ae_release_lock(&problem.lock);
}
class paracbck_minlm_f0_problem
{
public:
int nparams, nfunc;
alglib::real_2d_array a;
alglib::real_1d_array y;
int countdown;
bool raise_aperror;
alglib_impl::ae_int_t delay;
int callbacks_running;
alglib_impl::ae_lock lock;
bool parallelism_detected;
paracbck_minlm_f0_problem(int params, int ndup):nparams(params),nfunc(nparams*ndup),countdown(0),raise_aperror(true),delay(10),callbacks_running(0),parallelism_detected(false)
{
alglib::hqrndstate rs;
alglib::real_1d_array c;
alglib::real_2d_array a1;
//
memset(&lock, 0x0, sizeof(lock));
alglib_impl::ae_init_lock(&lock, NULL, ae_false);
//
alglib::hqrndseed(436444, 935774, rs);
alglib::hqrndnormalm(rs, nparams, nparams, a1);
alglib::hqrndnormalv(rs, nparams, c);
a.setlength(nparams*ndup, nparams);
y.setlength(nparams*ndup);
for(int i=0; i<nparams; i++)
{
double v = 0;
for(int j=0; j<nparams; j++)
v += a1[i][j]*c[j];
for(int k=0; k<ndup; k++)
{
for(int j=0; j<nparams; j++)
a[ndup*i+k][j] = a1[i][j];
y[ndup*i+k] = v;
}
}
}
~paracbck_minlm_f0_problem()
{
ae_free_lock(&lock);
}
};
void paracbck_minlmf0_fvec(const alglib::real_1d_array &vars, alglib::real_1d_array &f, void *ptr)
{
paracbck_minlm_f0_problem &problem = *((paracbck_minlm_f0_problem*)ptr);
//
// Compute targets
//
for(int i=0; i<problem.nfunc; i++)
{
f[i] = 0;
for(int j=0; j<problem.nparams; j++)
f[i] += problem.a[i][j]*vars[j];
f[i] -= problem.y[i];
}
//
// Decrease countdown counter, raise exception if needed
//
bool raise_exception = false;
ae_acquire_lock(&problem.lock);
if( problem.countdown>0 )
{
problem.countdown--;
raise_exception = problem.countdown==0;
}
ae_release_lock(&problem.lock);
if( raise_exception )
{
if( problem.raise_aperror )
throw alglib::ap_error("test ap_error");
else
throw std::string("test string");
}
//
// Increase number of running callbacks, delay, decrease number of running callbacks.
// Check that there are running callbacks while waiting.
//
alglib_impl::ae_int_t t0 = alglib_impl::ae_tickcount();
ae_acquire_lock(&problem.lock);
problem.callbacks_running++;
ae_release_lock(&problem.lock);
while( alglib_impl::ae_tickcount()-t0<problem.delay )
{
ae_acquire_lock(&problem.lock);
if( problem.callbacks_running>1 )
problem.parallelism_detected = true;
ae_release_lock(&problem.lock);
}
ae_acquire_lock(&problem.lock);
problem.callbacks_running--;
ae_release_lock(&problem.lock);
}
void paracbck_minlmf0_jac(const alglib::real_1d_array &vars, alglib::real_1d_array &f, alglib::real_2d_array &jac, void *ptr)
{
paracbck_minlm_f0_problem &problem = *((paracbck_minlm_f0_problem*)ptr);
//
// Compute targets
//
for(int i=0; i<problem.nfunc; i++)
{
f[i] = 0;
for(int j=0; j<problem.nparams; j++)
{
f[i] += problem.a[i][j]*vars[j];
jac[i][j] = problem.a[i][j];
}
f[i] -= problem.y[i];
}
//
// Decrease countdown counter, raise exception if needed
//
bool raise_exception = false;
ae_acquire_lock(&problem.lock);
if( problem.countdown>0 )
{
problem.countdown--;
raise_exception = problem.countdown==0;
}
ae_release_lock(&problem.lock);
if( raise_exception )
{
if( problem.raise_aperror )
throw alglib::ap_error("test ap_error");
else
throw std::string("test string");
}
//
// Increase number of running callbacks, delay, decrease number of running callbacks.
// Check that there are running callbacks while waiting.
//
alglib_impl::ae_int_t t0 = alglib_impl::ae_tickcount();
ae_acquire_lock(&problem.lock);
problem.callbacks_running++;
ae_release_lock(&problem.lock);
while( alglib_impl::ae_tickcount()-t0<problem.delay )
{
ae_acquire_lock(&problem.lock);
if( problem.callbacks_running>1 )
problem.parallelism_detected = true;
ae_release_lock(&problem.lock);
}
ae_acquire_lock(&problem.lock);
problem.callbacks_running--;
ae_release_lock(&problem.lock);
}
int main()
{
//
// Report system properties
//
printf("System:\n");
#ifdef AE_HPC
printf("* cores count %3ld\n", (long)alglib_impl::ae_cores_count());
#else
printf("* cores count %3ld\n", (long)1);
#endif
//
// Check status of allocation counter
//
#ifdef AE_USE_ALLOC_COUNTER
printf("Allocation counter activated...\n");
alglib_impl::_use_alloc_counter = ae_true;
if( alglib_impl::_alloc_counter!=0 )
{
printf("FAILURE: alloc_counter is non-zero on start!\n");
return 1;
}
{
alglib::real_1d_array x;
x.setlength(1);
if( alglib_impl::_alloc_counter==0 )
printf(":::: WARNING: ALLOC_COUNTER IS INACTIVE!!! ::::: \n");
}
if( alglib_impl::_alloc_counter!=0 )
{
printf("FAILURE: alloc_counter does not decrease!\n");
return 1;
}
#else
printf("No alloc counter.\nSome tests are skipped.\n");
#endif
//
// Testing basic functionality
//
printf("Basic functions:\n");
{
//
// Testing 1D array functionality
//
bool passed = true;
try
{
//
// 1D boolean
//
// Default constructor, string constructor, copy constructor, assignment constructors:
// * test that array sizes as reported by length match to what was specified
// * test item-by-item access
// * test to_string()
// * test that modification of the copied array does not change original
// * test that setlength() changes length
// * test setcontent/getcontent
// * test getcontent(), operator() and operator[] on constant arrays
// (in this case distinct implementation is used which must be tested separately)
//
alglib::boolean_1d_array arr_0, arr_1("[]"), arr_2("[true,false,true]"), arr_3(arr_2), arr_4, arr_5;
arr_4 = arr_2;
arr_5 = "[true,true,false]";
passed = passed && (arr_0.length()==0);
passed = passed && (arr_1.length()==0);
passed = passed && (arr_2.length()==3);
passed = passed && (arr_3.length()==3);
passed = passed && (arr_2[0]==arr_2(0)) && (arr_2[1]==arr_2(1)) && (arr_2[2]==arr_2(2));
passed = passed && arr_2[0] && !arr_2[1] && arr_2[2];
passed = passed && arr_3[0] && !arr_3[1] && arr_3[2];
passed = passed && arr_4[0] && !arr_4[1] && arr_4[2];
passed = passed && arr_5[0] && arr_5[1] && !arr_5[2];
passed = passed && (arr_2.tostring()=="[true,false,true]");
passed = passed && (arr_3.tostring()=="[true,false,true]");
passed = passed && (arr_4.tostring()=="[true,false,true]");
passed = passed && (arr_5.tostring()=="[true,true,false]");
arr_2[0] = false;
passed = passed && !arr_2[0] && arr_3[0] && arr_4[0];
arr_5.setlength(99);
passed = passed && (arr_5.length()==99);
// setcontent/getcontent
bool a0[] = {true, false, true, false, false};
bool a0_mod = false;
bool a0_orig = true;
bool *p6;
alglib::boolean_1d_array arr_6;
arr_6.setcontent(5, a0);
passed = passed && (arr_6[0]==a0[0]) && (arr_6[1]==a0[1]) && (arr_6[2]==a0[2]) && (arr_6[3]==a0[3]) && (arr_6[4]==a0[4]);
p6 = arr_6.getcontent();
passed = passed && (p6!=a0);
passed = passed && (p6[0]==a0[0]) && (p6[1]==a0[1]) && (p6[2]==a0[2]) && (p6[3]==a0[3]) && (p6[4]==a0[4]);
a0[0] = a0_mod;
passed = passed && (arr_6[0]!=a0[0]);
a0[0] = a0_orig;
// operations on constant arrays
{
const alglib::boolean_1d_array &ac = arr_6;
passed = passed && (ac[0]==a0[0]) && (ac[1]==a0[1]) && (ac[2]==a0[2]) && (ac[3]==a0[3]) && (ac[4]==a0[4]);
passed = passed && (ac(0)==a0[0]) && (ac(1)==a0[1]) && (ac(2)==a0[2]) && (ac(3)==a0[3]) && (ac(4)==a0[4]);
const bool *p = ac.getcontent();
passed = passed && (p[0]==a0[0]) && (p[1]==a0[1]) && (p[2]==a0[2]) && (p[3]==a0[3]) && (p[4]==a0[4]);
}
//
// Operations with proxy arrays:
// * changes in target are propagated to proxy and vice versa
// * assignments where proxy is source create new independent copy
// * assignments to proxy are checked (their size must match to that of the target)
// * incorrect assignments or attempts to change length must generate exception
// * attempts to call setlength() must fail even when new size match original size
// of the array
//
alglib::boolean_1d_array targt, acopy;
targt = "[true,false,false,true]";
alglib::boolean_1d_array proxy(targt.c_ptr());
acopy = proxy;
passed = passed && targt[0] && !targt[1] && !targt[2] && targt[3];
passed = passed && proxy[0] && !proxy[1] && !proxy[2] && proxy[3];
passed = passed && acopy[0] && !acopy[1] && !acopy[2] && acopy[3];
targt[0] = false;
passed = passed && !targt[0] && !proxy[0] && acopy[0];
proxy[0] = true;
passed = passed && targt[0] && proxy[0] && acopy[0];
acopy = "[false,true,true,true]";
proxy = acopy;
passed = passed && !targt[0] && targt[1] && targt[2] && targt[3];
passed = passed && !proxy[0] && proxy[1] && proxy[2] && proxy[3];
proxy = "[true,false,true,true]";
passed = passed && targt[0] && !targt[1] && targt[2] && targt[3];
passed = passed && proxy[0] && !proxy[1] && proxy[2] && proxy[3];
try
{
acopy = "[false,true,true]";
proxy = acopy;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy = "[true,true,true]";
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(100);
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(proxy.length());
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
}
catch(...)
{ passed = false; }
try
{
//
// 1D integer
//
// Default constructor, string constructor, copy constructor, assignment constructors:
// * test that array sizes as reported by length match to what was specified
// * test item-by-item access
// * test to_string()
// * test that modification of the copied array does not change original
// * test that setlength() changes length
//
const char *s1 = "[2,3,-1]";
const char *s2 = "[5,4,3]";
const char *s3 = "[6,7,3,-4]";
const char *s4 = "[9,5,-12,-0]";
const char *s5 = "[1,7,2,1]";
const char *s6 = "[7,7,7]";
int v10 = 2, v11 = 3, v12 = -1, v10_mod = 9;
int v20 = 5, v21 = 4, v22 = 3;
int v30 = 6, v31 = 7, v32 = 3, v33 = -4, v30_mod = -6;
int v40 = 9, v41 = 5, v42 =-12, v43 = 0;
int v50 = 1, v51 = 7, v52 = 2, v53 = 1;
alglib::integer_1d_array arr_0, arr_1("[]"), arr_2(s1), arr_3(arr_2), arr_4, arr_5;
arr_4 = arr_2;
arr_5 = s2;
passed = passed && (arr_0.length()==0);
passed = passed && (arr_1.length()==0);
passed = passed && (arr_2.length()==3);
passed = passed && (arr_3.length()==3);
passed = passed && (arr_2[0]==arr_2(0)) && (arr_2[1]==arr_2(1)) && (arr_2[2]==arr_2(2));
passed = passed && (arr_2[0]==v10) && (arr_2[1]==v11) && (arr_2[2]==v12);
passed = passed && (arr_3[0]==v10) && (arr_3[1]==v11) && (arr_3[2]==v12);
passed = passed && (arr_4[0]==v10) && (arr_4[1]==v11) && (arr_4[2]==v12);
passed = passed && (arr_5[0]==v20) && (arr_5[1]==v21) && (arr_5[2]==v22);
passed = passed && (arr_2.tostring()==s1);
passed = passed && (arr_3.tostring()==s1);
passed = passed && (arr_4.tostring()==s1);
passed = passed && (arr_5.tostring()==s2);
arr_2[0] = v10_mod;
passed = passed && (arr_2[0]==v10_mod) && (arr_3[0]==v10) && (arr_4[0]==v10);
arr_5.setlength(99);
passed = passed && (arr_5.length()==99);
// setcontent/getcontent
alglib::ae_int_t a0[] = {2, 3, 1, 9, 2};
alglib::ae_int_t a0_mod = 7;
alglib::ae_int_t a0_orig = 2;
alglib::ae_int_t *p6;
alglib::integer_1d_array arr_6;
arr_6.setcontent(5, a0);
passed = passed && (arr_6[0]==a0[0]) && (arr_6[1]==a0[1]) && (arr_6[2]==a0[2]) && (arr_6[3]==a0[3]) && (arr_6[4]==a0[4]);
p6 = arr_6.getcontent();
passed = passed && (p6!=a0);
passed = passed && (p6[0]==a0[0]) && (p6[1]==a0[1]) && (p6[2]==a0[2]) && (p6[3]==a0[3]) && (p6[4]==a0[4]);
a0[0] = a0_mod;
passed = passed && (arr_6[0]!=a0[0]);
a0[0] = a0_orig;
// operations on constant arrays
{
const alglib::integer_1d_array &ac = arr_6;
passed = passed && (ac[0]==a0[0]) && (ac[1]==a0[1]) && (ac[2]==a0[2]) && (ac[3]==a0[3]) && (ac[4]==a0[4]);
passed = passed && (ac(0)==a0[0]) && (ac(1)==a0[1]) && (ac(2)==a0[2]) && (ac(3)==a0[3]) && (ac(4)==a0[4]);
const alglib::ae_int_t *p = ac.getcontent();
passed = passed && (p[0]==a0[0]) && (p[1]==a0[1]) && (p[2]==a0[2]) && (p[3]==a0[3]) && (p[4]==a0[4]);
}
//
// Operations with proxy arrays:
// * changes in target are propagated to proxy and vice versa
// * assignments where proxy is source create new independent copy
// * assignments to proxy are checked (their size must match to that of the target)
// * incorrect assignments or attempts to change length must generate exception
// * attempts to call setlength() must fail even when new size match original size
// of the array
//
alglib::integer_1d_array targt, acopy;
targt = s3;
alglib::integer_1d_array proxy(targt.c_ptr());
acopy = proxy;
passed = passed && (targt[0]==v30) && (targt[1]==v31) && (targt[2]==v32) && (targt[3]==v33);
passed = passed && (proxy[0]==v30) && (proxy[1]==v31) && (proxy[2]==v32) && (proxy[3]==v33);
passed = passed && (acopy[0]==v30) && (acopy[1]==v31) && (acopy[2]==v32) && (acopy[3]==v33);
targt[0] = v30_mod;
passed = passed && (targt[0]==v30_mod) && (proxy[0]==v30_mod) && (acopy[0]==v30);
proxy[0] = v30;
passed = passed && (targt[0]==v30) && (proxy[0]==v30) && (acopy[0]==v30);
acopy = s4;
proxy = acopy;
passed = passed && (targt[0]==v40) && (targt[1]==v41) && (targt[2]==v42) && (targt[3]==v43);
passed = passed && (proxy[0]==v40) && (proxy[1]==v41) && (proxy[2]==v42) && (proxy[3]==v43);
proxy = s5;
passed = passed && (targt[0]==v50) && (targt[1]==v51) && (targt[2]==v52) && (targt[3]==v53);
passed = passed && (proxy[0]==v50) && (proxy[1]==v51) && (proxy[2]==v52) && (proxy[3]==v53);
try
{
acopy = s6;
proxy = acopy;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy = s6;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(100);
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(proxy.length());
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
}
catch(...)
{ passed = false; }
try
{
//
// 1D real
//
// Default constructor, string constructor, copy constructor, assignment constructors:
// * test that array sizes as reported by length match to what was specified
// * test item-by-item access
// * test to_string()
// * test that modification of the copied array does not change original
// * test that setlength() changes length
//
const char *s1 = "[2,3.5,-2.5E-1]";
const char *s1_fmt = "[2.00,3.50,-0.25]";
const char *s2 = "[5,4,3.126]";
const char *s2_fmt = "[5.00,4.00,3.13]";
const char *s3 = "[6,7,3,-4E2]";
const char *s4 = "[9,5,-12,-0.01]";
const char *s5 = "[1,7,2,1]";
const char *s6 = "[7,7,7]";
const int dps = 2;
const double v10 = 2, v11 = 3.5, v12 = -0.25, v10_mod = 9;
const double v20 = 5, v21 = 4, v22 = 3.126;
const double v30 = 6, v31 = 7, v32 = 3, v33 = -400, v30_mod = -6;
const double v40 = 9, v41 = 5, v42 =-12, v43 = -0.01;
const double v50 = 1, v51 = 7, v52 = 2, v53 = 1;
alglib::real_1d_array arr_0, arr_1("[]"), arr_2(s1), arr_3(arr_2), arr_4, arr_5;
arr_4 = arr_2;
arr_5 = s2;
passed = passed && (arr_0.length()==0);
passed = passed && (arr_1.length()==0);
passed = passed && (arr_2.length()==3);
passed = passed && (arr_3.length()==3);
passed = passed && (arr_2[0]==arr_2(0)) && (arr_2[1]==arr_2(1)) && (arr_2[2]==arr_2(2));
passed = passed && (arr_2[0]==v10) && (arr_2[1]==v11) && (arr_2[2]==v12);
passed = passed && (arr_3[0]==v10) && (arr_3[1]==v11) && (arr_3[2]==v12);
passed = passed && (arr_4[0]==v10) && (arr_4[1]==v11) && (arr_4[2]==v12);
passed = passed && (arr_5[0]==v20) && (arr_5[1]==v21) && (arr_5[2]==v22);
passed = passed && (arr_2.tostring(dps)==s1_fmt);
passed = passed && (arr_3.tostring(dps)==s1_fmt);
passed = passed && (arr_4.tostring(dps)==s1_fmt);
passed = passed && (arr_5.tostring(dps)==s2_fmt);
arr_2[0] = v10_mod;
passed = passed && (arr_2[0]==v10_mod) && (arr_3[0]==v10) && (arr_4[0]==v10);
arr_5.setlength(99);
passed = passed && (arr_5.length()==99);
// setcontent/getcontent
double a0[] = {2, 3.5, 1, 9.125, 2};
double a0_mod = 7;
double a0_orig = 2;
double *p6;
alglib::real_1d_array arr_6;
arr_6.setcontent(5, a0);
passed = passed && (arr_6[0]==a0[0]) && (arr_6[1]==a0[1]) && (arr_6[2]==a0[2]) && (arr_6[3]==a0[3]) && (arr_6[4]==a0[4]);
p6 = arr_6.getcontent();
passed = passed && (p6!=a0);
passed = passed && (p6[0]==a0[0]) && (p6[1]==a0[1]) && (p6[2]==a0[2]) && (p6[3]==a0[3]) && (p6[4]==a0[4]);
a0[0] = a0_mod;
passed = passed && (arr_6[0]!=a0[0]);
a0[0] = a0_orig;
// operations on constant arrays
{
const alglib::real_1d_array &ac = arr_6;
passed = passed && (ac[0]==a0[0]) && (ac[1]==a0[1]) && (ac[2]==a0[2]) && (ac[3]==a0[3]) && (ac[4]==a0[4]);
passed = passed && (ac(0)==a0[0]) && (ac(1)==a0[1]) && (ac(2)==a0[2]) && (ac(3)==a0[3]) && (ac(4)==a0[4]);
const double *p = ac.getcontent();
passed = passed && (p[0]==a0[0]) && (p[1]==a0[1]) && (p[2]==a0[2]) && (p[3]==a0[3]) && (p[4]==a0[4]);
}
//
// Operations with proxy arrays attached via attach_to(ae_vector*):
// * changes in target are propagated to proxy and vice versa
// * assignments where proxy is source create new independent copy
// * assignments to proxy are checked (their size must match to that of the target)
// * incorrect assignments or attempts to change length must generate exception
// * attempts to call setlength() must fail even when new size match original size
// of the array
//
{
alglib::real_1d_array targt, acopy;
targt = s3;
alglib::real_1d_array proxy(targt.c_ptr());
acopy = proxy;
passed = passed && (targt[0]==v30) && (targt[1]==v31) && (targt[2]==v32) && (targt[3]==v33);
passed = passed && (proxy[0]==v30) && (proxy[1]==v31) && (proxy[2]==v32) && (proxy[3]==v33);
passed = passed && (acopy[0]==v30) && (acopy[1]==v31) && (acopy[2]==v32) && (acopy[3]==v33);
targt[0] = v30_mod;
passed = passed && (targt[0]==v30_mod) && (proxy[0]==v30_mod) && (acopy[0]==v30);
proxy[0] = v30;
passed = passed && (targt[0]==v30) && (proxy[0]==v30) && (acopy[0]==v30);
acopy = s4;
proxy = acopy;
passed = passed && (targt[0]==v40) && (targt[1]==v41) && (targt[2]==v42) && (targt[3]==v43);
passed = passed && (proxy[0]==v40) && (proxy[1]==v41) && (proxy[2]==v42) && (proxy[3]==v43);
proxy = s5;
passed = passed && (targt[0]==v50) && (targt[1]==v51) && (targt[2]==v52) && (targt[3]==v53);
passed = passed && (proxy[0]==v50) && (proxy[1]==v51) && (proxy[2]==v52) && (proxy[3]==v53);
try
{
acopy = s6;
proxy = acopy;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy = s6;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(100);
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(proxy.length());
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
}
//
// >>> Unique for real_1d_array >>>
//
// Operations with proxy arrays attached via attach_to(double*):
// * changes in target are propagated to proxy and vice versa
// * assignments where proxy is source create new independent copy
// * assignments to proxy are checked (their size must match to that of the target)
// * incorrect assignments or attempts to change length must generate exception
// * attempts to call setlength() must fail even when new size match original size
// of the array
//
{
alglib::real_1d_array proxy, acopy;
double targt[] = {v30, v31, v32, v33};
proxy.attach_to_ptr(4, targt);
acopy = proxy;
passed = passed && (targt[0]==v30) && (targt[1]==v31) && (targt[2]==v32) && (targt[3]==v33);
passed = passed && (proxy[0]==v30) && (proxy[1]==v31) && (proxy[2]==v32) && (proxy[3]==v33);
passed = passed && (acopy[0]==v30) && (acopy[1]==v31) && (acopy[2]==v32) && (acopy[3]==v33);
targt[0] = v30_mod;
passed = passed && (targt[0]==v30_mod) && (proxy[0]==v30_mod) && (acopy[0]==v30);
proxy[0] = v30;
passed = passed && (targt[0]==v30) && (proxy[0]==v30) && (acopy[0]==v30);
acopy = s4;
proxy = acopy;
passed = passed && (targt[0]==v40) && (targt[1]==v41) && (targt[2]==v42) && (targt[3]==v43);
passed = passed && (proxy[0]==v40) && (proxy[1]==v41) && (proxy[2]==v42) && (proxy[3]==v43);
proxy = s5;
passed = passed && (targt[0]==v50) && (targt[1]==v51) && (targt[2]==v52) && (targt[3]==v53);
passed = passed && (proxy[0]==v50) && (proxy[1]==v51) && (proxy[2]==v52) && (proxy[3]==v53);
try
{
acopy = s6;
proxy = acopy;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy = s6;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(100);
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(proxy.length());
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
}
}
catch(...)
{ passed = false; }
try
{
//
// 1D complex
//
// Default constructor, string constructor, copy constructor, assignment constructors:
// * test that array sizes as reported by length match to what was specified
// * test item-by-item access
// * test to_string()
// * test that modification of the copied array does not change original
// * test that setlength() changes length
//
const char *s1 = "[2,3.5i,1-2.5E-1i]";
const char *s1_fmt = "[2.00,3.50i,1.00-0.25i]";
const char *s2 = "[5,-4+1i,3.126]";
const char *s2_fmt = "[5.00,-4.00+1.00i,3.13]";
const char *s3 = "[6,7,3,-4E2]";
const char *s4 = "[9,5,-12,-0.01]";
const char *s5 = "[1,7,2,1]";
const char *s6 = "[7,7,7]";
const int dps = 2;
alglib::complex v10 = 2, v11 = alglib::complex(0,3.5), v12 = alglib::complex(1,-0.25), v10_mod = 9;
alglib::complex v20 = 5, v21 = alglib::complex(-4,1), v22 = 3.126;
alglib::complex v30 = 6, v31 = 7, v32 = 3, v33 = -400, v30_mod = -6;
alglib::complex v40 = 9, v41 = 5, v42 =-12, v43 = -0.01;
alglib::complex v50 = 1, v51 = 7, v52 = 2, v53 = 1;
alglib::complex_1d_array arr_0, arr_1("[]"), arr_2(s1), arr_3(arr_2), arr_4, arr_5;
arr_4 = arr_2;
arr_5 = s2;
passed = passed && (arr_0.length()==0);
passed = passed && (arr_1.length()==0);
passed = passed && (arr_2.length()==3);
passed = passed && (arr_3.length()==3);
passed = passed && (arr_2[0]==arr_2(0)) && (arr_2[1]==arr_2(1)) && (arr_2[2]==arr_2(2));
passed = passed && (arr_2[0]==v10) && (arr_2[1]==v11) && (arr_2[2]==v12);
passed = passed && (arr_3[0]==v10) && (arr_3[1]==v11) && (arr_3[2]==v12);
passed = passed && (arr_4[0]==v10) && (arr_4[1]==v11) && (arr_4[2]==v12);
passed = passed && (arr_5[0]==v20) && (arr_5[1]==v21) && (arr_5[2]==v22);
passed = passed && (arr_2.tostring(dps)==s1_fmt);
passed = passed && (arr_3.tostring(dps)==s1_fmt);
passed = passed && (arr_4.tostring(dps)==s1_fmt);
passed = passed && (arr_5.tostring(dps)==s2_fmt);
arr_2[0] = v10_mod;
passed = passed && (arr_2[0]==v10_mod) && (arr_3[0]==v10) && (arr_4[0]==v10);
arr_5.setlength(99);
passed = passed && (arr_5.length()==99);
// setcontent/getcontent
alglib::complex a0[] = {2, 3.5, 1, 9.125, 2};
alglib::complex a0_mod = 7;
alglib::complex a0_orig = 2;
alglib::complex *p6;
alglib::complex_1d_array arr_6;
arr_6.setcontent(5, a0);
passed = passed && (arr_6[0]==a0[0]) && (arr_6[1]==a0[1]) && (arr_6[2]==a0[2]) && (arr_6[3]==a0[3]) && (arr_6[4]==a0[4]);
p6 = arr_6.getcontent();
passed = passed && (p6!=a0);
passed = passed && (p6[0]==a0[0]) && (p6[1]==a0[1]) && (p6[2]==a0[2]) && (p6[3]==a0[3]) && (p6[4]==a0[4]);
a0[0] = a0_mod;
passed = passed && (arr_6[0]!=a0[0]);
a0[0] = a0_orig;
// operations on constant arrays
{
const alglib::complex_1d_array &ac = arr_6;
passed = passed && (ac[0]==a0[0]) && (ac[1]==a0[1]) && (ac[2]==a0[2]) && (ac[3]==a0[3]) && (ac[4]==a0[4]);
passed = passed && (ac(0)==a0[0]) && (ac(1)==a0[1]) && (ac(2)==a0[2]) && (ac(3)==a0[3]) && (ac(4)==a0[4]);
const alglib::complex *p = ac.getcontent();
passed = passed && (p[0]==a0[0]) && (p[1]==a0[1]) && (p[2]==a0[2]) && (p[3]==a0[3]) && (p[4]==a0[4]);
}
//
// Operations with proxy arrays:
// * changes in target are propagated to proxy and vice versa
// * assignments where proxy is source create new independent copy
// * assignments to proxy are checked (their size must match to that of the target)
// * incorrect assignments or attempts to change length must generate exception
// * attempts to call setlength() must fail even when new size match original size
// of the array
//
alglib::complex_1d_array targt, acopy;
targt = s3;
alglib::complex_1d_array proxy(targt.c_ptr());
acopy = proxy;
passed = passed && (targt[0]==v30) && (targt[1]==v31) && (targt[2]==v32) && (targt[3]==v33);
passed = passed && (proxy[0]==v30) && (proxy[1]==v31) && (proxy[2]==v32) && (proxy[3]==v33);
passed = passed && (acopy[0]==v30) && (acopy[1]==v31) && (acopy[2]==v32) && (acopy[3]==v33);
targt[0] = v30_mod;
passed = passed && (targt[0]==v30_mod) && (proxy[0]==v30_mod) && (acopy[0]==v30);
proxy[0] = v30;
passed = passed && (targt[0]==v30) && (proxy[0]==v30) && (acopy[0]==v30);
acopy = s4;
proxy = acopy;
passed = passed && (targt[0]==v40) && (targt[1]==v41) && (targt[2]==v42) && (targt[3]==v43);
passed = passed && (proxy[0]==v40) && (proxy[1]==v41) && (proxy[2]==v42) && (proxy[3]==v43);
proxy = s5;
passed = passed && (targt[0]==v50) && (targt[1]==v51) && (targt[2]==v52) && (targt[3]==v53);
passed = passed && (proxy[0]==v50) && (proxy[1]==v51) && (proxy[2]==v52) && (proxy[3]==v53);
try
{
acopy = s6;
proxy = acopy;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy = s6;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(100);
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
try
{
proxy.setlength(proxy.length());
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
}
catch(...)
{ passed = false; }
//
// Report
//
printf(fmt_str, "* 1D arrays", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}
{
//
// Testing 2D array functionality
//
bool passed = true;
try
{
//
// 2D real
//
// Default constructor, string constructor, copy constructor, assignment constructors:
// * test that array sizes as reported by length match to what was specified
// * test item-by-item access
// * test to_string()
// * test that modification of the copied array does not change original
// * test that setlength() changes length
//
const char *s1 = "[[2,3.5,-2.5E-1],[1,2,3]]";
const char *s1_fmt = "[[2.00,3.50,-0.25],[1.00,2.00,3.00]]";
const char *s2 = "[[5],[4],[3.126]]";
const char *s2_fmt = "[[5.00],[4.00],[3.13]]";
const char *s3 = "[[6,7],[3,-4E2],[-3,-1]]";
const char *s4 = "[[9,5],[-12,-0.01],[-1,-2]]";
const char *s5 = "[[1,7],[2,1],[0,4]]";
const char *s60 = "[[7,7],[7,7]]";
const char *s61 = "[[7],[7],[7]]";
const int dps = 2;
const double v10 = 2, v11 = 3.5, v12 = -0.25, v13=1, v14 = 2, v15 = 3, v10_mod = 9;
const double v20 = 5, v21 = 4, v22 = 3.126;
const double v30 = 6, v31 = 7, v32 = 3, v33 = -400, v34=-3, v35=-1, v30_mod = -6;
/*double v40 = 9, v41 = 5, v42 =-12, v43 = -0.01;
double v50 = 1, v51 = 7, v52 = 2, v53 = 1;*/
double r;
alglib::real_2d_array arr_0, arr_1("[[]]"), arr_2(s1), arr_3(arr_2), arr_4, arr_5;
arr_4 = arr_2;
arr_5 = s2;
passed = passed && (arr_0.rows()==0) && (arr_0.cols()==0) && (arr_0.getstride()==0);
passed = passed && (arr_1.rows()==0) && (arr_1.cols()==0) && (arr_1.getstride()==0);
passed = passed && (arr_2.rows()==2) && (arr_2.cols()==3) && (arr_2.getstride()>=arr_2.cols());
passed = passed && (arr_3.rows()==2) && (arr_3.cols()==3) && (arr_3.getstride()>=arr_3.cols());
passed = passed && (arr_4.rows()==2) && (arr_4.cols()==3) && (arr_4.getstride()>=arr_4.cols());
passed = passed && (arr_5.rows()==3) && (arr_5.cols()==1) && (arr_5.getstride()>=arr_5.cols());
passed = passed && (arr_2[0][0]==arr_2(0,0)) && (arr_2[0][1]==arr_2(0,1)) && (arr_2[0][2]==arr_2(0,2));
passed = passed && (arr_2[1][0]==arr_2(1,0)) && (arr_2[1][1]==arr_2(1,1)) && (arr_2[1][2]==arr_2(1,2));
passed = passed && (arr_2[0][0]==v10) && (arr_2[0][1]==v11) && (arr_2[0][2]==v12);
passed = passed && (arr_2[1][0]==v13) && (arr_2[1][1]==v14) && (arr_2[1][2]==v15);
passed = passed && (arr_3[0][0]==v10) && (arr_3[0][1]==v11) && (arr_3[0][2]==v12);
passed = passed && (arr_3[1][0]==v13) && (arr_3[1][1]==v14) && (arr_3[1][2]==v15);
passed = passed && (arr_4[0][0]==v10) && (arr_4[0][1]==v11) && (arr_4[0][2]==v12);
passed = passed && (arr_4[1][0]==v13) && (arr_4[1][1]==v14) && (arr_4[1][2]==v15);
passed = passed && (arr_5[0][0]==v20) && (arr_5[1][0]==v21) && (arr_5[2][0]==v22);
passed = passed && (arr_2.tostring(dps)==s1_fmt);
passed = passed && (arr_3.tostring(dps)==s1_fmt);
passed = passed && (arr_4.tostring(dps)==s1_fmt);
passed = passed && (arr_5.tostring(dps)==s2_fmt);
arr_2[0][0] = v10_mod;
passed = passed && (arr_2[0][0]==v10_mod) && (arr_3[0][0]==v10) && (arr_4[0][0]==v10);
arr_5.setlength(99,97);
passed = passed && (arr_5.rows()==99) && (arr_5.cols()==97);
//
// setcontent/elementwise access/constant arrays
//
ae_int_t n, m, i, j;
for(n=1; n<=10; n++)
for(m=1; m<=10; m++)
{
alglib::real_2d_array arr_6;
double a0[100];
// fill array by random values, test setcontent(0
for(i=0; i<m*n; i++)
a0[i] = alglib::randomreal();
arr_6.setcontent(m, n, a0);
for(i=0; i<m; i++)
for(j=0; j<n; j++)
{
passed = passed && (arr_6[i][j]==a0[i*n+j]);
passed = passed && (arr_6(i,j)==a0[i*n+j]);
}
// test that setcontent() actually copies data instead of creating just reference
r = a0[0];
a0[0] = a0[0]+1;
passed = passed && (arr_6[0][0]!=a0[0]);
a0[0] = r;
// operations on constant arrays
{
const alglib::real_2d_array &ac = arr_6;
for(i=0; i<m; i++)
for(j=0; j<n; j++)
{
passed = passed && (ac[i][j]==a0[i*n+j]);
passed = passed && (ac(i,j)==a0[i*n+j]);
}
}
}
//
// Operations with proxy arrays:
// * changes in target are propagated to proxy and vice versa
// * assignments where proxy is source create new independent copy
// * assignments to proxy are checked (their size must match to that of the target)
// * incorrect assignments or attempts to change length must generate exception
// * attempts to call setlength() must fail even when new size match original size
// of the array
//
{ // test attach_to(ae_matrix*)
// subtest 0
alglib::real_2d_array targt, acopy, acopy2;
targt = s3;
alglib::real_2d_array proxy(targt.c_ptr());
acopy = proxy;
for(i=0; i<targt.rows(); i++)
for(j=0; j<targt.cols(); j++)
{
passed = passed && (proxy[i][j]==targt[i][j]);
passed = passed && (acopy[i][j]==targt[i][j]);
}
r = targt[0][0];
targt[0][0] = r+1;
passed = passed && (targt[0][0]!=r) && (proxy[0][0]!=r) && (acopy[0][0]==r);
proxy[0][0] = r;
passed = passed && (targt[0][0]==r) && (proxy[0][0]==r) && (acopy[0][0]==r);
// subtest 1
acopy = s4;
proxy = acopy;
for(i=0; i<acopy.rows(); i++)
for(j=0; j<acopy.cols(); j++)
{
passed = passed && (proxy[i][j]==acopy[i][j]);
passed = passed && (targt[i][j]==acopy[i][j]);
}
r = targt[0][0];
targt[0][0] = r+1;
passed = passed && (targt[0][0]!=r) && (proxy[0][0]!=r) && (acopy[0][0]==r);
proxy[0][0] = r;
passed = passed && (targt[0][0]==r) && (proxy[0][0]==r) && (acopy[0][0]==r);
// subtest 2
acopy2 = s5;
proxy = s5;
for(i=0; i<acopy.rows(); i++)
for(j=0; j<acopy.cols(); j++)
{
passed = passed && (proxy[i][j]==acopy2[i][j]);
passed = passed && (targt[i][j]==acopy2[i][j]);
}
// error handling test 0
try
{
acopy = s60;
proxy = acopy;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 1
try
{
acopy = s61;
proxy = acopy;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 2
try
{
proxy = s60;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 3
try
{
proxy = s61;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 4
try
{
proxy.setlength(100,99);
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 5
try
{
proxy.setlength(proxy.rows(),proxy.cols());
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
}
{ // test attach_to(double*)
// subtest 0
alglib::real_2d_array proxy, acopy, acopy2;
double targt[] = {v30, v31, v32, v33, v34, v35};
const int NCOLS = 2;
proxy.attach_to_ptr(3, 2, targt);
acopy = proxy;
for(i=0; i<proxy.rows(); i++)
for(j=0; j<proxy.cols(); j++)
{
passed = passed && (proxy[i][j]==targt[i*NCOLS+j]);
passed = passed && (acopy[i][j]==targt[i*NCOLS+j]);
}
r = targt[0*NCOLS+0];
targt[0*NCOLS+0] = r+1;
passed = passed && (targt[0*NCOLS+0]!=r) && (proxy[0][0]!=r) && (acopy[0][0]==r);
proxy[0][0] = r;
passed = passed && (targt[0*NCOLS+0]==r) && (proxy[0][0]==r) && (acopy[0][0]==r);
// subtest 1
acopy = s4;
proxy = acopy;
for(i=0; i<acopy.rows(); i++)
for(j=0; j<acopy.cols(); j++)
{
passed = passed && (proxy[i][j]==acopy[i][j]);
passed = passed && (targt[i*NCOLS+j]==acopy[i][j]);
}
r = targt[0*NCOLS+0];
targt[0*NCOLS+0] = r+1;
passed = passed && (targt[0*NCOLS+0]!=r) && (proxy[0][0]!=r) && (acopy[0][0]==r);
proxy[0][0] = r;
passed = passed && (targt[0*NCOLS+0]==r) && (proxy[0][0]==r) && (acopy[0][0]==r);
// subtest 2
acopy2 = s5;
proxy = s5;
for(i=0; i<acopy.rows(); i++)
for(j=0; j<acopy.cols(); j++)
{
passed = passed && (proxy[i][j]==acopy2[i][j]);
passed = passed && (targt[i*NCOLS+j]==acopy2[i][j]);
}
// error handling test 0
try
{
acopy = s60;
proxy = acopy;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 1
try
{
acopy = s61;
proxy = acopy;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 2
try
{
proxy = s60;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 3
try
{
proxy = s61;
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 4
try
{
proxy.setlength(100,99);
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
// error handling test 5
try
{
proxy.setlength(proxy.rows(),proxy.cols());
passed = false;
}
catch(alglib::ap_error e)
{ }
catch(...)
{ passed = false; }
}
}
catch(...)
{ passed = false; }
//
// Report
//
printf(fmt_str, "* 2D arrays", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}
{
//
// Testing CSV functionality
//
const char *csv_name = "alglib-tst-35252-ndg4sf.csv";
bool passed = true;
try
{
// CSV_DEFAULT must be zero
passed = passed && alglib::CSV_DEFAULT==0;
// absent file - must fail
try
{
alglib::real_2d_array arr;
read_csv("nonexistent123foralgtestinglib", '\t', alglib::CSV_DEFAULT, arr);
passed = false;
}
catch(alglib::ap_error)
{ }
catch(...)
{ passed = false; }
// non-rectangular file - must fail
try
{
alglib::real_2d_array arr;
file_put_contents(csv_name, "a,b,c\r\n1,2");
read_csv(csv_name, ',', alglib::CSV_SKIP_HEADERS, arr);
remove(csv_name);
passed = false;
}
catch(alglib::ap_error)
{ }
catch(...)
{ passed = false; }
try
{
alglib::real_2d_array arr;
file_put_contents(csv_name, "a,b,c\r\n1,2,3,4");
read_csv(csv_name, ',', alglib::CSV_SKIP_HEADERS, arr);
remove(csv_name);
passed = false;
}
catch(alglib::ap_error)
{ }
catch(...)
{ passed = false; }
try
{
alglib::real_2d_array arr;
file_put_contents(csv_name, "1,2,3,4\n1,2,3\n1,2,3");
read_csv(csv_name, ',', alglib::CSV_DEFAULT, arr);
remove(csv_name);
passed = false;
}
catch(alglib::ap_error)
{ }
catch(...)
{ passed = false; }
// empty file
try
{
alglib::real_2d_array arr;
file_put_contents(csv_name, "");
read_csv(csv_name, '\t', alglib::CSV_DEFAULT, arr);
remove(csv_name);
passed = passed && arr.rows()==0 && arr.cols()==0;
}
catch(...)
{ passed = false; }
// one row with header, tab separator
try
{
alglib::real_2d_array arr;
file_put_contents(csv_name, "a\tb\tc\n");
read_csv(csv_name, '\t', alglib::CSV_SKIP_HEADERS, arr);
remove(csv_name);
passed = passed && arr.rows()==0 && arr.cols()==0;
}
catch(...)
{ passed = false; }
// no header, comma-separated, full stop as decimal point
try
{
alglib::real_2d_array arr;
file_put_contents(csv_name, "1.5,2,3.25\n4,5,6");
read_csv(csv_name, ',', alglib::CSV_DEFAULT, arr);
remove(csv_name);
passed = passed && arr.tostring(2)=="[[1.50,2.00,3.25],[4.00,5.00,6.00]]";
}
catch(...)
{ passed = false; }
// header, tab-separated, mixed use of comma and full stop as decimal points
try
{
alglib::real_2d_array arr;
file_put_contents(csv_name, "a\tb\tc\n1.5\t2\t3,25\n4\t5.25\t6,1\n");
read_csv(csv_name, '\t', alglib::CSV_SKIP_HEADERS, arr);
remove(csv_name);
passed = passed && arr.tostring(2)=="[[1.50,2.00,3.25],[4.00,5.25,6.10]]";
}
catch(...)
{ passed = false; }
// header, tab-separated, fixed/exponential, spaces, mixed use of comma and full stop as decimal points
try
{
alglib::real_2d_array arr;
file_put_contents(csv_name, " a\t b \tc\n1,1\t 2.9\t -3.5 \n 1.1E1 \t 2.0E-1 \t-3E+1 \n+1 \t -2\t 3. \n.1\t-.2\t+.3\n");
read_csv(csv_name, '\t', alglib::CSV_SKIP_HEADERS, arr);
remove(csv_name);
passed = passed && arr.tostring(2)=="[[1.10,2.90,-3.50],[11.00,0.20,-30.00],[1.00,-2.00,3.00],[0.10,-0.20,0.30]]";
}
catch(...)
{ passed = false; }
}
catch(...)
{ passed = false; }
//
// Report
//
printf(fmt_str, "* CSV support", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}
//
// Serialization properties
//
{
//
// Test kd-tree serialization
//
bool passed = true;
alglib::hqrndstate rs;
alglib::kdtree tree0;
alglib::real_2d_array xy, rxy0, rxy1;
alglib::real_1d_array qx;
const int npts = 50;
const int nx = 2;
const int ny = 1;
int cnt0, cnt1;
alglib::hqrndrandomize(rs);
xy.setlength(npts, nx+ny);
for(int i=0; i<npts; i++)
for(int j=0; j<nx+ny; j++)
xy[i][j] = alglib::hqrndnormal(rs);
alglib::kdtreebuild(xy, npts, nx, ny, 2, tree0);
qx.setlength(nx);
try
{
// test string serialization/unserialization
alglib::kdtree tree1;
std::string s;
alglib::kdtreeserialize(tree0, s);
alglib::kdtreeunserialize(s, tree1);
for(int i=0; i<100; i++)
{
for(int j=0; j<nx; j++)
qx[j] = alglib::hqrndnormal(rs);
cnt0 = alglib::kdtreequeryknn(tree0, qx, 1, true);
cnt1 = alglib::kdtreequeryknn(tree1, qx, 1, true);
if( (cnt0!=1) || (cnt1!=1) )
{
passed = false;
break;
}
alglib::kdtreequeryresultsxy(tree0, rxy0);
alglib::kdtreequeryresultsxy(tree1, rxy1);
for(int j=0; j<nx+ny; j++)
passed = passed && (rxy0[0][j]==rxy1[0][j]);
}
}
catch(...)
{ passed = false; }
try
{
// test stream serialization/unserialization
//
// NOTE: we add a few symbols at the beginning and after the end of the data
// in order to test algorithm ability to work in the middle of the stream
alglib::kdtree tree1;
std::stringstream s;
s.put('b');
s.put('e');
s.put('g');
alglib::kdtreeserialize(tree0, s);
s.put('e');
s.put('n');
s.put('d');
s.seekg(0);
passed = passed && (s.get()=='b');
passed = passed && (s.get()=='e');
passed = passed && (s.get()=='g');
alglib::kdtreeunserialize(s, tree1);
passed = passed && (s.get()=='e');
passed = passed && (s.get()=='n');
passed = passed && (s.get()=='d');
for(int i=0; i<100; i++)
{
for(int j=0; j<nx; j++)
qx[j] = alglib::hqrndnormal(rs);
cnt0 = alglib::kdtreequeryknn(tree0, qx, 1, true);
cnt1 = alglib::kdtreequeryknn(tree1, qx, 1, true);
if( (cnt0!=1) || (cnt1!=1) )
{
passed = false;
break;
}
alglib::kdtreequeryresultsxy(tree0, rxy0);
alglib::kdtreequeryresultsxy(tree1, rxy1);
for(int j=0; j<nx+ny; j++)
passed = passed && (rxy0[0][j]==rxy1[0][j]);
}
}
catch(...)
{ passed = false; }
try
{
// test string-to-stream serialization/unserialization
alglib::kdtree tree1;
std::string s0;
alglib::kdtreeserialize(tree0, s0);
std::stringstream s1(s0);
alglib::kdtreeunserialize(s1, tree1);
for(int i=0; i<100; i++)
{
for(int j=0; j<nx; j++)
qx[j] = alglib::hqrndnormal(rs);
cnt0 = alglib::kdtreequeryknn(tree0, qx, 1, true);
cnt1 = alglib::kdtreequeryknn(tree1, qx, 1, true);
if( (cnt0!=1) || (cnt1!=1) )
{
passed = false;
break;
}
alglib::kdtreequeryresultsxy(tree0, rxy0);
alglib::kdtreequeryresultsxy(tree1, rxy1);
for(int j=0; j<nx+ny; j++)
passed = passed && (rxy0[0][j]==rxy1[0][j]);
}
}
catch(...)
{ passed = false; }
try
{
// test stream-to-string serialization/unserialization
alglib::kdtree tree1;
std::stringstream s0;
alglib::kdtreeserialize(tree0, s0);
std::string s1 = s0.str();
alglib::kdtreeunserialize(s1, tree1);
for(int i=0; i<100; i++)
{
for(int j=0; j<nx; j++)
qx[j] = alglib::hqrndnormal(rs);
cnt0 = alglib::kdtreequeryknn(tree0, qx, 1, true);
cnt1 = alglib::kdtreequeryknn(tree1, qx, 1, true);
if( (cnt0!=1) || (cnt1!=1) )
{
passed = false;
break;
}
alglib::kdtreequeryresultsxy(tree0, rxy0);
alglib::kdtreequeryresultsxy(tree1, rxy1);
for(int j=0; j<nx+ny; j++)
passed = passed && (rxy0[0][j]==rxy1[0][j]);
}
}
catch(...)
{ passed = false; }
//
// Report
//
printf(fmt_str, "* Serialization (kd-tree)", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}
{
//
// Test legacy RBF interface
//
const char *pc_str = "50000000000 00000000000 20000000000 10000000000 A0000000000 \
30000000000 20000000000 00000000000 A0000000000 30000000000\r\
00000000000 20000000000 A0000000000 60000000000 00000000000\n\
00000000000 00000000000 00000000000 00000000000 00000000000\r\n\
00000000m_3 00000000000 00000000000 00000000m_3 00000000000\n\r\
00000000000 00000000004 00000000000 00000000000\t00000000004 \
00000000000 00000000000 00000000804 00000000000 00000000000 \
00000000804 00000000000 00000000000 00000000G04 00000000000 \
00000000000 00000000G04 00000000000 00000000000 00000000O04 \
00000000000 00000000000 00000000O04 00000000000 00000000000 \
00000000S04 00000000000 00000000000 00000000S04 00000000000 \
00000000000 00000000W04 00000000000 00000000000 00000000W04 \
00000000000 00000000000 00000000Y04 00000000000 00000000000 \
00000000Y04 00000000000 00000000000 00000000K04 00000000000 \
00000000000 00000000K04 00000000000 00000000000 A0000000000 \
00000000000 10000000000 20000000000 30000000000 40000000000 \
60000000000 70000000000 80000000000 90000000000 50000000000 \
30000000000 00000000000 00000000000 00000000000 30000000000 \
00000000Y04 00000000000 00000000000 u1000000000 00000000000 \
00000000000 00000000000 60000000000 80000000000 00000000000 \
50000000000 00000000000 50000000000 50000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 K0000000000 \
00000000I04 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
00000000000 00000000000 00000000000 00000000000 00000000000 \
A0000000000 30000000000 00000000000 00000000000 00000000000 \
00000000m_3 00000000000 00000000000 00000000004 00000000000 \
00000000000 00000000804 00000000000 00000000000 00000000G04 \
00000000000 00000000000 00000000K04 00000000000 00000000000 \
00000000O04 00000000000 00000000000 00000000S04 00000000000 \
00000000000 00000000W04 00000000000 00000000000 00000000Y04 \
00000000000 00000000000 A0000000000 40000000000 00000000q04 \
-pAGQnQBI14 UqUWierJ91C esm8ag6G61C 00000000q04 4wcFMyCtu04 \
oPDvwHqst04 CExQXp8Ct04 00000000q04 litzPFhRb0C oKJvjcct314 \
5-fT-X8w614 00000000q04 3HSOsPVH11C vZWf4dgfv04 GbZg4MTJn04 \
00000000q04 iv7rMhuR71C hRtixp15r_3 EvCEDtLu-0C 00000000q04 \
41CXzA_q71C umRYLK2yp0C 1zzY3Zqd91C 00000000q04 JvxJzDeI21C \
TVbyd7Ygz0C JLywRdR1n0C 00000000q04 KmFarhc4g0C 1ehrn2tUt0C \
AECfwTIX814 00000000q04 Big__6hwt04 nSPzmAQrh_B 2H3o-KftH14 \
00000000q04 n1b9361vI14 mhJhviUE114 54a_qyBrH1C 00000000q04 \
10000000000 40000000000 StLCgor39-3 00000000000 00000000000 \
6qTG7Ae-1_3\n";
alglib::real_1d_array ref_val("[-0.042560546916643, 0.942523544654062, 0.875197036560778, 0.0656948997826632, -0.743065973803404, -0.8903682039297, -0.26994815318748, 0.602248517290195, 0.980011992233124, 0.436594293214176]");
bool passed = true;
try
{
// test unserialization from string without trailing end-of-stream symbol (dot)
// this test is necessary for backward compatibility
double eps = 0.0000000001;
alglib::rbfmodel model;
alglib::rbfunserialize(std::string(pc_str), model);
for(int i=0; i<ref_val.length(); i++)
passed = passed && (fabs(alglib::rbfcalc2(model,i,0)-ref_val[i])<eps);
}
catch(...)
{ passed = false; }
try
{
// test unserialization from string with trailing end-of-stream symbol (dot)
// this test is necessary for forward compatibility
double eps = 0.0000000001;
alglib::rbfmodel model;
alglib::rbfunserialize(std::string(pc_str)+".", model);
for(int i=0; i<ref_val.length(); i++)
passed = passed && (fabs(alglib::rbfcalc2(model,i,0)-ref_val[i])<eps);
}
catch(...)
{ passed = false; }
try
{
// test unserialization from stream WITHOUT trailing end-of-stream symbol (dot)
// this test MUST fail
double eps = 0.0000000001;
std::string _s(pc_str);
std::istringstream stream(_s);
alglib::rbfmodel model;
alglib::rbfunserialize(stream, model);
passed = false;
}
catch(...)
{ /* do nothing, it is expected to fail */ }
try
{
// test unserialization from stream WITH trailing end-of-stream symbol (dot)
// this test must succeed
double eps = 0.0000000001;
std::string _s = std::string(pc_str)+".";
std::istringstream stream(_s);
alglib::rbfmodel model;
alglib::rbfunserialize(stream, model);
for(int i=0; i<ref_val.length(); i++)
passed = passed && (fabs(alglib::rbfcalc2(model,i,0)-ref_val[i])<eps);
}
catch(...)
{ passed = false; }
try
{
// test that we can read from the stream after unserialization
double eps = 0.0000000001;
std::string _s = std::string(pc_str)+".<az>";
std::istringstream stream(_s);
alglib::rbfmodel model;
alglib::rbfunserialize(stream, model);
for(int i=0; i<ref_val.length(); i++)
passed = passed && (fabs(alglib::rbfcalc2(model,i,0)-ref_val[i])<eps);
passed = passed && (stream.get()=='<');
passed = passed && (stream.get()=='a');
passed = passed && (stream.get()=='z');
passed = passed && (stream.get()=='>');
}
catch(...)
{ passed = false; }
//
// Report
//
printf(fmt_str, "* Serialization (RBF)", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
}
{
bool passed = true;
#if (AE_OS==AE_WINDOWS) || AE_OS==AE_POSIX
alglib::hqrndstate rs;
alglib::rbfmodel rbf;
alglib::rbfreport rep;
alglib::real_2d_array xy;
int n = 1000, nx = 2, ny = 1;
double rbase = 1.0;
async_rbf_record async_rec;
alglib::hqrndseed(464, 764, rs);
xy.setlength(n, nx+ny);
for(int i=0; i<n; i++)
for(int j=0; j<=nx+ny; j++)
xy[i][j] = alglib::hqrndnormal(rs);
alglib::rbfcreate(nx, ny, rbf);
alglib::rbfsetalgohierarchical(rbf, rbase, 1, 0.0);
alglib::rbfsetpoints(rbf, xy);
alglib::rbfsetv2its(rbf, 100000);
passed = passed && (alglib::rbfpeekprogress(rbf)==0);
async_rec.p_model = &rbf;
async_rec.p_report= &rep;
async_rec.thread_finished = false;
#if AE_OS==AE_WINDOWS
HANDLE thread = CreateThread(NULL, 0, async_build_rbf_model, &async_rec, 0, NULL);
if( thread==NULL )
{
printf(fmt_str, "* Progress/termination (RBF)", "FAILED");
printf(">>> unable to create background thread\n");
fflush(stdout);
return 1;
}
#elif AE_OS==AE_POSIX
pthread_t thread;
if( pthread_create(&thread, NULL, async_build_rbf_model, &async_rec)!=0 )
{
printf(fmt_str, "* Progress/termination (RBF)", "FAILED");
printf(">>> unable to create background thread\n");
fflush(stdout);
return 1;
}
#else
#error Unable to determine OS, unexpected here
#endif
double last_progress = 0;
for(;;)
{
double new_progress = alglib::rbfpeekprogress(rbf);
passed = passed && (new_progress>=last_progress);
passed = passed && (new_progress<=0.1); // we expect to terminate well before reaching 10%
last_progress = new_progress;
if( new_progress>=0.001 )
{
alglib::rbfrequesttermination(rbf);
break;
}
}
for(;;)
{
double new_progress = alglib::rbfpeekprogress(rbf);
passed = passed && ((new_progress<=0.1) || (new_progress==1.0)); // we expect to terminate well before reaching 10%
if( async_rec.thread_finished )
break;
}
#if AE_OS==AE_WINDOWS
WaitForMultipleObjects(1, &thread, TRUE, INFINITE);
#elif AE_OS==AE_POSIX
pthread_join(thread, NULL);
#else
#error Unable to determine OS, unexpected here
#endif
passed = passed && (alglib::rbfpeekprogress(rbf)==1);
passed = passed && (rep.terminationtype==8);
passed = passed && (alglib::rbfcalc2(rbf,alglib::hqrndnormal(rs),alglib::hqrndnormal(rs))==0.0);
printf(fmt_str, "* Progress/termination (RBF)", passed ? "OK" : "FAILED");
fflush(stdout);
if( !passed )
return 1;
#else
printf(fmt_str, "* Progress/termination (RBF)", "??");
fflush(stdout);
if( !passed )
return 1;
#endif
}
{
//
// Test malloc() exceptions in constructors
//
#ifdef AE_USE_ALLOC_COUNTER
bool passed = true;
bool were_exceptions = false;
for(int eidx=0; ; eidx++) // loop is terminated when we survive through all the tests
{
//
// Select moment when we generate exception in the constructor
//
alglib_impl::_malloc_failure_after = alglib_impl::_alloc_counter_total+eidx;
//
// Perform many activities with ALGLIB, catch exceptions.
// It is survival test, it checks that we survive exceptions.
// If it fails, we are likely to end with abort().
//
try
{
{
real_1d_array x0 = "[1,2,3]";
real_1d_array x1(x0);
real_1d_array x2;
x2 = x1;
real_1d_array *p = new real_1d_array("[1]");
delete p;
}
{
real_2d_array x0 = "[[1,2,3],[0,0,0]]";
real_2d_array x1(x0);
real_2d_array x2;
x2 = x1;
real_2d_array *p = new real_2d_array("[[1],[5]]");
delete p;
}
{
sparsematrix s;
sparsecreate(2, 2, s);
sparseset(s, 0, 0, 2.0);
sparseset(s, 1, 1, 1.0);
sparseset(s, 0, 1, 1.0);
sparseadd(s, 1, 1, 4.0);
sparsematrix s2(s), s3;
s3 = s;
double v;
v = sparseget(s, 0, 0);
v = sparseget(s, 0, 1);
v = sparseget(s, 1, 0);
v = sparseget(s, 1, 1);
sparseconverttocrs(s);
real_1d_array x = "[1,-1]";
real_1d_array y = "[]";
sparsemv(s, x, y);
}
{
real_1d_array x = "[0,0]";
double epsg = 0.0000000001;
double epsf = 0;
double epsx = 0;
double stpmax = 0.1;
ae_int_t maxits = 0;
mincgstate state;
mincgreport rep;
mincgcreate(x, state);
mincgsetcond(state, epsg, epsf, epsx, maxits);
mincgsetstpmax(state, stpmax);
mincgstate state2;
state2 = state;
mincgstate state3(state2);
mincgrestartfrom(state, x);
}
{
mlptrainer trn;
multilayerperceptron network;
mlpreport rep;
real_2d_array xy = "[[1,1,1],[1,2,2],[2,1,2],[2,2,4]]";
mlpcreatetrainer(2, 1, trn);
mlpcreate1(2, 5, 1, network);
mlpsetdataset(trn, xy, 4);
mlptrainnetwork(trn, network, 5, rep);
real_1d_array x = "[2,2]";
real_1d_array y = "[0]";
mlpprocess(network, x, y);
}
{
std::string s;
double v;
rbfmodel model0;
rbfmodel model1;
real_2d_array xy = "[[-1,0,2],[+1,0,3]]";
rbfreport rep;
rbfcreate(2, 1, model0);
rbfsetpoints(model0, xy);
rbfsetalgohierarchical(model0, 1.0, 3, 0.0);
rbfbuildmodel(model0, rep);
alglib::rbfserialize(model0, s);
alglib::rbfunserialize(s, model1);
v = rbfcalc2(model0, 0.0, 0.0);
v = rbfcalc2(model1, 0.0, 0.0);
rbfbuildmodel(model0, rep);
v = rbfcalc2(model0, 0.0, 0.0);
rbfbuildmodel(model1, rep);
v = rbfcalc2(model1, 0.0, 0.0);
}
//
// We survived all tests, next iteration will bring no changed, terminate loop!
//
break;
}
catch(ap_error)
{ were_exceptions = true; }
}
alglib_impl::_malloc_failure_after = 0; // turn off artificial malloc failures
printf(fmt_str, "* Exceptions in constructors", were_exceptions ? (passed ? "OK" : "FAILED") : "..");
fflush(stdout);
if( !passed )
return 1;
#else
printf(fmt_str, "* Exceptions in constructors", "??");
fflush(stdout);
#endif
}
{
//
// Test multithreading-related settings
//
// For this test we measure performance of large NxNxN GEMMs
// with different threading settings.
//
printf("SMP settings vs GEMM speedup:\n");
#if !defined(ALGLIB_NO_EXPENSIVE_XTESTS)
if( alglib::_ae_cores_count()>1 )
{
bool passed = true;
alglib_impl::ae_uint64_t default_global_threading = alglib::_ae_get_global_threading();
alglib::ae_int_t default_nworkers = alglib::getnworkers();
double time_default = 0,
time_glob_ser = 0,
time_glob_smp = 0,
time_glob_ser_loc_ser = 0,
time_glob_ser_loc_smp = 0,
time_glob_smp_loc_ser = 0,
time_glob_smp_loc_smp = 0,
time_glob_smp_nw1 = 0;
alglib::ae_int_t n = 800, mintime = 2000, cnt, t0;
try
{
// allocate temporary matrices
alglib::real_2d_array a, b, c;
int i, j;
a.setlength(n, n);
b.setlength(n, n);
c.setlength(n, n);
for(i=0; i<n; i++)
for(j=0; j<n; j++)
{
a[i][j] = alglib::randomreal()-0.5;
b[i][j] = alglib::randomreal()-0.5;
c[i][j] = 0.0;
}
// measure time; interleave measurements with different settings in order to
// reduce variance of results
while(time_default<mintime)
{
// default threading
t0 = alglib_impl::ae_tickcount();
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 0,
0.0,
c, 0, 0);
time_default += alglib_impl::ae_tickcount()-t0;
alglib::_ae_set_global_threading(default_global_threading); // restore
// global serial
t0 = alglib_impl::ae_tickcount();
alglib::setglobalthreading(alglib::serial);
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 0,
0.0,
c, 0, 0);
time_glob_ser += alglib_impl::ae_tickcount()-t0;
alglib::_ae_set_global_threading(default_global_threading); // restore
// global parallel
t0 = alglib_impl::ae_tickcount();
alglib::setglobalthreading(alglib::parallel);
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 0,
0.0,
c, 0, 0);
time_glob_smp += alglib_impl::ae_tickcount()-t0;
alglib::_ae_set_global_threading(default_global_threading); // restore
// global serial, local serial
t0 = alglib_impl::ae_tickcount();
alglib::setglobalthreading(alglib::serial);
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 0,
0.0,
c, 0, 0,
alglib::serial);
time_glob_ser_loc_ser += alglib_impl::ae_tickcount()-t0;
alglib::_ae_set_global_threading(default_global_threading); // restore
// global serial, local parallel
t0 = alglib_impl::ae_tickcount();
alglib::setglobalthreading(alglib::serial);
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 0,
0.0,
c, 0, 0,
alglib::parallel);
time_glob_ser_loc_smp += alglib_impl::ae_tickcount()-t0;
alglib::_ae_set_global_threading(default_global_threading); // restore
// global parallel, local serial
t0 = alglib_impl::ae_tickcount();
alglib::setglobalthreading(alglib::parallel);
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 0,
0.0,
c, 0, 0,
alglib::serial);
time_glob_smp_loc_ser += alglib_impl::ae_tickcount()-t0;
alglib::_ae_set_global_threading(default_global_threading); // restore
// global parallel, local parallel
t0 = alglib_impl::ae_tickcount();
alglib::setglobalthreading(alglib::parallel);
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 0,
0.0,
c, 0, 0,
alglib::parallel);
time_glob_smp_loc_smp += alglib_impl::ae_tickcount()-t0;
alglib::_ae_set_global_threading(default_global_threading); // restore
// global parallel, nworkers=1
t0 = alglib_impl::ae_tickcount();
alglib::setglobalthreading(alglib::parallel);
alglib::setnworkers(1);
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 0,
0.0,
c, 0, 0);
time_glob_smp_nw1 += alglib_impl::ae_tickcount()-t0;
alglib::_ae_set_global_threading(default_global_threading); // restore
alglib::setnworkers(default_nworkers);
}
}
catch(ap_error)
{ passed = false; }
printf(fmt_speedup, "* default speedup", time_glob_ser/time_glob_ser);
printf(fmt_speedup, "* serial (global)", time_glob_ser/time_default);
printf(fmt_speedup, "* serial (local)", time_glob_ser/time_glob_ser_loc_ser);
printf(fmt_speedup, "* serial (nworkers=1)", time_glob_ser/time_glob_smp_nw1);
printf(fmt_speedup, "* parallel (global)", time_glob_ser/time_glob_smp);
printf(fmt_speedup, "* parallel (local) v1", time_glob_ser/time_glob_ser_loc_smp);
passed = passed && (time_glob_ser/time_default >0.85) && (time_glob_ser/time_default <1.15);
passed = passed && (time_glob_ser/time_glob_ser >0.85) && (time_glob_ser/time_glob_ser <1.15);
passed = passed && (time_glob_ser/time_glob_ser_loc_ser>0.85) && (time_glob_ser/time_glob_ser_loc_ser<1.15);
passed = passed && (time_glob_ser/time_glob_smp_loc_ser>0.85) && (time_glob_ser/time_glob_smp_loc_ser<1.15);
passed = passed && (time_glob_ser/time_glob_smp_nw1 >0.85) && (time_glob_ser/time_glob_smp_nw1 <1.15);
passed = passed && (time_glob_ser/time_glob_smp >1.30);
passed = passed && (time_glob_ser/time_glob_ser_loc_smp>1.30);
passed = passed && (time_glob_ser/time_glob_smp_loc_smp>1.30);
printf(fmt_str, "* test result", passed ? "OK" : "FAILED (soft failure)");
fflush(stdout);
//
// soft failure:
// // if( !passed )
// // return 1;
//
}
else
{
printf(fmt_str, "* test skipped (no SMP)", "??");
fflush(stdout);
}
#else
printf(fmt_str, "* test skipped (too slow for Valgrind)", "??");
fflush(stdout);
#endif
}
//
// Testing issues which must be fixed
//
printf("Issues:\n");
{
//
// Testing issue #505 (http://bugs.alglib.net/view.php?id=505) in optimizers.
// This issue was present in ALL optimizers, but we test it only on two: CG and LM.
//
try
{
//
// Test CG
// Stopping criteria - EpsX
//
mincgstate state;
mincgreport rep;
real_1d_array x = "[0.0]";
double x0 = 20*alglib::randomreal()-10;
double epsx = 1.0E-9;
mincgcreate(1, x, state);
mincgsetcond(state, 0.0, 0.0, epsx, 0);
mincgoptimize(state, func505_grad, NULL, &x0);
mincgresults(state, x, rep);
issue505_passed = issue505_passed && (fabs(4*pow(x[0]-x0,3))<1.0E-3);
}
catch(...)
{ issue505_passed = false; }
try
{
//
// Test LM
// Stopping criteria - after |grad|<epsG
//
minlmstate state;
minlmreport rep;
real_1d_array x = "[0.0]";
double x0 = 20*alglib::randomreal()-10;
double epsx = 1.0E-9;
minlmcreatevj(1, 2, x, state);
minlmsetcond(state, epsx, 0);
minlmoptimize(state, func505_vec, func505_jac, NULL, &x0);
minlmresults(state, x, rep);
issue505_passed = issue505_passed && (fabs(x[0]-x0)<1.0E-3);
}
catch(...)
{ issue505_passed = false; }
printf(fmt_str, "* issue 505", issue505_passed ? "OK" : "FAILED");
fflush(stdout);
if( !issue505_passed )
return 1;
//
// Testing issue #478 (http://bugs.alglib.net/view.php?id=478)
// in high-quality RNG. It have to correctly handle random numbers
// larger than 2^31.
//
// This test is performed only in 64-bit mode.
//
if( sizeof(alglib::ae_int_t)>4 )
{
//
// 64-bit mode, perform test:
// * use large NMax>2^31
// * generate 1.000.000 random numbers
// * use two bins - one for numbers less then NMax/2,
// another one for the rest of them
// * bin sizes are equal to n0, n1
// * both bins should be approximately equal, we use
// ad hoc threshold 0.45 < n0,n1 < 0.55.
//
try
{
alglib::hqrndstate rs;
alglib::ae_int_t nmax[3];
alglib::ae_int_t ncnt = 3, nidx;
double n0, n1;
alglib::hqrndrandomize(rs);
//
// nmax:
// * first nmax is just large value to test basic uniformity of generator
//
nmax[0] = 1000000;
nmax[0] = nmax[0]*nmax[0];
nmax[1] = 2147483562;
nmax[1] *= 1.5;
nmax[2] = 2147483562;
nmax[2] *= 3;
for(nidx=0; nidx<ncnt; nidx++)
{
n0 = 0;
n1 = 0;
for(int i=0; i<1000000; i++)
{
alglib::ae_int_t v = alglib::hqrnduniformi(rs, nmax[nidx]);
if( v<nmax[nidx]/2 )
n0++;
else
n1++;
issue478_passed = issue478_passed && (v>=0) && (v<nmax[nidx]);
}
issue478_passed = issue478_passed && (n0/(n0+n1)>0.45);
issue478_passed = issue478_passed && (n0/(n0+n1)<0.55);
issue478_passed = issue478_passed && (n1/(n0+n1)>0.45);
issue478_passed = issue478_passed && (n1/(n0+n1)<0.55);
}
}
catch(...)
{ issue478_passed = false; }
printf(fmt_str, "* issue 478", issue478_passed ? "OK" : "FAILED");
fflush(stdout);
if( !issue478_passed )
return 1;
}
else
{
//
// 32-bit mode, skip test
//
printf(fmt_str, "* issue 478", "OK (skipped in 32-bit mode)");
fflush(stdout);
}
//
// Testing issue #528 (http://bugs.alglib.net/view.php?id=528)
// in shared pool and smart pointer which leak memory.
//
// In order to test it we create pool, seed it with specially
// created structure, perform several operations, then clear it.
// We test allocation counter before and after this operation.
//
#ifdef AE_USE_ALLOC_COUNTER
try
{
int alloc_cnt;
alglib_impl::ae_state _alglib_env_state;
alglib_impl::ae_frame _frame_block;
alglib_impl::ae_shared_pool pool;
alglib_impl::ae_smart_ptr ptr0, ptr1;
void *p0, *p1;
seedrec seed;
// case #0: just seeding the pool
alloc_cnt = alglib_impl::_alloc_counter;
alglib_impl::ae_state_init(&_alglib_env_state);
alglib_impl::ae_frame_make(&_alglib_env_state, &_frame_block);
memset(&pool, 0, sizeof(pool));
memset(&seed, 0, sizeof(seed));
alglib_impl::ae_shared_pool_init(&pool, &_alglib_env_state, true);
_seedrec_init(&seed, &_alglib_env_state, ae_true);
alglib_impl::ae_shared_pool_set_seed(&pool, &seed, sizeof(seed), _seedrec_init, _seedrec_init_copy, _seedrec_destroy, &_alglib_env_state);
alglib_impl::ae_state_clear(&_alglib_env_state);
issue528_passed = issue528_passed && (alloc_cnt==alglib_impl::_alloc_counter);
// case #1: seeding and retrieving, not recycling
alloc_cnt = alglib_impl::_alloc_counter;
alglib_impl::ae_state_init(&_alglib_env_state);
alglib_impl::ae_frame_make(&_alglib_env_state, &_frame_block);
memset(&seed, 0, sizeof(seed));
memset(&pool, 0, sizeof(pool));
memset(&ptr0, 0, sizeof(ptr0));
alglib_impl::ae_smart_ptr_init(&ptr0, (void**)&p0, &_alglib_env_state, true);
alglib_impl::ae_shared_pool_init(&pool, &_alglib_env_state, true);
_seedrec_init(&seed, &_alglib_env_state, true);
alglib_impl::ae_shared_pool_set_seed(&pool, &seed, sizeof(seed), _seedrec_init, _seedrec_init_copy, _seedrec_destroy, &_alglib_env_state);
alglib_impl::ae_shared_pool_retrieve(&pool, &ptr0, &_alglib_env_state);
alglib_impl::ae_state_clear(&_alglib_env_state);
issue528_passed = issue528_passed && (alloc_cnt==alglib_impl::_alloc_counter);
// case #2: seeding and retrieving twice to different pointers, recycling both
alloc_cnt = alglib_impl::_alloc_counter;
alglib_impl::ae_state_init(&_alglib_env_state);
alglib_impl::ae_frame_make(&_alglib_env_state, &_frame_block);
memset(&ptr0, 0, sizeof(ptr0));
memset(&ptr1, 0, sizeof(ptr1));
memset(&pool, 0, sizeof(pool));
memset(&seed, 0, sizeof(seed));
alglib_impl::ae_smart_ptr_init(&ptr0, (void**)&p0, &_alglib_env_state, true);
alglib_impl::ae_smart_ptr_init(&ptr1, (void**)&p1, &_alglib_env_state, true);
alglib_impl::ae_shared_pool_init(&pool, &_alglib_env_state, true);
_seedrec_init(&seed, &_alglib_env_state, true);
alglib_impl::ae_shared_pool_set_seed(&pool, &seed, sizeof(seed), _seedrec_init, _seedrec_init_copy, _seedrec_destroy, &_alglib_env_state);
alglib_impl::ae_shared_pool_retrieve(&pool, &ptr0, &_alglib_env_state);
alglib_impl::ae_shared_pool_retrieve(&pool, &ptr1, &_alglib_env_state);
alglib_impl::ae_shared_pool_recycle(&pool, &ptr0, &_alglib_env_state);
alglib_impl::ae_shared_pool_recycle(&pool, &ptr1, &_alglib_env_state);
alglib_impl::ae_state_clear(&_alglib_env_state);
issue528_passed = issue528_passed && (alloc_cnt==alglib_impl::_alloc_counter);
}
catch(...)
{ issue528_passed = false; }
printf(fmt_str, "* issue 528", issue528_passed ? "OK" : "FAILED");
fflush(stdout);
if( !issue528_passed )
return 1;
#else
printf(fmt_str, "* issue 528", "??");
fflush(stdout);
#endif
//
// Testing issue #591 (http://bugs.alglib.net/view.php?id=591)
// in copying of object containing shared pool as one of its
// fields.
//
// Unfixed ALGLIB crashes because of unneeded assertion in the
// ae_shared_pool_init_copy() function.
//
try
{
alglib::multilayerperceptron net0, net1;
alglib::real_1d_array x("[1,2]"), y0("[0,0]"), y1("[0,0]"), y2("[0,0]");
alglib::mlpcreate0(2, 2, net0);
alglib::mlpprocess(net0, x, y0);
//
// Test assignment constructor
//
net1 = net0;
alglib::mlpprocess(net1, x, y1);
issue591_passed = issue591_passed && (fabs(y0[0]-y1[0])<1.0E-9) && (fabs(y0[1]-y1[1])<1.0E-9);
//
// Test copy constructor
//
alglib::multilayerperceptron net2(net0);
alglib::mlpprocess(net2, x, y2);
issue591_passed = issue591_passed && (fabs(y0[0]-y2[0])<1.0E-9) && (fabs(y0[1]-y2[1])<1.0E-9);
}
catch(...)
{ issue591_passed = false; }
printf(fmt_str, "* issue 591", issue591_passed ? "OK" : "FAILED");
fflush(stdout);
if( !issue591_passed )
return 1;
//
// Task #594 (http://bugs.alglib.net/view.php?id=594) - additional
// test for correctness of copying of objects. When we copy ALGLIB
// object, indenendent new copy is created.
//
// This test checks both copying with copy constructor and assignment
// constructor
//
try
{
alglib::multilayerperceptron net0, net1;
alglib::real_1d_array x("[1,2]"), y0("[0,0]"), y1("[0,0]"), y2("[0,0]");
alglib::mlpcreate0(2, 2, net0);
alglib::mlpprocess(net0, x, y0);
//
// Test assignment and copy constructors:
// * copy object with one of the constructors
// * process vector with original network
// * randomize original network
// * process vector with copied networks and compare
//
net1 = net0;
alglib::multilayerperceptron net2(net0);
alglib::mlprandomize(net0);
alglib::mlpprocess(net1, x, y1);
alglib::mlpprocess(net2, x, y2);
issue594_passed = issue594_passed && (fabs(y0[0]-y1[0])<1.0E-9) && (fabs(y0[1]-y1[1])<1.0E-9);
issue594_passed = issue594_passed && (fabs(y0[0]-y2[0])<1.0E-9) && (fabs(y0[1]-y2[1])<1.0E-9);
}
catch(...)
{ issue594_passed = false; }
printf(fmt_str, "* issue 594", issue594_passed ? "OK" : "FAILED");
fflush(stdout);
if( !issue594_passed )
return 1;
//
// Issue 764#, potential memory leak in the smart pointer
//
#ifdef AE_USE_ALLOC_COUNTER
try
{
int alloc_cnt;
alglib_impl::ae_state _alglib_env_state;
alglib_impl::ae_frame _frame_block;
alglib_impl::ae_shared_pool pool;
alglib_impl::ae_smart_ptr ptr0;
void *p0, *p1;
seedrec seed;
// seeding shared pool and retrieving twice to same pointer, no recycling
alloc_cnt = alglib_impl::_alloc_counter;
alglib_impl::ae_state_init(&_alglib_env_state);
alglib_impl::ae_frame_make(&_alglib_env_state, &_frame_block);
memset(&ptr0, 0, sizeof(ptr0));
memset(&pool, 0, sizeof(pool));
memset(&seed, 0, sizeof(seed));
alglib_impl::ae_smart_ptr_init(&ptr0, (void**)&p0, &_alglib_env_state, true);
alglib_impl::ae_shared_pool_init(&pool, &_alglib_env_state, true);
_seedrec_init(&seed, &_alglib_env_state, true);
alglib_impl::ae_shared_pool_set_seed(&pool, &seed, sizeof(seed), _seedrec_init, _seedrec_init_copy, _seedrec_destroy, &_alglib_env_state);
alglib_impl::ae_shared_pool_retrieve(&pool, &ptr0, &_alglib_env_state);
alglib_impl::ae_shared_pool_retrieve(&pool, &ptr0, &_alglib_env_state);
alglib_impl::ae_state_clear(&_alglib_env_state);
issue764_passed = issue764_passed && (alloc_cnt==alglib_impl::_alloc_counter);
}
catch(...)
{ issue764_passed = false; }
printf(fmt_str, "* issue 764", issue764_passed ? "OK" : "FAILED");
fflush(stdout);
if( !issue764_passed )
return 1;
#else
printf(fmt_str, "* issue 764", "??");
fflush(stdout);
#endif
//
// Issue 813: MSVC is unable to handle longjmp() from catch() block; the code
// cycles forever.
//
{
alglib::minlmstate state;
alglib::real_1d_array x;
x.setlength(1);
x[0] = 0;
alglib::minlmcreatev(1, x, 1e-5, state);
issue813_passed = false;
try
{
alglib::minlmoptimize(state, &issue813_callback);
}
catch(...)
{
issue813_passed = true;
}
printf(fmt_str, "* issue 813", issue813_passed ? "OK" : "FAILED");
fflush(stdout);
if( !issue813_passed )
return 1;
}
//
// Issue 824: pre-3.16 versions of ALGLIB hide exceptions generated in user callbacks
//
{
alglib::mincgstate state;
alglib::real_1d_array x;
x.setlength(1);
x[0] = 0;
alglib::mincgcreatef(1, x, 1e-5, state);
issue824_passed = true;
// throw int*
try
{
alglib::mincgoptimize(state, &issue824_callback_i);
}
catch(int*)
{
}
catch(double *)
{
issue824_passed = false;
}
catch(...)
{
issue824_passed = false;
}
// throw double*
try
{
alglib::mincgoptimize(state, &issue824_callback_d);
}
catch(int*)
{
issue824_passed = false;
}
catch(double *)
{
}
catch(...)
{
issue824_passed = false;
}
// done
printf(fmt_str, "* issue 824", issue824_passed ? "OK" : "FAILED");
fflush(stdout);
if( !issue824_passed )
return 1;
}
}
//
// Parallel optimizers
//
printf("Parallel optimizers:\n");
fflush(stdout);
{
#if (AE_OS==AE_UNKNOWN) || defined(ALGLIB_DO_NOT_TEST_ACTUAL_PARALLELISM)
bool test_parallel_speedup = false;
#else
bool test_parallel_speedup = alglib_impl::ae_cores_count()>1;
#endif
const double diff_step = 0.0001;
const double rosenbrock_parameter = 2.0;
const double ftol_lbfgs = 1.0e-10;
int i, n, npoints, nparams, ncoord;
double f;
alglib::real_1d_array x0, xf;
bool test_failed;
//
// Test LBFGS serial and parallel numerical differentiation
//
int local_counter;
test_failed = false;
n = 2;
local_counter = 0;
for(int global_cb_parallelism=0; global_cb_parallelism<=2; global_cb_parallelism++)
for(int local_cb_parallelism=0; local_cb_parallelism<=2; local_cb_parallelism++)
{
//
// determine parallelism parameters
//
alglib::xparams _cbk_map[] = { alglib::xdefault, alglib::serial_callbacks, alglib::parallel_callbacks };
alglib::xparams _add1_map[] = { alglib::xdefault, alglib::serial, alglib::parallel, alglib::xdefault };
alglib::xparams _add2_map[] = { alglib::serial, alglib::parallel, alglib::xdefault, alglib::parallel, alglib::serial };
//
alglib::xparams xglb = _cbk_map[global_cb_parallelism] | _add1_map[local_counter%4];
alglib::xparams xloc = _cbk_map[ local_cb_parallelism] | _add2_map[local_counter%5];
bool are_callbacks_parallel = local_cb_parallelism==2 || (local_cb_parallelism==0 && global_cb_parallelism==2);
local_counter++;
//
// Solve with current parallelism settings
//
alglib::minlbfgsstate state0;
alglib::minlbfgsreport rep0;
paracbck_rosenbrock_problem problem0(n,rosenbrock_parameter);
x0.setlength(n);
for(i=0; i<n; i++)
x0[i] = 0;
alglib_impl::ae_int_t t0 = alglib_impl::ae_tickcount();
alglib::minlbfgscreatef(n, imin(n,2), x0, diff_step, state0);
alglib::setglobalthreading(xglb);
alglib::minlbfgsoptimize(state0, paracbck_rosenbrock_func, NULL, &problem0, xloc);
alglib::minlbfgsresults(state0, xf, rep0);
paracbck_rosenbrock_func(xf, f, &problem0);
if( test_parallel_speedup && are_callbacks_parallel && !problem0.parallelism_detected )
{
printf(">>> MINLBFGS: alglib::parallel_callbacks are processed sequentially\n");
test_failed = true;
}
if( problem0.parallelism_detected && !are_callbacks_parallel )
{
printf(">>> MINLBFGS: alglib::serial_callbacks are parallelized\n");
test_failed = true;
}
if( f>ftol_lbfgs )
{
printf(">>> MINLBFGS: optimizer failed\n");
test_failed = true;
}
}
alglib::setglobalthreading(alglib::xdefault); // restore defaults
{
//
// Test various crash scenarios
//
for(int cc=1; cc<=3; cc++)
for(int cbtype=0; cbtype<2; cbtype++)
{
alglib::minlbfgsstate state0;
alglib::minlbfgsreport rep0;
paracbck_rosenbrock_problem problem0(n,rosenbrock_parameter);
problem0.countdown = cc;
x0.setlength(n);
for(i=0; i<n; i++)
x0[i] = 0;
alglib::minlbfgscreatef(n, imin(n,2), x0, diff_step, state0);
try
{
alglib::minlbfgsoptimize(state0, paracbck_rosenbrock_func, NULL, &problem0, cbtype==0 ? alglib::serial_callbacks : alglib::parallel_callbacks);
test_failed = true;
printf(">>> MINLBFGS: incorrect exception handling in callbacks\n");
}
catch(alglib::ap_error e)
{
}
}
}
printf(fmt_str, "* minlbfgs (D-protocol)", test_failed ? "FAILED" : (test_parallel_speedup?"OK":"WEAK OK"));
fflush(stdout);
if( test_failed )
return 1;
//
// Test MINLM
//
test_failed = false;
for(int ptype=0; ptype<=1; ptype++)
for(int cbtype=0; cbtype<=1; cbtype++)
for(int ndup=1; ndup<=2; ndup++)
{
//
// Test serial and parallel numerical differentiation, serial and parallel Jacobians.
//
nparams = 3;
const double ftol = 0.02;
const int maxits = 2; // just two iterations in order to be able to catch convergence problems due to errors in gradients
//
alglib::minlmstate state0;
alglib::minlmreport rep0;
alglib::real_1d_array cv;
paracbck_minlm_f0_problem problem0(nparams, ndup);
x0.setlength(nparams);
for(i=0; i<nparams; i++)
x0[i] = 0;
// modify problem statement according to the duplication factor: either use raw matrix
// produced by the generator, or replace each point f(x)=y with a pair f(x)=y-EPS / f(x)=y+EPS
if( cbtype==0 )
{
problem0.delay = 10;
alglib::minlmcreatev(nparams, problem0.a.rows(), x0, diff_step, state0);
alglib::minlmsetcond(state0, 0.0, maxits);
alglib::minlmoptimize(state0, paracbck_minlmf0_fvec, NULL, &problem0, ptype==0 ? alglib::serial_callbacks : alglib::parallel_callbacks);
}
else
{
problem0.delay = 10;
alglib::minlmcreatevj(nparams, problem0.a.rows(), x0, state0);
alglib::minlmsetcond(state0, 0.0, maxits);
alglib::minlmoptimize(state0, paracbck_minlmf0_fvec, paracbck_minlmf0_jac, NULL, &problem0, ptype==0 ? alglib::serial_callbacks : alglib::parallel_callbacks);
}
alglib::minlmresults(state0, xf, rep0);
cv.setlength(problem0.a.rows());
paracbck_minlmf0_fvec(xf, cv, &problem0);
for(int i=0; i<problem0.a.rows(); i++)
if( fabs(cv[i])>ftol )
{
printf(">>> MINLM: optimizer failed\n");
printf("%.3e\n", fabs(cv[i]));
test_failed = true;
}
if( ptype==0 && problem0.parallelism_detected )
{
printf(">>> MINLM: alglib::serial_callbacks are processed in parallel\n");
test_failed = true;
}
if( test_parallel_speedup && cbtype==0 && ptype!=0 && !problem0.parallelism_detected )
{
printf(">>> MINLM: alglib::parallel_callbacks are processed serially\n");
test_failed = true;
}
}
printf(fmt_str, "* minlm (B-, D- protocols)", test_failed ? "FAILED" : (test_parallel_speedup?"OK":"WEAK OK"));
fflush(stdout);
if( test_failed )
return 1;
//
// Test LSFIT
//
test_failed = false;
for(int ptype=0; ptype<=1; ptype++)
for(int cbtype=0; cbtype<=1; cbtype++)
for(int ndup=1; ndup<=2; ndup++)
for(int stype=-1; stype<=+1; stype++)
{
//
// Test serial and parallel numerical differentiation, serial and parallel gradients.
//
nparams = 3;
ncoord = nparams+stype;
const double ftol = 0.02;
const int maxits = 2; // just two iterations in order to be able to catch convergence problems due to errors in gradients
//
alglib::lsfitstate state0;
alglib::lsfitreport rep0;
alglib::real_1d_array cv;
paracbck_lsfit_f0_problem problem0(nparams, ncoord);
x0.setlength(nparams);
for(i=0; i<nparams; i++)
x0[i] = 0;
// modify problem statement according to the duplication factor: either use raw matrix
// produced by the generator, or replace each point f(x)=y with a pair f(x)=y-EPS / f(x)=y+EPS
alglib::real_2d_array moda = problem0.a;
alglib::real_1d_array mody = problem0.y;
if( ndup==2 )
{
moda.setlength(2*problem0.a.rows(), problem0.a.cols());
mody.setlength(2*problem0.a.rows());
for(int i=0; i<problem0.a.rows(); i++)
{
for(int j=0; j<problem0.a.cols(); j++)
{
moda[2*i+0][j] = problem0.a[i][j];
moda[2*i+1][j] = problem0.a[i][j];
}
double eps = sin(117*i+0.65);
mody[2*i+0] = problem0.y[i]+eps;
mody[2*i+1] = problem0.y[i]-eps;
}
}
if( cbtype==0 )
{
problem0.delay = 10;
alglib::lsfitcreatef(moda, mody, x0, moda.rows(), moda.cols(), nparams, diff_step, state0);
alglib::lsfitsetcond(state0, 0.0, maxits);
alglib::lsfitfit(state0, paracbck_lsfitf0_func, NULL, &problem0, ptype==0 ? alglib::serial_callbacks : alglib::parallel_callbacks);
}
else
{
problem0.delay = 10;
alglib::lsfitcreatefg(moda, mody, x0, moda.rows(), moda.cols(), nparams, state0);
alglib::lsfitsetcond(state0, 0.0, maxits);
alglib::lsfitfit(state0, paracbck_lsfitf0_func, paracbck_lsfitf0_grad, NULL, &problem0, ptype==0 ? alglib::serial_callbacks : alglib::parallel_callbacks);
}
alglib::lsfitresults(state0, xf, rep0);
cv.setlength(problem0.a.cols());
for(int i=0; i<problem0.a.rows(); i++)
{
for(int j=0; j<problem0.a.cols(); j++)
cv[j] = problem0.a[i][j];
paracbck_lsfitf0_func(xf, cv, f, &problem0);
if( fabs(f-problem0.y[i])>ftol )
{
printf(">>> LSFIT: optimizer failed\n");
printf("%.3e\n", fabs(f-problem0.y[i]));
test_failed = true;
}
}
if( ptype==0 && problem0.parallelism_detected )
{
printf(">>> LSFIT: alglib::serial_callbacks are processed in parallel\n");
test_failed = true;
}
if( test_parallel_speedup && ptype!=0 && !problem0.parallelism_detected )
{
printf(">>> LSFIT: alglib::parallel_callbacks are processed serially\n");
test_failed = true;
}
}
printf(fmt_str, "* lsfit (B-, D- protocols)", test_failed ? "FAILED" : (test_parallel_speedup?"OK":"WEAK OK"));
fflush(stdout);
if( test_failed )
return 1;
}
//
// Performance testing
//
printf("Performance:\n");
#if !defined(ALGLIB_NO_EXPENSIVE_XTESTS)
{
{
int _n[] = { 16, 32, 64, 1024, 0};
int i, j, k, t, nidx;
for(nidx=0; _n[nidx]!=0; nidx++)
{
//
// Settings:
// * n - matrix size
// * nrepeat - number of repeated multiplications, always divisible by 4
//
int n = _n[nidx];
double desiredflops = n>64 ? 1.0E10 : 1.0E9;
int nrepeat = (int)(desiredflops/(2*pow((double)n,3.0)));
nrepeat = 4*(nrepeat/4+1);
//
// Actual processing
//
alglib::real_2d_array a, b, c;
double perf0, perf1, perf2;
a.setlength(n, n);
b.setlength(n, n);
c.setlength(n, n);
for(i=0; i<n; i++)
for(j=0; j<n; j++)
{
a[i][j] = alglib::randomreal()-0.5;
b[i][j] = alglib::randomreal()-0.5;
c[i][j] = 0.0;
}
t = alglib_impl::ae_tickcount();
for(k=0; k<nrepeat; k++)
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, k%2,
b, 0, 0, (k/2)%2,
0.0,
c, 0, 0);
t = alglib_impl::ae_tickcount()-t;
perf0 = 1.0E-6*pow((double)n,3)*2.0*nrepeat/(0.001*t);
printf("* RGEMM-SEQ-%-4ld (MFLOPS) %5.0lf\n", (long)n, (double)perf0);
alglib::setnworkers(0);
t = alglib_impl::ae_tickcount();
for(k=0; k<nrepeat; k++)
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, k%2,
b, 0, 0, (k/2)%2,
0.0,
c, 0, 0, alglib::parallel);
t = alglib_impl::ae_tickcount()-t;
perf2 = 1.0E-6*pow((double)n,3)*2.0*nrepeat/(0.001*t);
printf("* RGEMM-MTN-%-4ld %4.1lfx\n", (long)n, (double)(perf2/perf0));
alglib::setnworkers(1);
}
}
}
#else
printf(fmt_str, "* test skipped (too slow for Valgrind)", "??");
fflush(stdout);
#endif
//
// Check allocation counter on exit
//
#ifdef AE_USE_ALLOC_COUNTER
printf("Allocation counter checked... ");
#ifdef _ALGLIB_HAS_WORKSTEALING
alglib_impl::ae_free_disposed_items();
alglib_impl::ae_complete_finalization_before_exit();
#endif
if( alglib_impl::_alloc_counter!=0 )
{
printf("FAILURE: alloc_counter is non-zero on end!\n");
return 1;
}
else
printf("OK\n");
#endif
//
// Return
//
return 0;
}
|