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 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949
|
dnl
dnl
dnl @author: Michele Martone
dnl
/* @cond INNERDOC */
dnl
ifelse(LIBMMVBR_INCLUDED_UTIL_M4,1,`',`
define(`LIBMMVBR_INCLUDED_TYPES_M4',`1')dnl
dnl `PACK' format will be experimented with in the future :)
include(`rsb_misc.m4')dnl
include(`do_unroll.m4')dnl
include(`libspblas_macros.m4')dnl RSB_M4_SPBLAS...
/**
* @file
* @brief
* Auxiliary functions.
*/
RSB_M4_HEADER_MESSAGE()dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`
#ifndef RSB_UTIL_H_INCLUDED
#define RSB_UTIL_H_INCLUDED
')
dnl
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
dnl
#include "rsb_common.h"
dnl #include "rsb_types.h"
dnl
dnl
dnl
dnl FIXME : COMMENT THIS FILE
dnl -------------------------
dnl
dnl
dnl
/* non blas-like functions */
dnl
dnl
rsb_err_t rsb__util_m4_sanity_check(void)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/**
There are bugs in the m4 macros or a bad m4 implementation which will trigger this test to fail.
We are interested in catching them, as we should rely on a sane m4 environment.
*/
RSB_M4_DEBUGINFO(``$0'')
if(
RSB_M4_XOR(0,0)!=0 ||
RSB_M4_XOR(1,0)!=1 ||
RSB_M4_XOR(0,1)!=1 ||
RSB_M4_XOR(1,1)!=0 ||
RSB_M4_AND(0,0)!=0 ||
RSB_M4_AND(1,0)!=0 ||
RSB_M4_AND(0,1)!=0 ||
RSB_M4_AND(1,1)!=1 ||
RSB_M4_OR(0,0)!=0 ||
RSB_M4_OR(1,0)!=1 ||
RSB_M4_OR(0,1)!=1 ||
RSB_M4_OR(1,1)!=1 ||
0
)
goto err;
return RSB_ERR_NO_ERROR;
err:
return RSB_ERR_INTERNAL_ERROR;
}
')dnl
dnl
dnl
const void * rsb__util_increase_by_one(void *p, rsb_nnz_idx_t n, rsb_type_t typecode)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) ) {(((mtype*)p)[n])+=1;return p;}
else
#endif
')dnl
return NULL;
}
')dnl
dnl
dnl
void rsb__util_set_area_to_fraction_of_integer(void *p, const int alphai, rsb_type_t typecode)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*
alpha NULL will imply 1
*/
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) ) {*(mtype*)p = 1;*(mtype*)p/=alphai;}
else
#endif
')dnl
return;
}
')dnl
dnl
dnl
void rsb__util_set_area_to_negated_fraction(void *p, const void *alpha, rsb_type_t typecode)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*
alpha NULL will imply 1
*/
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) ) {*(mtype*)p = -1;if(alpha)*(mtype*)p/=(*(mtype*)alpha);}
else
#endif
')dnl
return;
}
')dnl
dnl
dnl
void rsb__util_set_area_to_converted_integer(void *p, rsb_type_t typecode, const rsb_int n)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) ) {*(mtype*)p = (mtype)n;}
else
#endif
')dnl
return;
}
')dnl
dnl
dnl
rsb_coo_idx_t * rsb__util_get_partitioning_array( size_t bs, size_t X , rsb_blk_idx_t * X_b, rsb_flags_t flags)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* Given a block size (be it rows or columns), an element size X in bytes,
* and a dimension (rows or columns), returns an array containing the
* indices of the elements in each block.
*
* Therefore, the allocated arrays
*
* \param bs the block size
* \param X the rows or columns count
* \param X_b on output, the allocated array elements count : (X+bs-1)/bs
* \return NULL on error; a valid array pointer on success
*
* FIXME : why not size_t ? or maybe rsb_size_t ?
* */
size_t i;
rsb_err_t errval = RSB_ERR_NO_ERROR;
rsb_coo_idx_t * p_x = NULL;
*X_b = (X+bs-1)/bs;
/* WARNING : 1 is the extreme limit before overflow :) */
if( ( ((size_t)(*X_b)) < ((size_t)((X+bs-1)/bs))) || (RSB_BLK_ADD_OVERFLOW(*X_b,1)) )
{
/* overflow. should print some message. */
errval = RSB_ERR_LIMITS;goto err;
}
p_x = rsb__malloc(sizeof(rsb_coo_idx_t)*(*X_b+1));
if(! p_x) goto err;
/* note: should use some perrno some day */
/* note the last block size : it is the same, regardless congruences */
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`*X_b',` p_x[i+LI] = (i+LI)*bs;
')
dnl for(i = 0;i<*X_b;++i)p_x[i] = i*bs;
/* FIXME : this point should be remarked and documented way better ! */
if(flags&(RSB_FLAG_WANT_BCSS_STORAGE|RSB_FLAG_WANT_FIXED_BLOCKING_VBR))
p_x[*X_b] = *X_b*bs; /* the last element of p_x is the index of the last matrix row/column + 1 */
else
p_x[*X_b] = X; /* the last element of p_x is the index of the last matrix row/column + 1 */
return p_x;
err:
RSB_CONDITIONAL_FREE(p_x);
rsb__do_perror(NULL,errval);
return NULL;
}
')dnl
dnl
dnl
#ifdef RSB_OBSOLETE_QUARANTINE_UNUSED
dnl
rsb_err_t rsb__vector_diff(void * c, const void * a, const void * b, rsb_type_t type, size_t n)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* c <- a-b
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see daxpy,dcopy in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*ta = a,*tb = b;mtype *tc = c;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
tc[i+LI] = ta[i+LI]-tb[i+LI];
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb_vector_norm_square(void * c, const void * a, rsb_type_t type, size_t n)
{
/*!
* c <- a^T*a
*
* \param a an array pointer
* \param type a valid type code
* \param n the input array length
* \note see ddot in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*ta = a;mtype *tc = c;
tc[0] = RSB_M4_ZERO(mtype);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
tc[0]+=ta[i+LI]*ta[i+LI];
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb_vector_norm(void * c, const void * a, rsb_type_t type, size_t n)
{
/*!
* c <- sqrt(a^T*a)
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see ddot in BLAS
*
* \return \rsberrcodemsg
* */
rsb_err_t errval;
if(!c)
return RSB_ERR_BADARGS;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*cp = (mtype*)c;
errval = rsb_vector_norm_square(cp,a,type,n);
*cp = RSB_M4_SQRT(mtype,*cp);
}
else
#endif
')dnl
errval = RSB_ERR_UNSUPPORTED_TYPE;
RSB_DO_ERR_RETURN(errval)
}
')dnl
dnl
dnl
ifelse(1,0,`dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb_vector_norm_square_strided(void * c, const void * a, rsb_type_t type, size_t n, rsb_nnz_idx_t inc)
{
/*!
* c <- a^T*a
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see ddot in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
if(inc==1)
return rsb_vector_norm_square(c,a,type,n);
dnl
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*ta = a;mtype *tc = c;
tc[0] = RSB_M4_ZERO(mtype);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
tc[0]+=ta[(i+LI)*inc]*ta[(i+LI)*inc];
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
dnl
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
')dnl
dnl
dnl
rsb_err_t rsb__vector_norm_strided(void * c, const void * a, rsb_type_t type, size_t n, rsb_nnz_idx_t inc)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* c <- sqrt(a^T*a)
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see ddot in BLAS
*
* \return \rsberrcodemsg
* */
rsb_err_t errval;
if(!c)
return RSB_ERR_BADARGS;
if(inc==1)
return rsb_vector_norm(c,a,type,n);
ifelse(1,0,`dnl
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*cp = (mtype*)c;
errval = rsb_vector_norm_square_strided(cp,a,type,n,inc);
*cp = RSB_M4_SQRT(mtype,*cp);
}
else
#endif
')dnl
errval = RSB_ERR_UNSUPPORTED_TYPE;
dnl
',`
errval = RSB_ERR_INTERNAL_ERROR;
')dnl
dnl
RSB_DO_ERR_RETURN(errval)
}
')dnl
dnl
dnl
rsb_err_t rsb__util_vector_sum_strided(void * c, const void * a, rsb_type_t type, size_t n, rsb_nnz_idx_t inc)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* c <- sum(a)
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see ddot in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
/* See also rsb__cblas_Xnrm2 */
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
register mtype acc = RSB_M4_ZERO(mtype); const mtype*ta = a; mtype*tc = c;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
acc+=ta[(i+LI)*inc];
');
tc[0] = acc;
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_vector_sum(void * c, const void * a, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* c <- sum(a)
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see ddot in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*ta = a; mtype*tc = c; tc[0] = RSB_M4_ZERO(mtype);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
tc[0]+=ta[i+LI];
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
dnl
dnl rsb_err_t rsb_blas_Xdot(void * c, const void * a, rsb_type_t type, size_t n, rsb_nnz_idx_t inc)
dnl {
dnl cblas_ddot(n,a,1,a,1)
dnl }
dnl
#ifdef RSB_OBSOLETE_QUARANTINE_UNUSED
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb__vector_mult_sum(const void * a, const void * b, void * c, rsb_type_t type, size_t n, const int inca, const int incb)
{
/*!
* c <- sum(a*b)
* It is allowed to give c == a or c == b or a==b
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see ddot in BLAS
*
* \return \rsberrcodemsg
*
* p.s.: this routine is, numerically speaking, a crime!
*
* */
size_t i;
if(a==b && inca==incb)
return rsb_vector_norm_square_strided(c,a,type,n,inca);
if(inca == 1 && incb == 1)
{
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*tb = b; const mtype*ta = a; mtype*tc = c,cacc = RSB_M4_ZERO(mtype);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
cacc+=ta[i+LI]*tb[i+LI];
');
*tc = cacc;
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
}
else
{
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*tb = b; const mtype*ta = a; mtype*tc = c,cacc = RSB_M4_ZERO(mtype);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
cacc+=ta[inca*(i+LI)]*tb[incb*(i+LI)];
');
*tc = cacc;
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
}
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb_fill_with_zeros_nostride(void * array, rsb_type_t type, size_t n)
{
/*!
* \ingroup gr_vec
* Will zero the input n elements long array of type type.
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) ){
mtype*ta = array;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`ta[i+LI] = RSB_M4_ZERO(mtype);')}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb_fill_with_zeros(void * array, rsb_type_t type, size_t n, size_t incx)
{
/*!
* \ingroup gr_vec
* Will zero the input n elements long array of type type.
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
*
* \return \rsberrcodemsg
* */
size_t i;
if(incx==1)
return rsb_fill_with_zeros_nostride(array,type,n);
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) ){
mtype*ta = array;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`ta[(i+LI)*incx] = RSB_M4_ZERO(mtype);')}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb_vector_scale(void * a, const void * alphap, rsb_type_t type, size_t n)
{
/*!
* a <- a * alpha
*
* \param array an array pointer
* \param type a valid type code
* \param alphap scaling value (if NULL assumed to be zero)
* \param n the input array length
* \note see dscal in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
if(alphap==NULL || RSB_IS_ELEMENT_ZERO(alphap,type))
return rsb_fill_with_zeros(a,type,n,1);
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype alpha = *(mtype*)alphap; mtype*ta = a;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[i+LI]*=alpha;
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb_strided_vector_scale(void * a, const void * alphap, rsb_type_t type, size_t n, size_t stride)
{
/*!
* a <- a * alpha
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see dscal in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
if(stride==1)
return rsb_vector_scale(a,alphap,type,n);
if(alphap==NULL || RSB_IS_ELEMENT_ZERO(alphap,type))
return rsb_fill_with_zeros(a,type,n,stride);
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype alpha = *(mtype*)alphap; mtype*ta = a;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[stride*(i+LI)]*=alpha;
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_vector_add(void * a, const void * alphap, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* a <- a + alpha
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype alpha = *(mtype*)alphap; mtype*ta = a;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[i+LI]+=alpha;
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_vector_div(void * a, const void * alphap, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* this is a benchmark-oriented function only..
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype alpha = *(mtype*)alphap; mtype*ta = a;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[i+LI]/=alpha;
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__vector_increase_by_one(void * a, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{ mtype*ta = a;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[i+LI]+=RSB_M4_ONE(mtype);
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_vector_pow(void * a, rsb_type_t type, const void *y, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \return \rsberrcodemsg
* */
size_t i;
if(!a || !y)
goto err;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype ty = *(mtype*)y,*ta = a;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[i+LI] = RSB_M4_POW(mtype,ta[i+LI],ty);
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
err:
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_vector_sqrt(void * a, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \return \rsberrcodemsg
* */
size_t i;
if(!a)goto err;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{mtype*ta = a;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[i+LI] = RSB_M4_SQRT(mtype,ta[i+LI]);
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
err:
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__vector_scale_inv(void * a, const void * alphap, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* a <- 1/a * alpha
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see dscal in BLAS
*
* \return \rsberrcodemsg
* */
if(!alphap)
return RSB_ERR_BADARGS;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype alphai = RSB_M4_ONE(mtype)/(*(mtype*)alphap);
return rsb_vector_scale(a,&alphai,type,n);
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__vector_sum_of_abs_diffs(void * c, const void * a, const void * b, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*ap = a,*bp = b;
mtype ac = RSB_M4_ZERO(mtype);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ac += RSB_M4_ABS(mtype,ap[i+LI]-bp[i+LI]);
');
*((mtype*)(c)) = ac;
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__vector_sum_of_abs(void * c, const void * a, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*ap = a;
mtype ac = RSB_M4_ZERO(mtype);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ac += RSB_M4_ABS(mtype,ap[i+LI]);
');
*((mtype*)(c)) = ac;
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__vector_to_abs(void * a, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{mtype*ta = a;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[i+LI] = RSB_M4_ABS(mtype,ta[i+LI]);
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb_alpha_sum(void * a, const void * b, const void * alphap, rsb_type_t type, size_t n)
{
/*!
* a <- a + alpha * b
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see daxpy in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype alpha = alphap ? *(mtype*)alphap : RSB_M4_ONE(mtype);
mtype*ta = a; const mtype*tb = b;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[i+LI]+=alpha*tb[i+LI];
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
ifelse(1,0,`dnl
/* redundant code (see rsb__cblas_Xaxpy) */
rsb_err_t rsb_vectors_sum(void * a, const void * b, rsb_type_t typecode, const void *alphap, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* a <- a + alpha * b
*
* \param array an array pointer
* \param typecode a valid type code
* \param n the input array length
* \note see daxpy in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
if( !alphap || RSB_IS_ELEMENT_ONE(alphap,typecode))
{
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{mtype*ta = a; const mtype*tb = b;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[i+LI]+=tb[i+LI];
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
}
else
return rsb_alpha_sum(a,b,alphap,typecode,n);
dnl {
dnl foreach(`mtype',RSB_M4_TYPES,`dnl
dnl `#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
dnl if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
dnl {const mtype alpha = *((const mtype*)alphap);
dnl mtype*ta = a; const mtype*tb = b;
dnl RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
dnl ta[i+LI]+=alpha*tb[i+LI];
dnl ');
dnl }
dnl else
dnl #endif
dnl ')dnl
dnl return RSB_ERR_UNSUPPORTED_TYPE ;
dnl }
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
')dnl
dnl
dnl
rsb_err_t rsb__util_set_array_to_converted_integer(void *p, rsb_type_t typecode, const rsb_nnz_idx_t n, const rsb_nnz_idx_t incp, const rsb_int v)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*tp = p; const mtype tv = (mtype)v;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
tp[((i+LI)*incp)] = tv;
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__vectors_left_sum_reduce_and_zero(void * d, void * s, const rsb_type_t typecode, const size_t n, const size_t incd, const size_t off)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* d[off:off+n-1] <- d[off:off+n-1] + s[off:off+n-1]
* s[off:off+n-1] <- 0
*
* \param array an array pointer
* \param typecode a valid type code
* \param incd the stride of d
* \param off offset in the vectors
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*td = d,*ts = s;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
td[(off+i+LI)*incd]+=ts[(off+i+LI)];
ts[(off+i+LI)] = RSB_M4_ZERO(mtype);
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
ifelse(1,0,`dnl
/* redundant code -- see rsb__cblas_Xaxpy */
rsb_err_t rsb_vectors_sum_scale_strided(void * a, const void * b, rsb_type_t typecode, const void *alphap, size_t n, size_t inca, size_t incb)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* a <- a + alpha * b
*
* \param array an array pointer
* \param typecode a valid type code
* \param n the input array length
* \note see daxpy in BLAS
* TODO: declare alpha as a const local variable, so the compiler will not contempt aliasing.
* \return \rsberrcodemsg
* */
size_t i;
if(inca==1 && incb==1 /*&& ( !alphap || RSB_IS_ELEMENT_ONE(alphap,typecode))*/ )
return rsb_vectors_sum(a,b,typecode,alphap,n);
if( !alphap || RSB_IS_ELEMENT_ONE(alphap,typecode))
{
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*ta = a; const mtype*tb = b;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[(i+LI)*inca]+=tb[(i+LI)*incb];
');
}
#endif
')dnl
}
else
{
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{const mtype alpha = *((const mtype*)alphap);
mtype*ta = a; const mtype*tb = b;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[(i+LI)*inca]+=alpha*tb[(i+LI)*incb];
');
}
#endif
')dnl
}
dnl return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
')dnl
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb_alpha_sum_strided(void * a, const void * b, const void * alphap, rsb_type_t type, size_t n, int inca, int incb)
{
/*!
* a <- a + alpha * b
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
* \note see daxpy in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
if(inca == 1 && incb == 1)
return rsb_alpha_sum(a,b,alphap,type,n);
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype alpha = alphap ? *(mtype*)alphap : RSB_M4_ONE(mtype);
mtype*ta = a; const mtype*tb = b;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ta[inca*(i+LI)]+=alpha*tb[incb*(i+LI)];
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__cblas_Xaxpy(rsb_type_t type, size_t n, const void * alphap, const void * x, const int incx, void * y, const int incy)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* y <- y + alpha * x
*/
return rsb_alpha_sum_strided(y,x,alphap,type,n,incy,incx);
}
')dnl
dnl
dnl
rsb_err_t rsb__vector_mult(const void * a, const void * b, void * c, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* c <- a*b
* It is allowed to give c == a or c == b or a == b
*
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
*
* FIXME : useless ?
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*ta = a; const mtype*tb = b; mtype*tc = c;
dnl //const mtype omega = *(mtype*)omegap;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
tc[i+LI] = ta[i+LI]*tb[i+LI];
');
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__xcopy(void * a, const void * b, rsb_nnz_idx_t toi, rsb_nnz_idx_t foi, rsb_nnz_idx_t n,size_t el_size)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* a[toi:toi+n] <- b[foi:foi+n]
*
* \param array an array pointer
* \param type a valid type code
*
* \return \rsberrcodemsg
* */
rsb__memcpy(((rsb_byte_t*)a)+el_size*toi,((const rsb_byte_t*)b)+el_size*foi,el_size*n);
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__do_are_similar_parametric(const void * ap, const void * bp, rsb_nnz_idx_t n,rsb_type_t typecode, rsb_nnz_idx_t incx, rsb_nnz_idx_t incy, int extra_decimals)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
*
* \param array an array pointer
* \param type a valid type code
*
* \return \rsberrcodemsg
*
* For cases like 1+0I differing from 1-0I .
* */
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
rsb_nnz_idx_t i;
const mtype *a = ap;
const mtype *b = bp;
const RSB_M4_REALT(mtype) threshold = RSB_M4_THRESHOLD_VALUE(mtype) * RSB_M4_POW(mtype,10*RSB_M4_ONE(mtype),(mtype)extra_decimals);
for(i=0;i<n;++i)
{
const mtype av = a[incx*(i)];
const mtype bv = b[incy*(i)];
if( av - bv )
{
const mtype aav = RSB_M4_ABS(mtype,av);
const mtype abv = RSB_M4_ABS(mtype,bv);
if( av && RSB_M4_ABS(mtype,(aav - abv)) / RSB_M4_ABS(mtype,av) > threshold )
goto differing;
if( bv && RSB_M4_ABS(mtype,(aav - abv)) / RSB_M4_ABS(mtype,bv) > threshold )
goto differing;
}
}
return RSB_ERR_NO_ERROR;
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE;
differing:
return RSB_ERR_GENERIC_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__do_are_similar(const void * ap, const void * bp, rsb_nnz_idx_t n,rsb_type_t typecode, rsb_nnz_idx_t incx, rsb_nnz_idx_t incy)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
*
* \param array an array pointer
* \param type a valid type code
*
* \return \rsberrcodemsg
*
* For cases like 1+0I differing from 1-0I .
* */
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
rsb_nnz_idx_t i;
const mtype *a = ap;
const mtype *b = bp;
const RSB_M4_REALT(mtype) threshold = RSB_M4_THRESHOLD_VALUE(mtype);
for(i=0;i<n;++i)
{
const mtype av = a[incx*(i)];
const mtype bv = b[incy*(i)];
if( av - bv )
{
const mtype aav = RSB_M4_ABS(mtype,av);
const mtype abv = RSB_M4_ABS(mtype,bv);
if( av && RSB_M4_ABS(mtype,(aav - abv)) / RSB_M4_ABS(mtype,av) > threshold )
goto differing;
if( bv && RSB_M4_ABS(mtype,(aav - abv)) / RSB_M4_ABS(mtype,bv) > threshold )
goto differing;
}
}
return RSB_ERR_NO_ERROR;
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE;
differing:
return RSB_ERR_GENERIC_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__do_are_same(const void * ap, const void * bp, rsb_nnz_idx_t n,rsb_type_t typecode, rsb_nnz_idx_t incx, rsb_nnz_idx_t incy)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
return rsb__do_are_similar_parametric(ap, bp, n, typecode, incx, incy, 0);
}
')dnl
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
static rsb_err_t rsb__xcopy_strided_typed(void * a, const void * b, rsb_nnz_idx_t toi, rsb_nnz_idx_t foi, rsb_nnz_idx_t n,rsb_type_t typecode, rsb_nnz_idx_t incx, rsb_nnz_idx_t incy)
{
/*!
* a[toi:toi+n] <- b[foi:foi+n]
*
* \param array an array pointer
* \param type a valid type code
*
* \return \rsberrcodemsg
* */
if(incx==1 && incy==1)
return rsb__xcopy(a,b,toi,foi,n,RSB_SIZEOF(typecode));
/* else */
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
rsb_nnz_idx_t i;
mtype *ap = a; const mtype *bp = b;
ap+=toi;
bp+=foi;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
ap[(i+LI)*incx] = bp[(i+LI)*incy];
');
return RSB_ERR_NO_ERROR;
}
else
#endif
')dnl
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__sqrt_of_sum_of_fabs_diffs(const void * a, const void * b, void *err, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* Will compute the square root of the sum of the squares of the vectors elements differences.
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
*
* FIXME
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
ifelse(mtype,`int',`dnl
/* UHM ... */
{
double acc = RSB_M4_ZERO(double);
const mtype*ta = a, *tb = b;
*((double*)err) = RSB_M4_ZERO(double);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
acc+=(ta[i+LI]-tb[i+LI])*(ta[i+LI]-tb[i+LI]);
');
*((double*)err) = sqrt(acc);
}
',`dnl
{
const mtype*ta = a; const mtype*tb = b;
*((mtype*)err) = RSB_M4_ZERO(mtype);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
*((mtype*)(err))+=(ta[i+LI]-tb[i+LI])*(ta[i+LI]-tb[i+LI]);
');
*((mtype*)err) = RSB_M4_SQRT(mtype,(*((mtype*)err)));
}
')dnl
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__fill_with_increasing_values(void * array, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
* FIXME : document me
* starts with one.
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*ta = array;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`ta[i+LI] = (const mtype)(i+LI+1);')
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_do_conjugate(void * array, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
ifelse(RSB_M4_AND(RSB_M4_IS_COMPLEX_TYPE(mtype)),1,`dnl
{
mtype*ta = array;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`ta[i+LI] = RSB_M4_CONJ_SYM(mtype,`n',RSB_M4_SYMBOL_HERMITIAN)(ta[i+LI]);')
}
',`dnl
return RSB_ERR_NO_ERROR;
')dnl
else
`#endif'
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_do_negate(void * array, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
* Will negate the input n elements long array of type type.
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*ta = array;
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`ta[i+LI] = -ta[i+LI];')}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_find_min(void * minp, const void * array, rsb_type_t type, size_t n, rsb_nnz_idx_t inc)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
*
* \return \rsberrcodemsg
* */
size_t i;
if(n<1)return RSB_ERR_BADARGS;
if(inc<1)return RSB_ERR_BADARGS;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{const mtype * ap = array;mtype *mp = minp;
*mp = *ap;for(i = 1;i<n;++i){if(RSB_M4_ABS(mtype,ap[i*inc])<RSB_M4_ABS(mtype,*mp) )*mp = ap[i*inc];
}}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_find_max(void * maxp, const void * array, rsb_type_t type, size_t n, rsb_nnz_idx_t inc)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
*
* \return \rsberrcodemsg
* */
size_t i;
if(n<1)return RSB_ERR_BADARGS;
if(inc<1)return RSB_ERR_BADARGS;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{const mtype * ap = array;mtype *mp = maxp;
*mp = *ap;for(i=1;i<n;++i){if(RSB_M4_ABS(mtype,ap[i*inc])>RSB_M4_ABS(mtype,*mp))*mp = ap[i*inc];
}}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_drop_to_zero_if_above_threshold(void * array, rsb_type_t type, size_t n, const void * threshold)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{const mtype th = (*(const mtype*)(threshold)); mtype*ta = array;
for(i = 0;i<n;++i)
{if(RSB_M4_ABS(mtype,th)<RSB_M4_ABS(mtype,ta[i]))ta[i] = RSB_M4_ZERO(mtype);}}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_nnz_idx_t rsb__util_count_positive(void * array, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
*
* \return \rsberrcodemsg
* */
size_t i, c = 0;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{ mtype*ta = array;
for(i=0;i<n;++i)
c+=(RSB_M4_CREAL(mtype,ta[i])>(RSB_M4_REALT(mtype))0);
}else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return c;
}
')dnl
dnl
dnl
rsb_nnz_idx_t rsb__util_count_negative(void * array, rsb_type_t type, size_t n)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
*
* \return \rsberrcodemsg
* */
size_t i, c = 0;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{ mtype*ta = array;
for(i=0;i<n;++i)
c+=(RSB_M4_CREAL(mtype,ta[i])<(RSB_M4_REALT(mtype))0);
}else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return c;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_drop_to_zero_if_under_threshold(void * array, rsb_type_t type, size_t n, const void * threshold)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) ) {
const mtype th = (*(mtype*)(threshold)); mtype*ta = ((mtype*)(array));
for(i=0;i<n;++i){if(RSB_M4_ABS(mtype,th)>RSB_M4_ABS(mtype,ta[i]))ta[i] = RSB_M4_ZERO(mtype);}}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__fill_with_ones(void * array, rsb_type_t type, size_t n, size_t incx)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* \ingroup gr_vec
* Will set to one the input n elements long array of type type.
* \param array an array pointer
* \param type a valid type code
* \param n the input array length
*
* \return \rsberrcodemsg
* TODO:RENAME: rsb__fill_with_ones -> rsb__val_fill_with_ones.
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) ){
mtype*ta = ((mtype*)(array));
for(i=0;i<n;++i) {ta[i*incx] = RSB_M4_ONE(mtype);}}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__debug_print_vectors_diff_fd(const void * v1, const void * v2, size_t n, rsb_type_t type, size_t incx, size_t incy, int onlyfirst, FILE*fd)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* A debug function for printing the difference of two vectors of a specified type, in parallel.
* FIXME : It should take into account thresholds specific to each numerical type.
**/
#if RSB_ALLOW_STDOUT
size_t i, differing = 0;
if(!v1 || !v2)return RSB_ERR_BADARGS;
/*RSB_STDERR("\t vectors diff :\n"); */
RSB_FPRINTF(fd,"\t vectors diff :\n");
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype *v1p = v1,*v2p = v2;
const RSB_M4_REALT(mtype) th = RSB_M4_THRESHOLD_VALUE(mtype);
for(i=0;i<n ;++i)
ifelse(mtype,`long double complex',`if(creall(v1p[i*incx])-creall(v2p[i*incy])>th)/*FIXME : incomplete check*/',`dnl
ifelse(mtype,`double complex',`if(creal(v1p[i*incx])-creal(v2p[i*incy])>th)/*FIXME : incomplete check*/',`dnl
ifelse(mtype,`float complex',`if(crealf(v1p[i*incx])-crealf(v2p[i*incy])>th)/*FIXME : incomplete check*/',`dnl
ifelse(mtype,`complex', `if(creal(v1p[i*incx])-creal(v2p[i*incy])>th)/*FIXME : incomplete check*/',`dnl
ifelse(mtype,`int', `if(v1p[i*incx]-v2p[i*incy])',`dnl
ifelse(mtype,`char', `if(v1p[i*incx]-v2p[i*incy])',`dnl
if(fabs((double)(v1p[i*incx]-v2p[i*incy]))>th)/*FIXME : incomplete check*/
')dnl
')dnl
')dnl
')dnl
')dnl
')dnl
{ differing++;
if((onlyfirst==0)||(onlyfirst>differing))
RSB_FPRINTF(fd,"%zd : "RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_STRING(mtype)" "RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_STRING(mtype)"\n",(rsb_printf_int_t)i,dnl
ifelse(mtype,`long double complex',`creall(v1p[i*incx]),cimagl(v1p[i*incx]),creall(v2p[i*incy]),cimagl(v2p[i*incy])',`dnl
ifelse(mtype,`double complex',`creal(v1p[i*incx]),cimag(v1p[i*incx]),creal(v2p[i*incy]),cimag(v2p[i*incy])',`dnl
ifelse(mtype,`float complex',`crealf(v1p[i*incx]),cimagf(v1p[i*incx]),crealf(v2p[i*incy]),cimagf(v2p[i*incy])',`dnl
ifelse(mtype,`complex',`creal(v1p[i*incx]),cimag(v1p[i*incx]),creal(v2p[i*incy]),cimag(v2p[i*incy])',`dnl
v1p[i*incx],v2p[i*incy]`'dnl
')dnl
')dnl
')dnl
')dnl
);
}
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
if(differing>onlyfirst)RSB_FPRINTF(fd,"...(for a total of %zd differing entries)...\n",(rsb_printf_int_t)(differing-onlyfirst));
return RSB_ERR_NO_ERROR;
#else
return RSB_ERR_UNSUPPORTED_FEATURE;
#endif
}
')dnl
dnl
dnl
rsb_err_t rsb__debug_print_vectors_diff(const void * v1, const void * v2, size_t n, rsb_type_t type, size_t incx, size_t incy, int onlyfirst)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
return rsb__debug_print_vectors_diff_fd(v1, v2, n, type, incx, incy, onlyfirst, RSB_DEFAULT_STREAM);
}
')dnl
dnl
dnl
rsb_err_t rsb__debug_print_value(const void * v, rsb_type_t type)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
**/
#if RSB_ALLOW_STDOUT
if(!v)return RSB_ERR_BADARGS;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype *v1p = v;
RSB_STDOUT(RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_STRING(mtype),dnl
ifelse(mtype,`long double complex',`creall(v1p[0]),cimagl(v1p[0])',`dnl
ifelse(mtype,`double complex',`creal(v1p[0]),cimag(v1p[0])',`dnl
ifelse(mtype,`float complex',`crealf(v1p[0]),cimagf(v1p[0])',`dnl
ifelse(mtype,`complex',`creal(v1p[0]),cimag(v1p[0])',`dnl
v1p[0]`'dnl
')dnl
')dnl
')dnl
')dnl
);
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
#else
return RSB_ERR_UNSUPPORTED_FEATURE;
#endif
}
')dnl
dnl
dnl
rsb_err_t rsb__debug_print_vector_extra(const void * v1, size_t n, rsb_type_t type, size_t inc, int style, FILE*stream)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* A debug function for printing two vectors of a specified type, in parallel.
**/
#if RSB_ALLOW_STDOUT
rsb_nnz_idx_t i;
int want_header = ( style == 0x1 );
const char * ts = RSB_IS_MATRIX_TYPE_COMPLEX(type)?"complex":"real";
const char * ss = RSB_SYMMETRY_STRING(RSB_FLAG_NOFLAGS);
if( n <= 0 )
goto errb;
if(!v1 || !stream)
goto errb;
/*if(!want_header)
RSB_STDERR("\t vectors :\n");*/
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype *v1p = v1;
if(want_header)RSB_FPRINTF(stream,"%%%%MatrixMarket matrix array %s %s\n%zd %zd\n",ts,ss,(rsb_printf_int_t)n,(rsb_printf_int_t)1);
for(i=0;i<n;++i)
RSB_FPRINTF(stream,RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_STRING(mtype) "\n",dnl
ifelse(mtype,`long double complex',`creall(v1p[i*inc]),cimagl(v1p[i*inc])',`dnl
ifelse(mtype,`double complex',`creal(v1p[i*inc]),cimag(v1p[i*inc])',`dnl
ifelse(mtype,`float complex',`crealf(v1p[i*inc]),cimagf(v1p[i*inc])',`dnl
ifelse(mtype,`complex',`creal(v1p[i*inc]),cimag(v1p[i*inc])',`dnl
v1p[i*inc]`'dnl
')dnl
')dnl
')dnl
')dnl
);
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
#else
return RSB_ERR_UNSUPPORTED_FEATURE;
#endif
errb:
return RSB_ERR_BADARGS;
}
')dnl
dnl
dnl
rsb_err_t rsb__debug_print_vector(const void * v1, size_t n, rsb_type_t type, size_t inc)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
return rsb__debug_print_vector_extra(v1, n, type, inc, 0x0, stdout);
}
')dnl
dnl
dnl
rsb_err_t rsb__debug_print_vectors(const void * v1, const void * v2, size_t n, size_t incx, size_t incy, rsb_type_t type)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* A debug function for printing two vectors of a specified type, in parallel.
**/
#if RSB_ALLOW_STDOUT
size_t i;
if(!v1 || !v2)return RSB_ERR_BADARGS;
RSB_STDERR("\t vectors :\n");
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype *v1p = v1,*v2p = v2;
for(i=0;i<n;++i)
RSB_STDOUT(RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_STRING(mtype)" "RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_STRING(mtype)"\n",dnl
RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_ARG(mtype,`v1p[(i)*incx]'),dnl
RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_ARG(mtype,`v2p[(i)*incy]')dnl
);
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
#else
return RSB_ERR_UNSUPPORTED_FEATURE;
#endif
}
')dnl
dnl
dnl
')
dnl
dnl
dnl
dnl ifdef(`ONLY_WANT_HEADERS',`dnl
dnl #ifndef RSB_UTIL_H_INCLUDED
dnl #define RSB_UTIL_H_INCLUDED
dnl ')
dnl
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`',`dnl
dnl
dnl
')dnl
dnl
dnl
dnl
#ifdef RSB_WANT_OSKI_BENCHMARKING
rsb_err_t rsb__do_account_sorted_optimized_css(
const rsb_coo_idx_t * MIndx, const rsb_coo_idx_t * mIndx,
const rsb_coo_idx_t Mdim, const rsb_coo_idx_t mdim,
const rsb_nnz_idx_t nnz, rsb_nnz_idx_t * elements_per_block_row, rsb_nnz_idx_t * blocks_per_block_row
)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/**
\ingroup gr_internals
elements_per_block_row and blocks_per_block_row arrays should be blanked.
FIXME : missing error handling.
*/
rsb_err_t errval = RSB_ERR_NO_ERROR;
rsb_nnz_idx_t n = 0;
if(blocks_per_block_row)
for(n=0;n<nnz;++n)
{
RSB_DEBUG_ASSERT(MIndx[n]<Mdim);
RSB_DEBUG_ASSERT(MIndx[n]>=0);
elements_per_block_row[MIndx[n]]++;
blocks_per_block_row [MIndx[n]]++;
}
else
for(n=0;n<nnz;++n)
{
RSB_DEBUG_ASSERT(MIndx[n]<Mdim);
RSB_DEBUG_ASSERT(MIndx[n]>=0);
elements_per_block_row[MIndx[n]]++;
}
RSB_DO_ERR_RETURN(errval)
}
')dnl
dnl
#endif /* RSB_WANT_OSKI_BENCHMARKING */
dnl
#if RSB_OBSOLETE_QUARANTINE_UNUSED
rsb_err_t rsb__do_account_sorted_optimized(
struct rsb_mtx_t * mtxAp,
const rsb_coo_idx_t * IA, const rsb_coo_idx_t * JA,
const rsb_coo_idx_t Idim, const rsb_coo_idx_t Jdim,
const rsb_nnz_idx_t nnz, const struct rsb_mtx_partitioning_info_t * pinfop,
rsb_nnz_idx_t * elements_per_block_row,
rsb_nnz_idx_t * blocks_per_block_row
)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/**
* \ingroup gr_internals
* FIXME : document this
*/
rsb_coo_idx_t blockrows = 0;
rsb_coo_idx_t blockcolumns = 0;
rsb_coo_idx_t baserow = 0;
rsb_coo_idx_t basecolumn = 0;
dnl rsb_nnz_idx_t block_count = 0;
dnl rsb_nnz_idx_t *indptr = mtxAp->indptr;
dnl rsb_nnz_idx_t *bpntr = mtxAp->bpntr;
dnl rsb_nnz_idx_t *bindx = mtxAp->bindx;
const rsb_coo_idx_t *Mpntr = NULL;
const rsb_coo_idx_t *mpntr = NULL;
const rsb_coo_idx_t *MIndx = NULL;
const rsb_coo_idx_t *mIndx = NULL;
rsb_blk_idx_t mI = 0, MI = 0;
rsb_err_t errval = RSB_ERR_NO_ERROR;
rsb_nnz_idx_t k = 0; /* will index a nnz sized array */
int K = 0;
dnl if(0)
dnl //if( flags & RSB_FLAG_SHOULD_DEBUG )
dnl errval = rsb__do_account_sorted( mtxAp, IA, JA, nnz, pinfop, elements_per_block_row, blocks_per_block_row);
if(nnz==0)
{
/* FIXME: new case, incomplete (useful for diagonal implicit matrices) */
return RSB_ERR_NO_ERROR;
}
#if RSB_WANT_EXPERIMENTAL_NO_EXTRA_CSR_ALLOCATIONS
if(!pinfop)
{
/* a performance fix */
if(mtxAp->flags & RSB_FLAG_WANT_COLUMN_MAJOR_ORDER)
return rsb__do_account_sorted_optimized_css(JA,IA,Jdim,Idim,nnz,elements_per_block_row,blocks_per_block_row);
else
return rsb__do_account_sorted_optimized_css(IA,JA,Idim,Jdim,nnz,elements_per_block_row,blocks_per_block_row);
}
#endif
if(mtxAp->flags & RSB_FLAG_WANT_COLUMN_MAJOR_ORDER)
{
mpntr = pinfop->rpntr;
Mpntr = pinfop->cpntr;
mIndx = IA;
MIndx = JA;
}
else
{
Mpntr = pinfop->rpntr;
mpntr = pinfop->cpntr;
MIndx = IA;
mIndx = JA;
}
foreach(`matrix_storage',RSB_M4_MATRIX_STORAGE,`dnl
/* storage matrix_storage */
if( mtxAp->`matrix_storage'==RSB_M4_MATRIX_STORAGE_PREPROCESSOR_SYMBOL(matrix_storage) )
{
k = mI = MI = 0;K = 0;
#if RSB_EXPERIMENTAL_USE_PURE_BCSS_FOR_CONSTRUCTOR
rsb__get_physical_blocking_size(mtxAp, &blockrows, &blockcolumns);
RSB_ASSERT( blockrows && blockcolumns);
#else
blockrows = Mpntr[MI+1] - Mpntr[MI];
blockcolumns = mpntr[mI+1] - mpntr[mI];
#endif
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
pushdef(`RSB_M4_Mpntr',`(blockrows *($1))')dnl
pushdef(`RSB_M4_mpntr',`(blockcolumns*($1))')dnl
',`dnl
pushdef(`RSB_M4_Mpntr',`Mpntr[$1]')dnl
pushdef(`RSB_M4_mpntr',`mpntr[$1]')dnl
')dnl
k = mI = MI = K=0;
while( MIndx[k] >= RSB_M4_Mpntr(MI+1) )++MI; /* skipping preceding block rows .. */
while( mIndx[k] >= RSB_M4_mpntr(mI+1) )++mI; /* skipping preceding block columns .. */
blockrows = RSB_M4_Mpntr(MI+1) - RSB_M4_Mpntr(MI);
blockcolumns = RSB_M4_mpntr(mI+1) - RSB_M4_mpntr(mI);
baserow = RSB_M4_Mpntr(MI);
basecolumn = RSB_M4_mpntr(mI);
*elements_per_block_row = 0;
*blocks_per_block_row = 0;
elements_per_block_row[MI*0] += blockrows * blockcolumns;
blocks_per_block_row[MI] +=1;
while(RSB_LIKELY(k<nnz))
{
#ifdef DEBUG
if( MIndx[k] < baserow )
{
RSB_ERROR("k=%zd : (%zd %zd) is not ok\n",k,(rsb_printf_int_t) (MIndx[k]+1),(rsb_printf_int_t)(mIndx[k]+1));
RSB_STDERR("(minor dim. index %zd < base row %zd)\n",(rsb_printf_int_t)MIndx[k] , (rsb_printf_int_t)baserow);
errval = RSB_ERR_INTERNAL_ERROR;
goto err;
}
#endif
if( mIndx[k] >= basecolumn+blockcolumns )
{
/* new block column, for sure */
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
mI = mIndx[k]/blockcolumns;
',`
while( mIndx[k] >= RSB_M4_mpntr(mI+1) )++mI;
blockcolumns = RSB_M4_mpntr(mI+1) - RSB_M4_mpntr(mI);
')dnl
basecolumn = RSB_M4_mpntr(mI);
if( MIndx[k] >= baserow+blockrows )
{
/* new block row */
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
MI = MIndx[k]/blockrows;
',`
while( MIndx[k] >= RSB_M4_Mpntr(MI+1) )++MI;
blockrows = RSB_M4_Mpntr(MI+1) - RSB_M4_Mpntr(MI);
')dnl
baserow = RSB_M4_Mpntr(MI);
}
else
{
/* same block row */
}
*elements_per_block_row += blockrows * blockcolumns;
blocks_per_block_row[MI] +=1;
++K;
}
else
if( MIndx[k] >= baserow+blockrows )
{
/* new row block, for sure */
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
MI = MIndx[k]/blockrows;
',`
while( MIndx[k] >= RSB_M4_Mpntr(MI+1) )++MI;
blockrows = RSB_M4_Mpntr(MI+1) - RSB_M4_Mpntr(MI);
')dnl
baserow = RSB_M4_Mpntr(MI);
if( mIndx[k] < basecolumn )
{
/* new row block, new block column */
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
mI = mIndx[k]/blockcolumns;
',`
mI = 0;
while( mIndx[k] >= RSB_M4_mpntr(mI+1) )++mI;
blockcolumns = RSB_M4_mpntr(mI+1) - RSB_M4_mpntr(mI);
')dnl
basecolumn = RSB_M4_mpntr(mI);
}
else
{
/* new row block, same column */
}
/* get rid of this var : elements_per_block_row */
*elements_per_block_row += blockrows * blockcolumns;
blocks_per_block_row[MI] +=1;
++K;
}
else
{
/* same block row for sure */
}
++k;
}
errval = RSB_ERR_NO_ERROR;goto ret;
}
popdef(`RSB_M4_Mpntr')dnl
popdef(`RSB_M4_mpntr')dnl
')dnl
dnl
errval = RSB_ERR_INTERNAL_ERROR;
ret: return errval;
}
dnl
')dnl
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
#ifdef RSB_OBSOLETE_QUARANTINE_UNUSED
dnl
static rsb_err_t rsb__do_insert_sorted_optimized_css( struct rsb_mtx_t * mtxAp, const void *VA, const rsb_coo_idx_t * MIndx, const rsb_coo_idx_t * mIndx, const rsb_nnz_idx_t nnz)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/**
\ingroup gr_internals
elements_per_block_row and blocks_per_block_row arrays should be blanked.
FIXME : missing error handling.
*/
rsb_err_t errval = RSB_ERR_NO_ERROR;
rsb_nnz_idx_t n = 0;
/* in case of RSB_FLAG_EXPERIMENTAL_IN_PLACE_CSR, they are equal */
if(mtxAp->VA != VA)
rsb__memcpy(mtxAp->VA ,VA ,mtxAp->el_size*nnz);
for(n=0;n<nnz+1;++n)
mtxAp->indptr[n] = n;
for(n=0;n<mtxAp->nnz;++n)
mtxAp->bindx [n] = mIndx[n];
mtxAp->bindx [nnz] = 0;
// should also set bindx, indptr,
RSB_DO_ERR_RETURN(errval)
}
')dnl
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
dnl
#ifdef RSB_OBSOLETE_QUARANTINE_UNUSED
dnl
rsb_err_t rsb__do_insert_sorted_optimized( struct rsb_mtx_t * mtxAp, const void *VA, const rsb_coo_idx_t * IA, const rsb_coo_idx_t * JA, const rsb_nnz_idx_t nnz, const struct rsb_mtx_partitioning_info_t * pinfop)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*
* FIXME ! UNFINISHED
* and please note that linked format is incomplete, so it does not support well block column major
*/
rsb_coo_idx_t blockrows = 0;
rsb_coo_idx_t blockcolumns = 0;
rsb_coo_idx_t baserow = 0;
rsb_coo_idx_t basecolumn = 0;
dnl rsb_nnz_idx_t block_count = 0;
rsb_nnz_idx_t *indptr = mtxAp->indptr;
dnl rsb_nnz_idx_t *bpntr = mtxAp->bpntr;
rsb_nnz_idx_t *bindx = mtxAp->bindx;
const rsb_coo_idx_t *Mpntr = NULL;
const rsb_coo_idx_t *mpntr = NULL;
const rsb_coo_idx_t *MIndx = NULL;
const rsb_coo_idx_t *mIndx = NULL;
rsb_blk_idx_t mI = 0, MI = 0;
rsb_err_t errval = RSB_ERR_NO_ERROR;
rsb_nnz_idx_t k = 0; /* will index a nnz sized array */
rsb_nnz_idx_t K = 0;
if(nnz==0)
{
/* FIXME: new case, incomplete (useful for diagonal implicit matrices) */
K = 0; /* if nnz == 0 then K == 0 */
bindx[K] = 0; // the first element off the working bindx should be set to a safe value
return RSB_ERR_NO_ERROR;
}
dnl if(0)
dnl return rsb__do_insert_sorted( mtxAp, VA, IA, JA, nnz, pinfop);
#if RSB_WANT_EXPERIMENTAL_NO_EXTRA_CSR_ALLOCATIONS
if(!pinfop)
{
/* a performance fix */
if(mtxAp->flags & RSB_FLAG_WANT_COLUMN_MAJOR_ORDER)
return rsb__do_insert_sorted_optimized_css( mtxAp, VA, JA, IA, nnz );
else
return rsb__do_insert_sorted_optimized_css( mtxAp, VA, IA, JA, nnz );
}
#endif
if(mtxAp->flags & RSB_FLAG_WANT_COLUMN_MAJOR_ORDER)
{
mpntr = pinfop->rpntr;
Mpntr = pinfop->cpntr;
mIndx = IA;
MIndx = JA;
}
else
{
Mpntr = pinfop->rpntr;
mpntr = pinfop->cpntr;
MIndx = IA;
mIndx = JA;
}
foreach(`matrix_storage',RSB_M4_MATRIX_STORAGE,`dnl
foreach(`mtype',RSB_M4_TYPES,`dnl
/* type mtype, storage matrix_storage */
if( mtxAp->typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
if( mtxAp->`matrix_storage'==RSB_M4_MATRIX_STORAGE_PREPROCESSOR_SYMBOL(matrix_storage) )
{
mtype * dst = mtxAp->VA;
k = mI = MI = 0;K = 0;
#if RSB_EXPERIMENTAL_USE_PURE_BCSS_FOR_CONSTRUCTOR
rsb__get_physical_blocking_size(mtxAp, &blockrows, &blockcolumns);
RSB_ASSERT( blockrows && blockcolumns);
#else
blockrows = Mpntr[MI+1] - Mpntr[MI];
blockcolumns = mpntr[mI+1] - mpntr[mI];
#endif
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
pushdef(`RSB_M4_Mpntr',`(blockrows *($1))')dnl
pushdef(`RSB_M4_mpntr',`(blockcolumns*($1))')dnl
',`dnl
pushdef(`RSB_M4_Mpntr',`Mpntr[$1]')dnl
pushdef(`RSB_M4_mpntr',`mpntr[$1]')dnl
')dnl
ifelse(RSB_M4_IS_FORMAT_COLUMN_MAJOR(matrix_storage),1,`dnl
pushdef(`RSB_M4_IBO',`(MIndx[k]-baserow)+(mIndx[k]-basecolumn)*blockrows')dnl
',`dnl
pushdef(`RSB_M4_IBO',`(MIndx[k]-baserow)*blockcolumns+(mIndx[k]-basecolumn)')dnl
')dnl
pushdef(`RSB_M4_BLOCK_OFFSET',`
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
K * blockrows * blockcolumns
',`dnl
ifelse(RSB_M4_IS_FORMAT_LINKED_LIST(matrix_storage),1,`dnl
RSB_BLOCK_OFFSET(mtxAp,K)
dnl indptr[ K ] seems not adequate
',`dnl
indptr[ K ]
/*K * blockrows * blockcolumns*/
/*RSB_BLOCK_OFFSET(mtxAp,K)/mtxAp->el_size*/ /* FIXME : unfinished ! */
')dnl
')dnl
dnl
')dnl
while( MIndx[k] >= RSB_M4_Mpntr(MI+1) )++MI; /* skipping preceding block rows .. */
while( mIndx[k] >= RSB_M4_mpntr(mI+1) )++mI; /* skipping preceding block columns .. */
dnl blockrows = RSB_M4_Mpntr(MI+1) - RSB_M4_Mpntr(MI);
dnl blockcolumns = RSB_M4_mpntr(mI+1) - RSB_M4_mpntr(mI);
baserow = RSB_M4_Mpntr(MI);
basecolumn = RSB_M4_mpntr(mI);
bindx [ K ] = mI; /* a new block */
indptr[ K+1 ] = indptr[ K ] + blockrows * blockcolumns; /* FIXME : DUPLICATION ?! see later */
dnl DELETE THIS
ifelse(RSB_M4_IS_FORMAT_LINKED_LIST(matrix_storage),1,`dnl
{
if(RSB_WANT_VERBOSE_MESSAGES)
RSB_INFO("initializing linked lists stuff.\n");
ifelse(RSB_M4_IS_FORMAT_COLUMN_MAJOR(matrix_storage),1,`dnl
RSB_BLOCK_TRAILING_STRUCT_SET(RSB_BLOCK_TRAILING_STRUCT_GET(mtxAp,K),mI,MI,blockcolumns,blockrows,basecolumn,baserow)
',`dnl
RSB_BLOCK_TRAILING_STRUCT_SET(RSB_BLOCK_TRAILING_STRUCT_GET(mtxAp,K),MI,mI,blockrows,blockcolumns,baserow,basecolumn)
')dnl
}
')dnl
dnl dst = mtxAp->VA;
dnl dst += RSB_M4_IBO;
dnl dst += RSB_M4_BLOCK_OFFSET;
dnl {rsb_blk_idx_t ibo = 0;/* FIXME */
dnl ifelse(RSB_M4_IS_FORMAT_COLUMN_MAJOR(matrix_storage),1,`dnl
dnl ibo = RSB_GET_INTRA_BLOCK_OFFSET(mIndx[k],MIndx[k],mI,MI,mtxAp) ;
dnl ',`dnl
dnl ibo = RSB_GET_INTRA_BLOCK_OFFSET(MIndx[k],mIndx[k],MI,mI,mtxAp) ;
dnl ')dnl
dnl dst += ibo;
dnl }
if( (mtxAp->flags & RSB_FLAG_SORTED_INPUT ) != 0 && 1 /* ONLY FOR 1 X 1 BLOCKED */)
{
//RSB_STDERR("rsb__do_insert_sorted_optimized : TODO : please specialize for specific blockings ! \n");
}
while(RSB_LIKELY(k<nnz))
{
#ifdef DEBUG
if( MIndx[k] < baserow )
{
RSB_ERROR("k=%zd : (%zd %zd) is not ok\n",k, (rsb_printf_int_t)(MIndx[k]+1),(rsb_printf_int_t)(mIndx[k]+1));
RSB_STDERR("(minor dim. index %zd < base row %zd)\n",(rsb_printf_int_t)MIndx[k] , (rsb_printf_int_t)baserow);
errval = RSB_ERR_INTERNAL_ERROR;
goto err;/* NOTE : this jump could be evil */
}
#endif
if( mIndx[k] >= basecolumn+blockcolumns )
{
/* new block column, for sure */
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
mI = mIndx[k]/blockcolumns;
',`
while( mIndx[k] >= RSB_M4_mpntr(mI+1) )++mI;
blockcolumns = RSB_M4_mpntr(mI+1) - RSB_M4_mpntr(mI);
')dnl
basecolumn = RSB_M4_mpntr(mI);
if( MIndx[k] >= baserow+blockrows )
{
/* new block row */
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
MI = MIndx[k]/blockrows;
',`
while( MIndx[k] >= RSB_M4_Mpntr(MI+1) )++MI;
blockrows = RSB_M4_Mpntr(MI+1) - RSB_M4_Mpntr(MI);
')dnl
baserow = RSB_M4_Mpntr(MI);
}
else
{
/* same block row */
}
++K;
bindx [ K ] = mI; /* a new block */
indptr[ K+1 ] = indptr[ K ] + blockrows * blockcolumns;
ifelse(RSB_M4_IS_FORMAT_LINKED_LIST(matrix_storage),1,`dnl
ifelse(RSB_M4_IS_FORMAT_COLUMN_MAJOR(matrix_storage),1,`dnl
RSB_BLOCK_TRAILING_STRUCT_SET(RSB_BLOCK_TRAILING_STRUCT_GET(mtxAp,K),mI,MI,blockcolumns,blockrows,basecolumn,baserow)
',`dnl
RSB_BLOCK_TRAILING_STRUCT_SET(RSB_BLOCK_TRAILING_STRUCT_GET(mtxAp,K),MI,mI,blockrows,blockcolumns,baserow,basecolumn)
')dnl
')dnl
}
else
if( MIndx[k] >= baserow+blockrows )
{
/* new row block, for sure */
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
MI = MIndx[k]/blockrows;
',`
while( MIndx[k] >= RSB_M4_Mpntr(MI+1) )++MI;
blockrows = RSB_M4_Mpntr(MI+1) - RSB_M4_Mpntr(MI);
')dnl
baserow = RSB_M4_Mpntr(MI);
if( mIndx[k] < basecolumn )
{
/* new row block, new block column */
mI = 0;
ifelse(RSB_M4_IS_FORMAT_BCSS(matrix_storage),1,`dnl
mI = mIndx[k]/blockcolumns;
',`
while( mIndx[k] >= RSB_M4_mpntr(mI+1) )++mI;
blockcolumns = RSB_M4_mpntr(mI+1) - RSB_M4_mpntr(mI);
')dnl
basecolumn = RSB_M4_mpntr(mI);
}
else
{
/* new row block, same column */
}
++K;
bindx [ K ] = mI; /* a new block */
indptr[ K+1 ] = indptr[ K ] + blockrows * blockcolumns;
ifelse(RSB_M4_IS_FORMAT_LINKED_LIST(matrix_storage),1,`dnl
ifelse(RSB_M4_IS_FORMAT_COLUMN_MAJOR(matrix_storage),1,`dnl
RSB_BLOCK_TRAILING_STRUCT_SET(RSB_BLOCK_TRAILING_STRUCT_GET(mtxAp,K),mI,MI,blockcolumns,blockrows,basecolumn,baserow)
',`
RSB_BLOCK_TRAILING_STRUCT_SET(RSB_BLOCK_TRAILING_STRUCT_GET(mtxAp,K),MI,mI,blockrows,blockcolumns,baserow,basecolumn)
')dnl
')dnl
}
else
{
/* same block row for sure */
}
dst = mtxAp->VA;
RSB_DEBUG_ASSERT(mI>=0);
RSB_DEBUG_ASSERT(MI>=0);
ifelse(RSB_M4_IS_FORMAT_LINKED_LIST(matrix_storage),1,`dnl
/* :( */
dst = (mtype*) ( ((rsb_byte_t*)dst)+RSB_BLOCK_OFFSET(mtxAp,K) );
RSB_DEBUG_ASSERT(((rsb_byte_t*)dst)>=((rsb_byte_t*)mtxAp->VA));
dnl dst = (mtype*)((rsb_byte_t*)dst)+(K+1)*RSB_BLOCK_EXTRA_BYTES;
rsb_nnz_idx_t ibo = 0;
if(RSB_UNLIKELY(mtxAp->flags & RSB_FLAG_WANT_COLUMN_MAJOR_ORDER))
ibo = RSB_GET_INTRA_BLOCK_OFFSET(mIndx[k],MIndx[k],mI,MI,mtxAp) ;
else
ibo = RSB_GET_INTRA_BLOCK_OFFSET(MIndx[k],mIndx[k],MI,mI,mtxAp) ;
dst = (mtype*) (((rsb_byte_t*)dst)+ibo);
RSB_DEBUG_ASSERT(((rsb_byte_t*)dst)>=((rsb_byte_t*)mtxAp->VA));
',`
RSB_DEBUG_ASSERT(((rsb_byte_t*)dst)>=((rsb_byte_t*)mtxAp->VA));
dst += RSB_M4_BLOCK_OFFSET;
RSB_DEBUG_ASSERT(((rsb_byte_t*)dst)>=((rsb_byte_t*)mtxAp->VA));
dst += RSB_M4_IBO;
')dnl
RSB_DEBUG_ASSERT(((rsb_byte_t*)dst)>=((rsb_byte_t*)mtxAp->VA));
dst[0] = ((const mtype*)VA)[k];
++k;
}
if(nnz)++K; /* if nnz == 0 then K = 0 */
bindx[K] = 0; // the first element off the working bindx should be set to a safe value
return RSB_ERR_NO_ERROR; /* FIXME ! */
}
popdef(`RSB_M4_Mpntr')dnl
popdef(`RSB_M4_mpntr')dnl
popdef(`RSB_M4_IBO')dnl
popdef(`RSB_M4_BLOCK_OFFSET')dnl
dnl
')dnl
')dnl
errval = RSB_ERR_INTERNAL_ERROR;
return errval;
}
dnl
')dnl
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
#ifdef RSB_OBSOLETE_QUARANTINE_UNUSED
rsb_err_t rsb__dump_block(rsb_type_t type, const void * VA, rsb_blk_idx_t roff, rsb_blk_idx_t coff, rsb_blk_idx_t rows, rsb_blk_idx_t cols )
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* Will dump to stdout a dense matrix.
* Used for debugging purposes.
*
* FIXME : should be integrated with the macro subsystem in util.m4, and support column major order, and debugged.
*/
#if RSB_ALLOW_STDOUT
register rsb_coo_idx_t i, j;
if(RSB_BLK_MUL_OVERFLOW(rows,cols))
return RSB_ERR_LIMITS;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if(type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype))
{
for(i=0;i<rows;++i)for(j=0;j<cols;++j)
if(((mtype*)VA)[cols*i+j]!=RSB_M4_ZERO(mtype) )
{ RSB_STDOUT(""
dnl :( were %10 %10 % 20 ...
"%zd"/* FIXME : this could be any index type! */
"\t"
"%zd"
"\t"
RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_STRING(mtype)
"\n",(rsb_printf_int_t)(roff+i+1),(rsb_printf_int_t)(coff+j+1),
RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_ARG(mtype,`((mtype*)VA)[cols*i+j]'));
}
return RSB_ERR_NO_ERROR;
}
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
#else
return RSB_ERR_UNSUPPORTED_FEATURE;
#endif
}
')dnl
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
dnl
#ifdef RSB_OBSOLETE_QUARANTINE_UNUSED
rsb_err_t rsb__dump_blocks(const struct rsb_mtx_t *mtxAp)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
return RSB_ERR_UNIMPLEMENTED_YET;
#if 0
/*!
* \ingroup gr_internals
* A debug function for printing out the matrix structure.
*
* FIXME : UNFINISHED
* Note : it is extremely slow.
**/
rsb_blk_idx_t i,j;
if(!mtxAp)return RSB_ERR_BADARGS;
if(!mtxAp->options)return RSB_ERR_BADARGS;
RSB_STDERR("\t block structure :\n");
/* this prints out the matrix blocks nnz structure */
for(i=0;i<mtxAp->M_b;++i)
{
for(j=0;j<mtxAp->K_b;++j)
if((RSB_BITMAP_GET(mtxAp->options->bitmap,mtxAp->M_b,mtxAp->K_b,i,j)))
{
RSB_STDERR("1");
}
else
{
RSB_STDERR("0");
}
RSB_STDERR("\n");
}
return RSB_ERR_NO_ERROR;
#endif
}
')dnl
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
dnl
rsb_err_t rsb__test_print_csr(rsb_type_t type, rsb_flags_t flags, const rsb_coo_idx_t * IA, const rsb_coo_idx_t * JA, const void * VA, rsb_coo_idx_t rows, rsb_coo_idx_t cols, rsb_nnz_idx_t nnz, rsb_bool_t want_header, FILE*stream)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/**
* \ingroup gr_internals
* Dumps out a whole matrix, from its CSR representation.
*
* Warning : the nonzeros should be sorted on input.
*/
#if RSB_ALLOW_STDOUT
rsb_coo_idx_t k;
if( !stream )goto err;
if( !IA )goto err;
if( ( !JA || !VA ) && nnz>0 )goto err;
RSB_FPRINTF(stream,"%zd\n",(rsb_printf_int_t)rows);
/* RSB_FPRINTF(stream,"%zd\n",(rsb_printf_int_t) nnz); */
for(k=0;k<rows+1;++k) { RSB_FPRINTF(stream,"%zd\n",(rsb_printf_int_t)(IA[k]+1)); }
for(k=0;k<nnz ;++k) { RSB_FPRINTF(stream,"%zd\n",(rsb_printf_int_t)(JA[k]+1)); }
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if(type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype))
{
for(k=0;k<nnz;++k)
{
RSB_FPRINTF(stream,
RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_STRING(mtype)
"\n"
,RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_ARG(mtype,`((mtype*)VA)[k]'));
}
return RSB_ERR_NO_ERROR;
}
#endif
')dnl
err:
return RSB_ERR_GENERIC_ERROR;
#else
return RSB_ERR_UNSUPPORTED_FEATURE;
#endif
}
')dnl
dnl
dnl
rsb_err_t rsb__test_print_coo_mm(rsb_type_t type, rsb_flags_t flags, const rsb_coo_idx_t * IA, const rsb_coo_idx_t * JA, const void * VA, rsb_coo_idx_t rows, rsb_coo_idx_t cols, rsb_nnz_idx_t nnz, rsb_bool_t want_header, FILE*stream)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/**
* \ingroup gr_internals
* Dumps out a whole matrix, from its coordinates, in matrix market format.
*
* Warning : the nonzeros should be sorted on input.
*/
#if RSB_ALLOW_STDOUT
rsb_coo_idx_t k;
const char * ts = RSB_IS_MATRIX_TYPE_COMPLEX(type)?"complex":"real";
const char * ss = RSB_SYMMETRY_STRING(flags);
if( !stream )
{
goto err;
}
if( ( !IA || !JA || !VA ) && nnz > 0 )
goto err;
if( rows < 0 || cols < 0 || nnz < 0 )
goto err;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if(type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype))
{
if(want_header)RSB_FPRINTF(stream,"%%%%MatrixMarket matrix coordinate %s %s\n%zd %zd %zd\n",ts,ss,(rsb_printf_int_t)rows,(rsb_printf_int_t)cols,(rsb_printf_int_t)nnz);
/* for(k=0;k<nnz;++k) { RSB_FPRINTF(stream,"%6zd %6zd %20g\n",(rsb_printf_int_t)(IA[k]+1),(rsb_printf_int_t)(JA[k]+1),((float*)VA)[k]); }*/
for(k=0;k<nnz;++k)
{
RSB_FPRINTF(stream,
"%zd"
"\t"
"%zd"
"\t"
RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_STRING(mtype)
"\n"
,(rsb_printf_int_t)(IA[k]+1),(rsb_printf_int_t)(JA[k]+1),dnl
RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_PRINTF_ARG(mtype,`((mtype*)VA)[k]'));
}
return RSB_ERR_NO_ERROR;
}
#endif
')dnl
err:
return RSB_ERR_GENERIC_ERROR;
#else
return RSB_ERR_UNSUPPORTED_FEATURE;
#endif
}
')dnl
dnl
dnl
/*static*/ /*inline*/ size_t rsb__do_sizeof(rsb_type_t type)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*
* FIXME : UNUSED ?
*/
size_t so = 0;
switch(type)
{
/* supported RSB_M4_MATRIX_TYPES */
foreach(`type',RSB_M4_MATRIX_TYPES,`dnl
case RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(type) :
so = sizeof(type);
break;
')dnl
/* unsupported type */
default :
RSB_NULL_STATEMENT_FOR_COMPILER_HAPPINESS
}
return so;
}
')dnl
dnl
dnl
#ifdef RSB_OBSOLETE_QUARANTINE_UNUSED
dnl
ifdef(`1',`0',`dnl
rsb_err_t rsb__do_coo_sum( struct rsb_coo_mtx_t*coocp, const void *alphap, const struct rsb_coo_mtx_t*cooap, const void *betap, const struct rsb_coo_mtx_t*coobp)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
struct rsb_coo_mtx_t cooa = *cooap, coob = *coobp, cooc = *coocp;
rsb_nnz_idx_t /*rnz = 0,*/an, bn, cn;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if(cooa.typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype))
{
mtype alpha = alphap?*(mtype*)alphap:RSB_M4_ONE(mtype);
mtype beta = betap ?*(mtype*)betap :RSB_M4_ONE(mtype);
for(cn = 0, an = 0, bn = 0;an<cooa.nnz || bn<coob.nnz;)
{
rsb_nnz_idx_t ap = an, bp = bn;
if(cooa.IA[an]==coob.IA[bn] && cooa.JA[an]==coob.JA[bn])
cooc.IA[cn] = cooa.IA[an],cooc.JA[cn] = cooa.JA[an],
((mtype*)cooc.VA)[cn] = alpha * ((mtype*)cooa.VA)[an] + beta * ((mtype*)coob.VA)[bn],
ap = an, bp = bn, ++cn, ++an, ++bn;
for(;an<cooa.nnz && cooa.IA[an]==cooa.IA[ap] && cooa.JA[an]==cooa.JA[ap] ;++an)
//RSB_STDOUT("x> %d %d\n",cooa.IA[an],cooa.JA[an])
((mtype*)cooc.VA)[cn] += alpha * ((mtype*)cooa.VA)[an];
for(;bn<coob.nnz && coob.IA[bn]==coob.IA[bp] && coob.JA[bn]==coob.JA[bp] ;++bn)
//RSB_STDOUT("x> %d %d\n",coob.IA[bn],coob.JA[bn])
((mtype*)cooc.VA)[cn] += beta * ((mtype*)coob.VA)[bn];
if( bn<coob.nnz )
for(;an<cooa.nnz && (cooa.IA[an]<coob.IA[bn] ||
(cooa.IA[an] <= coob.IA[bn] && cooa.JA[an]<coob.JA[bn]))
;++an)
//RSB_STDOUT("-> %d %d\n",cooa.IA[an],cooa.JA[an]),
cooc.IA[cn] = cooa.IA[an], cooc.JA[cn] = cooa.JA[an],
((mtype*)cooc.VA)[cn] = alpha * ((mtype*)cooa.VA)[an],
++cn;
if( an<cooa.nnz )
for(;bn<coob.nnz && (cooa.IA[an]>coob.IA[bn] ||
(cooa.IA[an]>=coob.IA[bn] && cooa.JA[an]>coob.JA[bn]))
;++bn)
// RSB_STDOUT("-> %d %d\n",coob.IA[bn],coob.JA[bn]),
cooc.IA[cn] = coob.IA[bn],cooc.JA[cn] = coob.JA[bn],
((mtype*)cooc.VA)[cn] = beta * ((mtype*)coob.VA)[bn],
++cn;
//RSB_STDOUT("? %d %d\n",an,bn);
}
}
else
#endif
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
')dnl
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
dnl
dnl
rsb_err_t rsb__cor_merge_dups(rsb_type_t typecode, void* RSB_RESTRICT VA, rsb_coo_idx_t * RSB_RESTRICT IA, rsb_coo_idx_t * RSB_RESTRICT JA, rsb_nnz_idx_t offB, rsb_nnz_idx_t nnzB, rsb_nnz_idx_t nnzC, const int wv, int wp, rsb_nnz_idx_t *onzp, struct rsb_coo_mtx_t*RSB_RESTRICT coop)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/**
See rsb__cor_merge.
*/
rsb_err_t errval = RSB_ERR_NO_ERROR;
void *VB = NULL, *VC = NULL, *VT = NULL;
rsb_coo_idx_t * IB = NULL, *JB = NULL;
rsb_coo_idx_t * IC = NULL, *JC = NULL;
rsb_coo_idx_t * IT = NULL, *JT = NULL;
rsb_nnz_idx_t bi = 0, ci = 0, ti = 0;
rsb_nnz_idx_t b0 = 0, c0 = 0;
rsb_nnz_idx_t onz = 0;
struct rsb_coo_mtx_t coo;
size_t es = RSB_SIZEOF(typecode);
if( nnzB == 0 || nnzC == 0 )
{
goto ret;
}
b0 = offB;
c0 = offB + nnzB;
VB = RSB_TYPED_OFF_PTR(typecode,VA,b0);
VC = RSB_TYPED_OFF_PTR(typecode,VA,c0);
IB = IA + b0;
IC = IA + c0;
JB = JA + b0;
JC = JA + c0;
RSB_BZERO_P(&coo);
coo.nnz = nnzB + nnzC;
coo.typecode = typecode;
if( coop && coop->nnz)
{
coo = *coop;
coo.nnz = nnzB + nnzC; /* necessary */
}
else
{
if( NULL == rsb__allocate_coo_matrix_t(&coo) )
goto err;
}
IT = coo.IA;
JT = coo.JA;
VT = coo.VA;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if(typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype))
{
mtype * vT = VT;
mtype * vB = VB;
mtype * vC = VC;
again`_'RSB_M4_CHOPSPACES(mtype):
if ( bi<nnzB && ci<nnzC && RSB_COO_LT(IB[bi],JB[bi],IC[ci],JC[ci]) )
{
IT[ti] = IB[bi];
JT[ti] = JB[bi];
vT[ti] = vB[bi];
++bi,++ti;
}
while( bi<nnzB && ci<nnzC && RSB_COO_LT(IB[bi],JB[bi],IC[ci],JC[ci]) && ti > 0 && RSB_COO_EQ(IB[bi],JB[bi],IT[ti-1],JT[ti-1]) )
{
--ti;
vT[ti] += vB[bi];
++bi;
++ti;
++onz;
}
/* FIXME: this works as RSB_FLAG_DUPLICATES_SUM but should support either merge, last, first, ... */
if ( bi<nnzB && ci<nnzC && RSB_COO_EQ(IB[bi],JB[bi],IC[ci],JC[ci]) )
{
IT[ti] = IB[bi];
JT[ti] = JB[bi];
vT[ti] = vB[bi] + vC[ci];
++bi,++ci,++ti;
++onz;
}
while( bi<nnzB && ci<nnzC && RSB_COO_EQ(IB[bi],JB[bi],IC[ci],JC[ci]) && ti > 0 && RSB_COO_EQ(IB[bi],JB[bi],IT[ti-1],JT[ti-1]) )
{
--ti;
vT[ti] += vB[bi] + vC[ci];
++bi;
++ci;
++ti;
++onz;
}
if ( bi<nnzB && ci<nnzC && RSB_COO_GT(IB[bi],JB[bi],IC[ci],JC[ci]) )
{
IT[ti] = IC[ci];
JT[ti] = JC[ci];
vT[ti] = vC[ci];
++ci,++ti;
}
while( bi<nnzB && ci<nnzC && RSB_COO_GT(IB[bi],JB[bi],IC[ci],JC[ci]) && ti > 0 && RSB_COO_EQ(IC[ci],JC[ci],IT[ti-1],JT[ti-1]) )
{
--ti;
vT[ti] += vC[ci];
++ci;
++ti;
++onz;
}
if( ci < nnzC && bi < nnzB )
goto again`_'RSB_M4_CHOPSPACES(mtype);
again`_once_'RSB_M4_CHOPSPACES(mtype):
if ( bi<nnzB && ci==nnzC )
{
IT[ti] = IB[bi];
JT[ti] = JB[bi];
vT[ti] = vB[bi];
++bi,++ti;
}
while( bi<nnzB && ci==nnzC && ti > 0 && RSB_COO_EQ(IB[bi],JB[bi],IT[ti-1],JT[ti-1]) )
{
--ti;
vT[ti] += vB[bi];
++bi;
++ti;
++onz;
}
if ( ci<nnzC && bi==nnzB )
{
IT[ti] = IC[ci];
JT[ti] = JC[ci];
vT[ti] = vC[ci];
++ci,++ti;
}
while( ci<nnzC && bi==nnzB && ti > 0 && RSB_COO_EQ(IC[ci],JC[ci],IT[ti-1],JT[ti-1]) )
{
--ti;
vT[ti]+= vC[ci];
++ci;
++ti;
++onz;
}
if( ci < nnzC || bi < nnzB )
goto again`_once_'RSB_M4_CHOPSPACES(mtype);
}
else
#endif
')dnl
errval = RSB_ERR_INTERNAL_ERROR;
coo.nnz -= onz;
RSB_COA_MEMCPY(IA,IT,offB,0,(coo.nnz));
RSB_COA_MEMCPY(JA,JT,offB,0,(coo.nnz));
if(wp)
{
RSB_A_MEMCPY_parallel( VA,VT,offB,0,(coo.nnz),es);
}
else
{
RSB_A_MEMCPY( VA,VT,offB,0,(coo.nnz),es);
}
RSB_ASSERT(rsb__util_is_coo_array_sorted_up_partial_order(IA,coo.nnz));
goto done;
err:
errval = RSB_ERR_ENOMEM;
done:
if( coop && coop->nnz)
;
else
rsb__destroy_coo_matrix_t(&coo);
RSB_ASSIGN_IF(onzp,onz);
ret:
return errval;
}
')dnl
dnl
dnl
rsb_err_t rsb__do_copy_converted_scaled(const void *RSB_RESTRICT src, void *RSB_RESTRICT dst, const void *RSB_RESTRICT alphap, rsb_type_t stype,rsb_type_t dtype, size_t nnz, rsb_trans_t transA)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* Copies scaled and conj-transposed.
* alpha according to src code type.
* \return \rsberrcodemsg
* */
rsb_nnz_idx_t nzi;
if((!dst) || (!src))
return RSB_ERR_BADARGS;
foreach(`mtypea',RSB_M4_TYPES,`dnl
foreach(`mtypeb',RSB_M4_TYPES,`dnl
if( stype == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtypea) && dtype == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtypeb) )
{
const mtypea alpha = alphap?*(mtypea*)alphap:RSB_M4_ONE(mtypea);
const mtypea*tsrc = src;
mtypeb*tdst = dst;
ifelse(RSB_M4_AND(RSB_M4_IS_COMPLEX_TYPE(mtypeb)),1,`dnl
if(RSB_DOES_CONJUGATE(transA))
for(nzi=0;nzi<nnz;++nzi) RSB_M4_ASSIGN(mtypeb,mtypea,`tdst[nzi]',`(mtypeb)(alpha*RSB_M4_CONJ(`tsrc[nzi]',mtypeb,RSB_M4_TRANS_C,RSB_M4_SYMBOL_UNSYMMETRIC))')
else
')dnl
for(nzi=0;nzi<nnz;++nzi) RSB_M4_ASSIGN(mtypeb,mtypea,`tdst[nzi]',`(mtypeb)(alpha*tsrc[nzi])')
}
else
')dnl
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_csc2csr(const void *RSB_RESTRICT VA, const rsb_coo_idx_t * RSB_RESTRICT IA, const rsb_coo_idx_t * RSB_RESTRICT JA, void *RSB_RESTRICT oVA, rsb_coo_idx_t * RSB_RESTRICT oIA, rsb_coo_idx_t * RSB_RESTRICT oJA, rsb_coo_idx_t m, rsb_coo_idx_t k, rsb_nnz_idx_t nnz, rsb_type_t typecode, const rsb_coo_idx_t offi, const rsb_coo_idx_t offo, rsb_flags_t*flagsp)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* */
rsb_nnz_idx_t nzi = 0, nzo;
rsb_coo_idx_t nr, nc;
rsb_flags_t flags = RSB_FLAG_NOFLAGS;
rsb_bool_t islowtri = RSB_BOOL_TRUE, isupptri = RSB_BOOL_TRUE;
rsb_nnz_idx_t lowtrin = 0, upptrin = 0;
RSB_BZERO(oIA, sizeof(*oIA)*(m+1));
oIA[0] = offo;
for(nzi=0;nzi<nnz;++nzi)
oIA[IA[nzi]-offi+1]++;
for(nr=0;nr<m;++nr)
oIA[nr+1]+=oIA[nr];
foreach(`mtype',RSB_M4_TYPES,`dnl
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
for(nc=0;nc<k;++nc)
for(nzi = JA[nc]-offi;nzi<JA[nc+1]-offi;++nzi)
{
nzo = oIA[IA[nzi]-offi]++;
oJA[nzo] = nc+offo;
((mtype*)oVA)[nzo] = ((const mtype*)VA)[nzi];
}
else
')dnl
return RSB_ERR_UNSUPPORTED_TYPE;
for(nc=0;nc<k;++nc)
for(nzi=JA[nc]-offi;nzi<JA[nc+1]-offi;++nzi)
{
oIA[IA[nzi]-offi]--;
if(IA[nzi]-offi>nc)
lowtrin++;
else
if(IA[nzi]-offi<nc)
upptrin++;
}
if(upptrin)
islowtri = RSB_BOOL_FALSE;
if(lowtrin)
isupptri = RSB_BOOL_FALSE;
if(isupptri)
RSB_DO_FLAG_ADD(flags,RSB_FLAG_UPPER);
if(islowtri)
RSB_DO_FLAG_ADD(flags,RSB_FLAG_LOWER);
if( RSB_XOR(upptrin,lowtrin) )
RSB_DO_FLAG_ADD(flags,RSB_FLAG_TRIANGULAR);
if(*flagsp) RSB_DO_FLAG_ADD(*flagsp,flags);
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_coo_copy_and_stats(const void *RSB_RESTRICT VA, const rsb_coo_idx_t * RSB_RESTRICT IA, const rsb_coo_idx_t * RSB_RESTRICT JA, void *RSB_RESTRICT oVA, rsb_coo_idx_t * RSB_RESTRICT oIA, rsb_coo_idx_t * RSB_RESTRICT oJA, rsb_coo_idx_t*m, rsb_coo_idx_t*k, const rsb_nnz_idx_t nnz, const rsb_type_t typecode, const rsb_coo_idx_t offi, const rsb_coo_idx_t offo, rsb_flags_t iflags, rsb_flags_t*flagsp)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* FIXME: unfinished! shall support also typecode-based zeros removal
* */
rsb_nnz_idx_t nzi = 0;
rsb_coo_idx_t maxi = 0,maxj = 0;
rsb_bool_t islowtri = RSB_BOOL_TRUE,isupptri = RSB_BOOL_TRUE;
rsb_flags_t flags = RSB_FLAG_NOFLAGS;
rsb_nnz_idx_t lowtrin = 0,upptrin = 0;
if(nnz<1)
goto done;
foreach(`mtype',RSB_M4_TYPES,`dnl
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
rsb_coo_idx_t i = IA[nzi], j = JA[nzi];
maxi = i, maxj = j;
((mtype*)oVA)[nzi] = ((mtype*)VA)[nzi];
oIA[nzi] = i-offi+offo;
oJA[nzi] = j-offi+offo;
lowtrin |= (i>j), upptrin |= (i<j);
for(nzi=1;RSB_LIKELY(nzi<nnz);++nzi)
dnl RSB_M4_SIMPLE_LOOP_UNROLL(`nzi',`LI',`1',`nnz',`
dnl /* if ( is non zero ... ) */
{
dnl if(IA[nzi+LI]>maxi) maxi = IA[nzi+LI];
dnl if(JA[nzi+LI]>maxj) maxj = JA[nzi+LI];
dnl const rsb_coo_idx_t i = IA[nzi+LI],j = JA[nzi+LI];
rsb_coo_idx_t i = IA[nzi],j = JA[nzi];
maxi = RSB_MAX(maxi, i);
maxj = RSB_MAX(maxj, j);
((mtype*)oVA)[nzi] = ((mtype*)VA)[nzi];
oIA[nzi] = i-offi+offo;
oJA[nzi] = j-offi+offo;
dnl ((mtype*)oVA)[nzi+LI] = ((mtype*)VA)[nzi+LI];
dnl oIA[nzi+LI] = i-offi+offo;
dnl oJA[nzi+LI] = j-offi+offo;
dnl if(IA[nzi+LI]>JA[nzi+LI])isupptri = RSB_BOOL_FALSE;
dnl else if(IA[nzi+LI]<JA[nzi+LI])islowtri = RSB_BOOL_FALSE;
lowtrin |= (i>j);
upptrin |= (i<j);
}
dnl ')
}
else
')dnl
return RSB_ERR_UNSUPPORTED_TYPE;
if(upptrin)
islowtri = RSB_BOOL_FALSE;
if(lowtrin)
isupptri = RSB_BOOL_FALSE;
if(isupptri)
RSB_DO_FLAG_ADD(flags,RSB_FLAG_UPPER);
if(islowtri)
RSB_DO_FLAG_ADD(flags,RSB_FLAG_LOWER);
if( RSB_XOR(upptrin,lowtrin) )
RSB_DO_FLAG_ADD(flags,RSB_FLAG_TRIANGULAR);
if(flagsp) RSB_DO_FLAG_ADD(*flagsp,flags);
if(flagsp)
if(RSB_DO_FLAG_HAS_INTERSECTION(*flagsp,RSB_FLAG_ANY_SYMMETRY))
maxi = maxj = RSB_MAX(maxi,maxj);
if(m) *m = maxi+1;
if(k) *k = maxj+1;
done:
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
rsb_err_t rsb__util_coo_copy(const void *RSB_RESTRICT VA, const rsb_coo_idx_t * RSB_RESTRICT IA, const rsb_coo_idx_t * RSB_RESTRICT JA, void *RSB_RESTRICT oVA, rsb_coo_idx_t * RSB_RESTRICT oIA, rsb_coo_idx_t * RSB_RESTRICT oJA, const rsb_nnz_idx_t nnz, const rsb_type_t typecode, const rsb_coo_idx_t offi, const rsb_coo_idx_t offo)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* FIXME: unfinished! shall support also typecode-based zeros removal
* */
rsb_nnz_idx_t nzi = 0;
dnl rsb_flags_t flags = RSB_FLAG_NOFLAGS;
foreach(`mtype',RSB_M4_TYPES,`dnl
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
for(nzi=0;RSB_LIKELY(nzi<nnz);++nzi)
dnl RSB_M4_SIMPLE_LOOP_UNROLL(`nzi',`LI',`1',`nnz',`
dnl /* if ( is non zero ... ) */
{
dnl const rsb_coo_idx_t i = IA[nzi+LI],j = JA[nzi+LI];
rsb_coo_idx_t i = IA[nzi], j = JA[nzi];
((mtype*)oVA)[nzi] = ((mtype*)VA)[nzi];
oIA[nzi] = i-offi+offo;
oJA[nzi] = j-offi+offo;
dnl ((mtype*)oVA)[nzi+LI] = ((mtype*)VA)[nzi+LI];
dnl oIA[nzi+LI] = i-offi+offo;
dnl oJA[nzi+LI] = j-offi+offo;
}
dnl ')
}
else
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
dnl done:
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
/* sparse blas level 1 equivalent functions */
dnl
int rsb__BLAS_Xusdot(const rsb_type_t typecode, const enum blas_conj_type conj_arg, const rsb_blas_int_t nz, const void*x, const rsb_blas_int_t*indx, const void*y, const rsb_blas_int_t incy, void*r, const enum blas_base_type index_base)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
\rsb_spblasl1_dot_msg
\rsb_warn_untested_msg
*/
foreach(`mtype',RSB_M4_TYPES,`dnl
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*xa = (mtype*)x;
mtype*ya = (mtype*)y;
mtype*rp = (mtype*)r;
mtype ac = RSB_M4_ZERO(mtype);
rsb_blas_int_t nzi, xi;
if( index_base == blas_one_base )
ya-=incy;
ifelse(RSB_M4_AND(RSB_M4_IS_COMPLEX_TYPE(mtype)),1,`dnl
if( conj_arg == blas_conj )
for(nzi=0;RSB_LIKELY(nzi<nz);++nzi)
{
xi = indx[nzi];
ac += RSB_M4_CONJ(xa[nzi],mtype,RSB_M4_TRANS_C,RSB_M4_SYMBOL_UNSYMMETRIC) * ya[xi*incy];
}
else
')dnl
for(nzi=0;RSB_LIKELY(nzi<nz);++nzi)
{
xi = indx[nzi];
ac += xa[nzi] * ya[xi*incy];
}
RSB_SET_IF_NOT_NULL(rp,ac);
}
else
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
int rsb__BLAS_Xusaxpy(const rsb_type_t typecode, const rsb_blas_int_t nz, const void*alpha, const void*x, const rsb_blas_int_t*indx, const void*y, const rsb_blas_int_t incy, const enum blas_base_type index_base)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
\rsb_spblasl1_axpy_msg
\rsb_warn_untested_msg
*/
foreach(`mtype',RSB_M4_TYPES,`dnl
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*xa = (const mtype*)x;
mtype*ya = (mtype*)y;
const mtype alphav = *(mtype*)alpha;
rsb_blas_int_t nzi, xi;
if( index_base == blas_one_base )
ya-=incy;
for(nzi=0;RSB_LIKELY(nzi<nz);++nzi)
{
xi = indx[nzi];
ya[nzi*incy] += alphav*xa[xi];
}
}
else
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
int rsb__BLAS_Xusga(const rsb_type_t typecode, const rsb_blas_int_t nz, const void*y, const rsb_blas_int_t incy, void*x, const rsb_blas_int_t*indx, const enum blas_base_type index_base)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
\rsb_spblasl1_ga_msg
\rsb_warn_untested_msg
*/
foreach(`mtype',RSB_M4_TYPES,`dnl
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*xa = (mtype*)x;
const mtype*ya = (const mtype*)y;
rsb_blas_int_t nzi,xi;
if( index_base == blas_one_base )
ya-=incy;
for(nzi=0;RSB_LIKELY(nzi<nz);++nzi)
{
xi = indx[nzi];
xa[nzi] = ya[xi*incy];
}
}
else
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
int rsb__BLAS_Xusgz(const rsb_type_t typecode, const rsb_blas_int_t nz, void*y, const rsb_blas_int_t incy, void*x, const rsb_blas_int_t*indx, const enum blas_base_type index_base)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
\rsb_spblasl1_gz_msg
\rsb_warn_untested_msg
*/
foreach(`mtype',RSB_M4_TYPES,`dnl
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype*xa = (mtype*)x;
mtype*ya = (mtype*)y;
rsb_blas_int_t nzi,xi;
if( index_base == blas_one_base )
ya-=incy;
for(nzi=0;RSB_LIKELY(nzi<nz);++nzi)
{
xi = indx[nzi];
xa[nzi] = ya[xi*incy];
ya[xi*incy] = RSB_M4_ZERO(mtype);
}
}
else
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
int rsb__BLAS_Xussc(const rsb_type_t typecode, const rsb_blas_int_t nz, const void*x, void*y, const rsb_blas_int_t incy, const rsb_blas_int_t*indx, const enum blas_base_type index_base)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
\rsb_spblasl1_sc_msg
\rsb_warn_untested_msg
*/
foreach(`mtype',RSB_M4_TYPES,`dnl
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*xa = (const mtype*)x;
mtype*ya = (mtype*)y;
rsb_blas_int_t nzi,xi;
if( index_base == blas_one_base )
ya-=incy;
for(nzi=0;RSB_LIKELY(nzi<nz);++nzi)
{
xi = indx[nzi];
ya[xi*incy] = xa[nzi];
}
}
else
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
/* blas level 1 equivalent functions */
dnl
dnl
rsb_err_t rsb__cblas_Xcopy(rsb_type_t typecode, rsb_nnz_idx_t n, const void * x, rsb_nnz_idx_t incx, void * y, rsb_nnz_idx_t incy)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
return rsb__xcopy_strided_typed(y,x,0,0,n,typecode,incy,incx);
}
')dnl
dnl
dnl
rsb_err_t rsb__cblas_Xnrm2(rsb_type_t type, size_t n, const void * a, rsb_nnz_idx_t incA, void * c)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* c <- sqrt(sum(|a_i|^2))
*
* \param a an array pointer
* \param type a valid type code
* \param n the input array length
* \note see dznrm2 in BLAS
*
* \return \rsberrcodemsg
* */
size_t i;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( type == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
const mtype*ta = a;RSB_M4_REALT(mtype) *tc = c,acc = RSB_M4_ZERO(mtype),tmp = RSB_M4_ZERO(mtype);
RSB_M4_SIMPLE_LOOP_UNROLL(`i',`LI',`0',`n',`dnl
acc = RSB_M4_ABS(mtype,ta[(i+LI)*incA]);tmp += acc*acc;
');
tc[0] = RSB_M4_CREAL(mtype,RSB_M4_SQRT(mtype,tmp));
}
else
#endif /* RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) */
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
dnl
#ifdef RSB_OBSOLETE_QUARANTINE_UNUSED
dnl
rsb_err_t rsb__cblas_Xdotu_sub(rsb_type_t type, size_t n, const void * x, rsb_nnz_idx_t incx, const void * y, rsb_nnz_idx_t incy, void *dotu)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* */
return rsb__vector_mult_sum(x,y,dotu,type,n,incx,incy);
}
')dnl
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
rsb_err_t rsb__cblas_Xscal(rsb_type_t type, size_t n, const void * alphap, void * a, size_t stride)dnl
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*!
* a <- a * alpha
* */
return rsb_strided_vector_scale(a,alphap,type,n,stride);
}
')dnl
dnl
dnl
dnl
#ifdef RSB_OBSOLETE_QUARANTINE_UNUSED
rsb_err_t rsb__coo_insertion_sort(rsb_type_t typecode, void* VB, rsb_coo_idx_t * IB, rsb_coo_idx_t * JB, rsb_nnz_idx_t offA, rsb_nnz_idx_t nnzA)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/* only for *small* arrays, where allocation of a temporary array is not justified */
rsb_coo_idx_t * IA = NULL, *JA = NULL;
rsb_nnz_idx_t i, j;
IA = IB + offA;
JA = JB + offA;
foreach(`mtype',RSB_M4_TYPES,`dnl
`#ifdef 'RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype)
if( typecode == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) )
{
mtype * VA = (mtype*) RSB_TYPED_OFF_PTR(typecode,VB,offA);
for(i=1;i<nnzA;++i)
for(j=i;j>0 && RSB_COO_LT(IA[j],JA[j],IA[j-1],JA[j-1]);--j)
{
RSB_SWAP(rsb_coo_idx_t,IA[j],IA[j-1]);
RSB_SWAP(rsb_coo_idx_t,JA[j],JA[j-1]);
RSB_SWAP(mtype ,VA[j],VA[j-1]);
}
}
else
#endif /* RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype) */
')dnl
return RSB_ERR_UNSUPPORTED_TYPE ;
return RSB_ERR_NO_ERROR;
}
')dnl
dnl
#endif /* RSB_OBSOLETE_QUARANTINE_UNUSED */
dnl
void rsb__coo_to_lr( void * RSB_RESTRICT VBu, rsb_coo_idx_t*RSB_RESTRICT IB, rsb_coo_idx_t*RSB_RESTRICT JB, void * RSB_RESTRICT VAu, rsb_coo_idx_t*RSB_RESTRICT IA, rsb_coo_idx_t*RSB_RESTRICT JA, rsb_coo_idx_t mj, rsb_nnz_idx_t nnzA, rsb_nnz_idx_t nzoffB, rsb_nnz_idx_t nzoffA, rsb_nnz_idx_t*RSB_RESTRICT nzlp, rsb_nnz_idx_t*RSB_RESTRICT nzrp, rsb_coo_idx_t iadd, rsb_coo_idx_t jadd, rsb_type_t typecode)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
/*
* Given COO arrays matrices A and (temporary) B, store the coefficients left of the mj-th column before the one coming after it, respecting their original ordering.
* A serial function.
* Each of arrays VAu, IA, JA fit nzoffA+nnzA elements.
* Each of arrays VBu, IB, JB fit nzoffB+nnzA elements.
* *nzlp will be set to the count of the elements left of mj.
* *nzrp will be set to the count of the elements right of mj.
* iadd will be added to the each of the nnzA IA element.
* jadd will be added to the each of the nnzA JA element which is >= mj.
* */
rsb_nnz_idx_t nzl = 0, nzr = 0, nzi = 0;
RSB_DEBUG_ASSERT(IA!=IB);
RSB_DEBUG_ASSERT(JA!=JB);
IA += nzoffA;
JA += nzoffA;
IB += nzoffB;
JB += nzoffB;
switch(typecode)
{
/* supported RSB_M4_MATRIX_TYPES */
foreach(`type',RSB_M4_MATRIX_TYPES,`dnl
case RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(type) :
{
type * VA = ((type *)VAu) + nzoffA;
type * VB = ((type *)VBu) + nzoffB;
RSB_DEBUG_ASSERT(VA!=VB);
/* visit IA, JA, VA */
for(nzi=0;nzi<nnzA;++nzi)
{
if( JA[nzi] < mj )
{
/* elements left of mj go to the beginning of IB,JB,VB */
IB[nzl] = IA[nzi] + iadd;
JB[nzl] = JA[nzi];
VB[nzl] = VA[nzi];
nzl++;
}
else
{
/* elements right of mj go to the end of IB,JB,VB, reversed */
nzr++;
IB[nnzA-nzr] = IA[nzi] + iadd;
JB[nnzA-nzr] = JA[nzi] + jadd;
VB[nnzA-nzr] = VA[nzi];
}
}
/* first nzl elements lay left of mj; the last nzr are right of mj, reversed */
RSB_DEBUG_ASSERT( nzl+nzr == nnzA );
/* copy left elements back to A */
for(nzi=0;nzi<nzl ;++nzi)
{
IA[nzi] = IB[nzi];
JA[nzi] = JB[nzi];
VA[nzi] = VB[nzi];
}
/* copy right elements back to A, reversed to original relative order */
for( ;nzi<nnzA;++nzi)
{
IA[nzi] = IB[nnzA-(1+nzi-nzl)];
JA[nzi] = JB[nnzA-(1+nzi-nzl)];
VA[nzi] = VB[nnzA-(1+nzi-nzl)];
}
}
break;
')dnl
/* unsupported type */
default :
RSB_NULL_STATEMENT_FOR_COMPILER_HAPPINESS
}
*nzlp = nzl;
*nzrp = nzr;
}')dnl
dnl
dnl
rsb_err_t rsb__util_testall(void)
ifdef(`ONLY_WANT_HEADERS',`;',`dnl
{
dnl
rsb_err_t errval = RSB_ERR_NO_ERROR;
rsb_blk_idx_t inc;
dnl
RSB_STDOUT("MTX PRINT TEST BEGIN\n");
foreach(`mtype',RSB_M4_TYPES,`dnl
{
const mtype iVA [] = {1,2};
const rsb_coo_idx_t iIA[] = {0,1};
const rsb_coo_idx_t iJA[] = {0,1};
mtype oVA [] = {-1,-2};
rsb_coo_idx_t oJA[] = {-1,-2};
rsb_coo_idx_t oIA[] = {-1,-2};
rsb_coo_idx_t m=0,k=0;
const rsb_nnz_idx_t nnz=2;
const rsb_type_t typecode = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype);
const rsb_coo_idx_t offi=0, offo=0;
mtype exp = RSB_M4_ZERO(mtype);
const mtype alpha = 2;
mtype res = 1;
rsb_flags_t iflags=RSB_FLAG_NOFLAGS, *flagsp=&iflags;
inc = 1;
// {-1,-2} -> {+1,+2}
errval = rsb__util_coo_copy_and_stats(iVA, iIA, iJA, oVA, oIA, oJA, &m, &k, nnz, typecode, offi, offo, iflags, flagsp);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+1,+2} -> {+1,+2}
errval = rsb__util_coo_copy_and_stats(iVA, iIA, iJA, oVA, oIA, oJA, NULL, NULL, nnz, typecode, offi, offo, iflags, NULL);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,oVA,typecode,nnz,inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=3) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+1,+2} -> {+2,+4}
errval = rsb__cblas_Xscal(typecode, nnz, &alpha, oVA, inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,oVA,typecode,nnz,inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=6) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+2,+4} -> {+4,+8}
errval = rsb_strided_vector_scale(oVA,&alpha,typecode,nnz,inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,oVA,typecode,nnz,inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=12) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+4,+8} -> {+2,+1}
oVA[0] /= 2; // avoid pow roundoff errors
oVA[1] /= 8; // avoid pow roundoff errors
errval = rsb__util_vector_pow(oVA, typecode, &alpha, nnz);
// {+2,+1} -> {+4,+1}
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,oVA,typecode,nnz,inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=5) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+4,+1} -> {+1,+1}
errval = rsb__util_vector_pow(oVA, typecode, &exp, nnz);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+1,+1} -> {+2,+1}
errval = rsb_strided_vector_scale(oVA, &alpha, typecode, nnz*0+1, inc*2); // test for inc==2
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,oVA,typecode,nnz,inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=3) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__test_print_coo_mm(typecode, iflags, oIA, oJA, oVA, m, k, nnz, RSB_BOOL_TRUE, RSB_DEFAULT_STREAM);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
}
')
dnl
RSB_STDOUT("MTX PRINT TEST END\n");
foreach(`mtype',RSB_M4_TYPES,`dnl
for(inc=1;inc<=2;++inc)
{
const rsb_type_t type = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype);
const mtype VA [] = {1,0,2,0,3,0};
const mtype VAL[17] = {1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1};
mtype nrm2[2] = {0,-1};
const rsb_nnz_idx_t n = sizeof(VA)/(sizeof(VA[0])*inc);
// TODO: maybe get rid of redundance here.
errval = rsb__util_vector_sum_strided(&nrm2[0], VA, type, n, inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__cblas_Xnrm2(type, n, VA, inc, &nrm2[1]);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(nrm2[0]!=nrm2[0]) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__cblas_Xnrm2(type, 17, VAL, 1, &nrm2[1]);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(roundf(nrm2[1]) != 4 ) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
}
for(inc=1;inc<=2;++inc)
{
const rsb_type_t type = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype);
mtype VA [] = {+1,-1,+3,-3,+4,-4};
const mtype VAU[] = {+0,+0,+3,-3,+4,-4};
const mtype VAA[] = {+0,+0,+3,-3,+0,+0};
mtype soad = RSB_M4_ZERO(mtype);
const rsb_nnz_idx_t n = sizeof(VA)/(sizeof(VA[0])*inc);
#if defined(__INTEL_COMPILER) /* meant to circumvent e.g. icc -O2 -fp-model fast=2 (observed on 19.1.2.254 or 2021.3.0) */
const mtype lthr = 3 * 0.95, hthr = 3 * 1.05;
#else
const mtype lthr = 3, hthr = 3;
#endif
errval = rsb__util_drop_to_zero_if_under_threshold(VA,type,n,<hr);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__vector_sum_of_abs_diffs(&soad,VA,VAU,type,n);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(soad) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_drop_to_zero_if_above_threshold(VA,type,n,&hthr);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__vector_sum_of_abs_diffs(&soad,VA,VAA,type,n);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(soad) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
}
')dnl
dnl
RSB_STDOUT("DIFF PRINT TEST BEGIN\n");
foreach(`mtype',RSB_M4_TYPES,`dnl
{
const rsb_type_t type = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype);
const mtype VAU[] = {+0,+0,+3,-3,+4,-4};
const mtype VAA[] = {+0,+0,+3,-3,+0,+0};
const rsb_nnz_idx_t n = sizeof(VAU)/(sizeof(VAU[0]));
// TODO: beef this test up; add e.g. quiet option to rsb__debug_print_vectors_diff
errval = rsb__debug_print_vectors_diff(VAU,VAA,n,type,1,1,0);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
}
')dnl
dnl
dnl
foreach(`mtype',RSB_M4_TYPES,`dnl
for(inc=1;inc<=2;++inc)
{
const rsb_type_t type = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype);
const mtype VAU[] = {+0,+0,+3,-3,+4,-4};
const mtype VAA[] = {+0,+0,+3,-3,+0,+0};
const rsb_nnz_idx_t n = sizeof(VAU)/(sizeof(VAU[0])*inc);
errval = rsb__debug_print_vectors(VAU,VAA,n,1,inc,type);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__debug_print_vector(VAU,n,type,inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
}
')dnl
RSB_STDOUT("DIFF PRINT TEST END\n");
dnl
dnl
foreach(`mtype',RSB_M4_TYPES,`dnl
{
const int inc = 1;
const rsb_type_t type = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype);
mtype v1[] = {+1,+0,+5,-2,+4,-6};
mtype v2[] = {+2,+0,+3,-2,+0,+0};
const rsb_nnz_idx_t off = 1;
const rsb_nnz_idx_t n = sizeof(v1)/(sizeof(v1[0])*inc)-off;
const mtype zero = RSB_M4_ZERO(mtype), sum = 2;
mtype res = zero;
rsb_nnz_idx_t cnt;
cnt = rsb__util_count_positive(v1,type,n+off);
if(cnt!=3) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
cnt = rsb__util_count_negative(v1,type,n+off);
if(cnt!=2) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__vectors_left_sum_reduce_and_zero(v1,v2,type,n,inc,off);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,v1+off,type,n,inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=sum) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,v2+off,type,n,inc);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=zero) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
}
')dnl
dnl
dnl
#if RSB_WITH_SPARSE_BLAS_INTERFACE
foreach(`mtype',RSB_M4_SPBLAS_MATRIX_SUPPORTED_TYPES,`dnl
{
/* BLAS types and interfaces only here */
const int incy = 1;
const rsb_type_t type = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype);
const mtype x[] = {+1,+0,+5,-2,+4,-6};
mtype y[] = {+2,+0,+3,-2,+0,+0};
mtype w[] = {+0,+0,+0,+0,+0,+0};
const rsb_blas_int_t indx[] = {0,1,2,3,3,3};
const rsb_nnz_idx_t nz = sizeof(indx)/(sizeof(indx[0]));
const rsb_nnz_idx_t ny = sizeof(y)/(sizeof(y[0]));
const mtype zero = RSB_M4_ZERO(mtype);
mtype alpha = 2;
mtype dotr = zero;
mtype res = zero;
#if RSB_WANT_SPARSE_BLAS_LEVEL_1
int istat;
dnl rsb_blas_int_t istat;
#endif
const enum blas_base_type bzb = blas_zero_base;
const enum blas_conj_type bc = blas_conj;
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=3) errval = RSB_ERR_INTERNAL_ERROR;
#if RSB_WANT_SPARSE_BLAS_LEVEL_1
RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`dot',`u',`ID',`0',`f90')(&bc, &nz, x, &(indx[0]), y, &incy, &dotr, &bzb, &istat);
dnl istat=RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`dot',`u',`ID',`0',`lang_c')(bc, nz, x, indx, y, incy, &dotr, bzb);
#else
errval = rsb__BLAS_Xusdot(type, bj, nz, x, indx, y, incy, &dotr, bzb);
#endif
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(dotr!=25) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
#if RSB_WANT_SPARSE_BLAS_LEVEL_1
ifelse(RSB_M4_IS_COMPLEX_TYPE(mtype),`1',`dnl
dnl istat=RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`axpy',`u',`ID',`0',`lang_c')(nz,&alpha, x, indx, y, incy, bzb);
RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`axpy',`u',`ID',`0',`f90')(&nz,&alpha, x, &(indx[0]), y, &incy, &bzb, &istat);
',`dnl
dnl istat=RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`axpy',`u',`ID',`0',`lang_c')(nz, alpha, x, indx, y, incy, bzb);
RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`axpy',`u',`ID',`0',`f90')(&nz,&alpha, x, &(indx[0]), y, &incy, &bzb, &istat);
')dnl
#else
errval = rsb__BLAS_Xusaxpy(type, nz, &alpha, x, indx, y, incy, bzb);
#endif
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+2,+0,+3,-2,+0,+0} => {+4,+0,+13,-6,-4,-4}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
alpha=-alpha;
errval = rsb__BLAS_Xusaxpy(type, nz, &alpha, x, indx, y, incy, bzb);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+2,+0,+3,-2,+0,+0} <= {+4,+0,+13,-6,-4,-4}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=3) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
#if RSB_WANT_SPARSE_BLAS_LEVEL_1
dnl istat=RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`ga',`u',`ID',`0',`lang_c')(nz, x, incy, y, indx, bzb);
RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`ga',`u',`ID',`0',`f90')(&nz, x, &incy, y, &(indx[0]), &bzb, &istat);
#else
errval = rsb__BLAS_Xusga(type, nz, x, incy, y, indx, bzb);
#endif
errval=RSB_BLAS_ERROR_TO_RSB_ERROR(istat);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+2,+0,+3,-2,+0,+0} => {+1,+0,+5,-2,-2,-2}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=0) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
y[3]=-3;
#if RSB_WANT_SPARSE_BLAS_LEVEL_1
RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`gz',`u',`ID',`0',`f90')(&nz, y, &incy, w, &(indx[0]), &bzb, &istat);
dnl istat=RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`gz',`u',`ID',`0',`lang_c')(nz, y, incy, w, indx, bzb);
#else
errval = rsb__BLAS_Xusgz(type, nz, y, incy, w, indx, bzb);
#endif
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// w: {0,0,0,0,0,0} => {+1,+0,+5,-3,+0,+0} // the two zeroes becaue of usgz zeroing after first copy
// y: {+1,+0,+5,-2,-2,-2} => {+0,+0,+0,+0,-2,-2}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=-4) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,w,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=3) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
#if RSB_WANT_SPARSE_BLAS_LEVEL_1
dnl istat=RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`sc',`u',`ID',`0',`lang_c')(nz,x,y,incy,indx,bzb);
RSB_M4_SPBLAS_MATRIX_ALL_L1_FUNCTION(mtype,`sc',`u',`ID',`0',`f90')(&nz,x,y,&incy,&(indx[0]),&bzb,&istat);
#else
errval = rsb__BLAS_Xussc(type,nz,x,y,incy,indx,bzb);
#endif
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// y: {+0,+0,+0,+0,-2,-2} => {+1,+0,+5,-6,-2,-2}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=-4) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
}
')dnl
#endif /* RSB_WITH_SPARSE_BLAS_INTERFACE */
dnl
dnl
foreach(`mtype',RSB_M4_TYPES,`dnl
{
const int incy = 1;
const rsb_type_t type = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype);
const mtype x[] = {+1,+0,+5,-2,+4,-6};
mtype y[] = {+2,+0,+3,-2,+0,+0};
mtype w[] = {+0,+0,+0,+0,+0,+0};
const rsb_blas_int_t indx[] = {0,1,2,3,3,3};
const rsb_nnz_idx_t nz = sizeof(indx)/(sizeof(indx[0]));
const rsb_nnz_idx_t ny = sizeof(y)/(sizeof(y[0]));
const mtype zero = RSB_M4_ZERO(mtype);
mtype alpha = 2;
mtype dotr = zero;
mtype res = zero;
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=3) errval = RSB_ERR_INTERNAL_ERROR;
errval = rsb__BLAS_Xusdot(type, blas_conj, nz, x, indx, y, incy, &dotr, blas_zero_base);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(dotr!=25) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__BLAS_Xusaxpy(type, nz, &alpha, x, indx, y, incy, blas_zero_base);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+2,+0,+3,-2,+0,+0} => {+4,+0,+13,-6,-4,-4}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
alpha=-alpha;
errval = rsb__BLAS_Xusaxpy(type, nz, &alpha, x, indx, y, incy, blas_zero_base);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+2,+0,+3,-2,+0,+0} <= {+4,+0,+13,-6,-4,-4}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=3) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__BLAS_Xusga(type, nz, x, incy, y, indx, blas_zero_base);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// {+2,+0,+3,-2,+0,+0} => {+1,+0,+5,-2,-2,-2}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=0) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
y[3]=-3;
errval = rsb__BLAS_Xusgz(type, nz, y, incy, w, indx, blas_zero_base);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// w: {0,0,0,0,0,0} => {+1,+0,+5,-3,+0,+0} // the two zeroes becaue of usgz zeroing after first copy
// y: {+1,+0,+5,-2,-2,-2} => {+0,+0,+0,+0,-2,-2}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=-4) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,w,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=3) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__BLAS_Xussc(type,nz,x,y,incy,indx,blas_zero_base);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
// y: {+0,+0,+0,+0,-2,-2} => {+1,+0,+5,-6,-2,-2}
errval = rsb__util_vector_sum_strided(&res,y,type,ny,incy);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=-4) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
}
')dnl
dnl
dnl
foreach(`stype',RSB_M4_TYPES,`dnl
foreach(`dtype',RSB_M4_TYPES,`dnl
{
const rsb_type_t stypecode = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(stype);
const rsb_type_t dtypecode = RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(dtype);
const stype x[] = {+1,+0,+5,-2,+4,-6};
dtype y[] = {+2,+0,+3,-2,+0,+0};
const rsb_nnz_idx_t nnz = sizeof(y)/(sizeof(y[0]));
stype alpha = 2;
dtype res = RSB_M4_ZERO(dtype);
errval = rsb__do_copy_converted_scaled(x, y, &alpha, stypecode, dtypecode, nnz, RSB_TRANSPOSITION_N);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
errval = rsb__util_vector_sum_strided(&res,y,dtypecode,nnz,1);
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
if(res!=4) errval = RSB_ERR_INTERNAL_ERROR;
if(RSB_SOME_ERROR(errval)){ RSB_PERR_GOTO(err,RSB_ERRM_ES) }
}
')
')
dnl
err:
return errval;;
}
')
dnl
ifdef(`ONLY_WANT_HEADERS',`dnl
`#define 'RSB__MAX_SIZEOF` ( \'dnl
foreach(`type',RSB_M4_SPBLAS_MATRIX_SUPPORTED_TYPES,`
RSB_MAX(sizeof(type),\')
`0'foreach(`type',RSB_M4_SPBLAS_MATRIX_SUPPORTED_TYPES,`)'))
',`')dnl
dnl
dnl
dnl
#ifdef __cplusplus
}
#endif /* __cplusplus */
dnl
dnl
ifdef(`ONLY_WANT_HEADERS',`
#endif /* RSB_UTIL_H_INCLUDED */
')
dnl
/* @endcond */
dnl
|