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
|
subroutine spops
c
c operations on sparse matrices
c
c Copyright INRIA
include '../stack.h'
integer op
common /mtlbc/ mmode
c
integer iadr,sadr
c
double precision sr,si,e1,powr,powi
integer star,dstar,slash,bslash,dot,colon,quote
integer less,great,equal
integer insert,extrac
integer top0
logical isany
integer tops,top4
* the following boolean vars are defined to replace test on m*n == 0 or m*n == 1)
* for sparse matrices the product m x n may leads to integer overflow.
* (bruno dec 2004)
logical a1_is_empty, a1_is_scalar, a2_is_empty, a2_is_scalar,
$ a3_is_empty, a3_is_scalar, a4_is_empty, a4_is_scalar
data star/47/,dstar/62/,slash/48/
data bslash/49/,dot/51/,colon/44/,quote/53/
data less/59/,great/60/,equal/50/
data insert/2/,extrac/3/
c
iadr(l)=l+l-1
sadr(l)=(l/2)+1
c
op=fin
c
if (ddt .eq. 4) then
write(buf(1:4),'(i4)') fin
call basout(io,wte,' spops op: '//buf(1:4))
endif
c
top0=top
lw=lstk(top+1)+1
if(op.eq.extrac) goto 70
if(op.eq.insert) goto 80
it2=0
goto (04,03,02,01) rhs
call error(39)
return
c
01 il4=iadr(lstk(top))
if(istk(il4).lt.0) il4=iadr(istk(il4+1))
m4=istk(il4+1)
n4=istk(il4+2)
it4=istk(il4+3)
if(istk(il4).eq.5) then
nel4=istk(il4+4)
irc4=il4+5
l4=sadr(irc4+m4+nel4)
elseif(istk(il4).eq.1) then
nel4=m4*n4
l4=sadr(il4+4)
else
top=top0
fin=-fin
return
endif
mn4=m4*n4 ! must not be used if arg4 is a sparse
a4_is_empty = m4.eq.0 .or. n4.eq.0
a4_is_scalar = (.not.a4_is_empty) .and. (m4.eq.1 .and. n4.eq.1)
top=top-1
c
02 il3=iadr(lstk(top))
if(istk(il3).lt.0) il3=iadr(istk(il3+1))
m3=istk(il3+1)
n3=istk(il3+2)
it3=istk(il3+3)
if(istk(il3).eq.5) then
nel3=istk(il3+4)
irc3=il3+5
l3=sadr(irc3+m3+nel3)
elseif(istk(il3).eq.1) then
l3=sadr(il3+4)
nel3=m3*n3
else
top=top0
fin=-fin
return
endif
mn3=m3*n3 ! must not be used if arg3 is a sparse
a3_is_empty = m3.eq.0 .or. n3.eq.0
a3_is_scalar = (.not.a3_is_empty) .and. (m3.eq.1 .and. n3.eq.1)
top=top-1
c
03 il2=iadr(lstk(top))
if(istk(il2).lt.0) il2=iadr(istk(il2+1))
m2=istk(il2+1)
n2=istk(il2+2)
it2=istk(il2+3)
if(istk(il2).eq.5) then
nel2=istk(il2+4)
irc2=il2+5
l2=sadr(irc2+m2+nel2)
elseif(istk(il2).eq.1) then
l2=sadr(il2+4)
nel2=m2*n2
else
top=top0
fin=-fin
return
endif
mn2=m2*n2 ! must not be used if arg2 is a sparse
a2_is_empty = m2.eq.0 .or. n2.eq.0
a2_is_scalar = (.not.a2_is_empty) .and. (m2.eq.1 .and. n2.eq.1)
top=top-1
c
04 il1=iadr(lstk(top))
if(istk(il1).lt.0) il1=iadr(istk(il1+1))
m1=istk(il1+1)
n1=istk(il1+2)
it1=istk(il1+3)
if(istk(il1).eq.5) then
nel1=istk(il1+4)
irc1=il1+5
l1=sadr(irc1+m1+nel1)
elseif(istk(il1).eq.1) then
l1=sadr(il1+4)
nel1=m1*n1
else
top=top0
fin=-fin
return
endif
mn1=m1*n1 ! must not be used if arg1 is a sparse
a1_is_empty = m1.eq.0 .or. n1.eq.0
a1_is_scalar = (.not.a1_is_empty) .and. (m1.eq.1 .and. n1.eq.1)
top=top-1
c
c operations binaires et ternaires
c --------------------------------
c
top=top+1
itr=max(it1,it2)
c
fun = 0
c
c cconc extrac insert rconc
goto(65 , 999 , 999 ,66) op
c
c : + - * / \ = '
goto(06,07,08,10,20,25,130,05,05,60) op+1-colon
c
05 if(op.eq.dstar .or. op.eq.dstar+dot) goto 30 ! case dstar+dot added (bug fix 1769)
if(op.eq.quote+dot) goto 60
if(op.ge.3*dot+star) goto 200
if(op.ge.2*dot+star) goto 120
if(op.ge.less+equal) goto 130
if(op.ge.dot+star) goto 55
if(op.ge.less) goto 130
06 top=top0
fin=-fin
return
c
c addition
07 continue
if (a1_is_empty) then
c []+a
if (mmode.eq.1) then
c . Matlab like []+a=[]
else
c . []+a=a
call icopy(5+m2+nel2,istk(il2),1,istk(il1),1)
l1=sadr(il1+5+m2+nel2)
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(l1),1)
lstk(top+1)=l1+nel2*(it2+1)
goto 999
endif
elseif(a2_is_empty) then
c a+[]
if (mmode.eq.1) then
c . Matlab like a+[]=[]
istk(il1+1)=0
istk(il1+2)=0
istk(il1+3)=0
lstk(top+1)=sadr(il1+4)
else
c . a+[]=a
endif
goto 999
endif
if (m1 .lt. 0) then
c eye+a
top=top0
fin=-fin
return
endif
if (m2 .lt. 0) then
c a+eye
top=top0
fin=-fin
return
endif
if (a2_is_scalar .and. .not. a1_is_scalar) then
c a+cst
top=top0
fin=-fin
return
endif
if (a1_is_scalar .and. .not.a2_is_scalar) then
c cst+a
top=top0
fin=-fin
return
endif
if (m1.ne.m2 .or. n1.ne.n2) then
call error(8)
return
endif
if(istk(il1).ne.5 .or. istk(il2).ne.5) then
c addition with a full matrix
top=top0
fin=-fin
return
endif
c addition of 2 sparse matrices of the same size
irc=iadr(lw)
if(itr.eq.1) then
nelmx=(iadr(lstk(bot))-irc-m1-10)/5
else
nelmx=(iadr(lstk(bot))-irc-m1-10)/3
endif
lc=sadr(irc+m1+nelmx)
lw=lc+nelmx*(itr+1)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
nel=nelmx
if(itr.eq.1) then
call wspasp(m1,n1,stk(l1),stk(l1+nel1),nel1,istk(irc1),
$ stk(l2),stk(l2+nel2),nel2,istk(irc2),stk(lc),stk(lc+nel),
$ nel,istk(irc),it1,it2,ierr)
else
call dspasp(m1,n1,stk(l1),nel1,istk(irc1),stk(l2),nel2,
$ istk(irc2),stk(lc),nel,istk(irc),ierr)
endif
if(ierr.ne.0) then
call error(17)
return
endif
istk(il1+3)=itr
istk(il1+4)=nel
call icopy(m1+nel,istk(irc),1,istk(irc1),1)
l1=sadr(irc1+m1+nel)
call unsfdcopy(nel,stk(lc),1,stk(l1),1)
if(itr.eq.1) call unsfdcopy(nel,stk(lc+nelmx),1,stk(l1+nel),1)
lstk(top+1)=l1+nel*(itr+1)
go to 999
c
c soustraction
08 if(rhs.eq.1) then
if(mn1.eq.0) goto 999
call dscal(nel1*(it1+1),-1.0d+0,stk(l1),1)
goto 999
endif
if (a1_is_empty) then
c []-a
if (mmode.eq.1) then
c . Matlab like []-a=[]
else
c . []-a=-a
call icopy(5+m2+nel2,istk(il2),1,istk(il1),1)
l1=sadr(il1+5+m2+nel2)
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(l1),1)
call dscal(nel2*(it2+1),-1.0d0,stk(l1),1)
lstk(top+1)=l1+nel2*(it2+1)
goto 999
endif
elseif(a2_is_empty) then
c a-[]
if (mmode.eq.1) then
c . Matlab like a-[]=[]
istk(il1+1)=0
istk(il1+2)=0
istk(il1+3)=0
lstk(top+1)=sadr(il1+4)
else
c . a-[]=a
endif
goto 999
endif
if (m1 .lt. 0.or.m2 .lt. 0) then
c soustraction a-eye*b
top=top0
fin=-fin
return
endif
if (a2_is_scalar .and. .not.a1_is_scalar) then
c a-cst
top=top0
fin=-fin
return
endif
if (a1_is_scalar .and. .not.a2_is_scalar) then
c cst-a
top=top0
fin=-fin
return
endif
c check dimensions
if (m1 .ne. m2.or.n1 .ne. n2) then
call error(9)
return
endif
if(istk(il1).ne.5.or.istk(il2).ne.5) then
c soustraction avec une matrice non creuse
top=top0
fin=-fin
return
endif
c soustraction de 2 matrice sparse de meme taille
irc=iadr(lw)
if(itr.eq.1) then
nelmx=(iadr(lstk(bot))-irc-m1-10)/5
else
nelmx=(iadr(lstk(bot))-irc-m1-10)/3
endif
lc=sadr(irc+m1+nelmx)
lw=lc+nelmx*(itr+1)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
nel=nelmx
if(itr.eq.1) then
call wspssp(m1,n1,stk(l1),stk(l1+nel1),nel1,istk(irc1),
$ stk(l2),stk(l2+nel2),nel2,istk(irc2),stk(lc),stk(lc+nel),
$ nel,istk(irc),it1,it2,ierr)
else
call dspssp(m1,n1,stk(l1),nel1,istk(irc1),stk(l2),nel2,
$ istk(irc2),stk(lc),nel,istk(irc),ierr)
endif
if(ierr.ne.0) then
call error(17)
return
endif
istk(il1+3)=itr
istk(il1+4)=nel
call icopy(m1+nel,istk(irc),1,istk(irc1),1)
l1=sadr(irc1+m1+nel)
call unsfdcopy(nel,stk(lc),1,stk(l1),1)
if(itr.eq.1) call unsfdcopy(nel,stk(lc+nelmx),1,stk(l1+nel),1)
lstk(top+1)=l1+nel*(itr+1)
go to 999
c multiplication
10 continue
c$$$ if (m2*mn2 .eq. 1) go to 12
c$$$ if (mn1 .eq. 1 ) go to 13
c$$$ if (mn2 .eq. 1 ) go to 12
if (a2_is_scalar) goto 12
if (a1_is_scalar) goto 13
m1=abs(m1)
n1=abs(n1)
m2=abs(m2)
n2=abs(n2)
if(a1_is_empty .or. a2_is_empty) then
istk(il1)=1
istk(il1+1)=0
istk(il1+2)=0
istk(il1+3)=0
lstk(top+1)=sadr(il1+4)+1
goto 999
endif
c matrix matrix multiplication
if (n1 .ne. m2) then
call error(10)
return
endif
if(istk(il1).eq.1.or.istk(il2).eq.1) then
c full x sparse or sparse x full
lc=lw
lw=lw+m1*n2*(itr+1)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
if(istk(il1).eq.1) then
c full x sparse
if(itr.eq.1) then
call wsmsp(m1,n1,n2,stk(l1),stk(l1+m1*n1),m1,
$ stk(l2),stk(l2+nel2),nel2,istk(irc2),
$ stk(lc),stk(lc+m1*n2),m1,it1,it2)
else
call dsmsp(m1,n1,n2,stk(l1),m1,stk(l2),nel2,
$ istk(irc2),stk(lc),m1)
endif
else
c sparse x full
if(itr.eq.1) then
call wspms(m1,n1,n2,stk(l1),stk(l1+nel1),nel1,istk(irc1),
$ stk(l2),stk(l2+m2*n2),m2,stk(lc),stk(lc+m1*n2),m1,
$ it1,it2)
else
call dspms(m1,n1,n2,stk(l1),nel1,istk(irc1),
$ stk(l2),m2,stk(lc),m1)
endif
endif
istk(il1)=1
istk(il1+1)=m1
istk(il1+2)=n2
istk(il1+3)=itr
l1=sadr(il1+4)
call unsfdcopy(m1*n2*(itr+1),stk(lc),1,stk(l1),1)
lstk(top+1)=l1+m1*n2*(itr+1)
return ! ici un return direct (pas de goto 999) !
endif
* sparse x sparse
ib=iadr(lw)
ic=ib+m2+1
ixb=ic+m1+1
lx=sadr(ixb+n2)
lc=lx+n2*(itr+1)
nel=(iadr(lstk(bot))-iadr(lc)-m1-10)/(1+2*(itr+1))
irc=iadr(lc+nel*(itr+1))
lw=sadr(irc+m1+nel)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
nelc=nel
if(itr.eq.1) then
call wspmsp(m1,n1,n2,stk(l1),stk(l1+nel1),nel1,istk(irc1),
$ stk(l2),stk(l2+nel2),nel2,istk(irc2),
$ stk(lc),stk(lc+nel),nelc,istk(irc),
$ istk(ib),istk(ic),stk(lx),stk(lx+n2),istk(ixb),
$ it1,it2,ierr)
else
call dspmsp(m1,n1,n2,stk(l1),nel1,istk(irc1),
$ stk(l2),nel2,istk(irc2),stk(lc),nelc,istk(irc),
$ istk(ib),istk(ic),stk(lx),istk(ixb),ierr)
endif
if(ierr.eq.1) then
buf='not enough memory'
call error(9999)
return
endif
istk(il1+2)=n2
istk(il1+3)=itr
istk(il1+4)=nelc
l1=sadr(il1+5+m1+nelc)
if(lc.ge.l1) then
call unsfdcopy(nelc,stk(lc),1,stk(l1),1)
if(itr.eq.1) call unsfdcopy(nelc,stk(lc+nel),1,stk(l1+nelc),1)
else
call unsfdcopy(nelc,stk(lc),-1,stk(l1),-1)
if(itr.eq.1) call unsfdcopy(nelc,stk(lc+nel),-1,
$ stk(l1+nelc),-1)
endif
call icopy(nelc+m1,istk(irc),1,istk(il1+5),1)
lstk(top+1)=l1+nelc*(itr+1)
go to 999
c
12 continue
c a*cst
if(istk(il2).eq.1) then
si = 0.0d0
sr = stk(l2)
if(it2.eq.1) si = stk(l2+1)
elseif(istk(il2).eq.5) then
if(nel2.eq.0) then
sr = 0.0d0
si = 0.0d0
else
si = 0.0d0
sr = stk(l2)
if(it2.eq.1) si = stk(l2+1)
endif
endif
if(abs(sr)+abs(si).eq.0.0d0) then
if(istk(il1).eq.1) then
istk(il1+3)=0
call dset(m1*n1,0.0d0,stk(l1),1)
lstk(top+1)=l1+m1*n1
else
istk(il1+3)=0
istk(il1+4)=0
call iset(abs(m1),0,istk(il1+5),1)
lstk(top+1)=sadr(il1+5+abs(m1))+1
endif
return
endif
go to 14
13 continue
c cst*a
if(istk(il1).eq.1) then
si = 0.0d0
sr = stk(l1)
if(it1.eq.1) si = stk(l1+1)
elseif(istk(il1).eq.5) then
if(nel1.eq.0) then
sr = 0.0d0
si = 0.0d0
else
si = 0.0d0
sr = stk(l1)
if(it1.eq.1) si = stk(l1+1)
endif
endif
if(abs(sr)+abs(si).eq.0.0d0) then
if(istk(il2).eq.1) then
istk(il1)=1
istk(il1+1)=m2
istk(il1+2)=n2
istk(il1+3)=0
l1=sadr(il1+4)
call dset(m2*n2,0.0d0,stk(l1),1)
lstk(top+1)=l1+m2*n2
else
istk(il1)=5
istk(il1+1)=m2
istk(il1+2)=n2
istk(il1+3)=0
istk(il1+4)=0
c call iset(iabs(m2),0,stk(il1+5),1)
c lstk(top+1)=sadr(il1+5+abs(m2))+1
c FD modif
nnnb=1+abs(m2)
call iset(nnnb,0,istk(il1+5),1)
lstk(top+1)=sadr(il1+5+nnnb)
endif
return
endif
if(istk(il2).eq.5) then
call icopy(5+m2+nel2,istk(il2),1,istk(il1),1)
l1=sadr(il1+5+m2+nel2)
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(l1),1)
elseif(istk(il2).eq.1) then
call icopy(4,istk(il2),1,istk(il1),1)
l1=sadr(il1+4)
call unsfdcopy(mn2*(it2+1),stk(l2),1,stk(l1),1)
endif
m1=m2
n1=n2
mn1=it1
it1=it2
it2=mn1
mn1=mn2
nel1=nel2
c
14 continue
istk(il1+1)=m1
istk(il1+2)=n1
istk(il1+3)=itr
lstk(top+1)=l1+nel1*(itr+1)
c
err=lstk(top+1)-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
c
goto (15,16,17),it2+2*it1
c la matrice et le scalaire sont reel
call dscal(nel1,sr,stk(l1),1)
lstk(top+1)=l1+nel1
goto 999
15 continue
c la matrice est reelle le scalaire est complexe
err=l1+2*nel1-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
call unsfdcopy(nel1,stk(l1),1,stk(l1+nel1),1)
call dscal(nel1,sr,stk(l1),1)
call dscal(nel1,si,stk(l1+nel1),1)
lstk(top+1)=l1+2*nel1
goto 999
16 continue
c la matrice est complexe, le scalaire est reel
call dscal(nel1,sr,stk(l1),1)
call dscal(nel1,sr,stk(l1+nel1),1)
lstk(top+1)=l1+2*nel1
goto 999
17 continue
c la matrice et le scalaire sont complexes
call wscal(nel1,sr,si,stk(l1),stk(l1+nel1),1)
lstk(top+1)=l1+2*nel1
goto 999
c
c right division
20 if (mn2 .ne. 1) then
c right division by a matrix -->macro coded
fin = -fin
top = top0
rhs = 2
go to 999
endif
c right division by a scalar
sr=stk(l2)
si=0.0d+0
if(it2.eq.1) si=stk(l2+1)
e1=max(abs(sr),abs(si))
if(e1.eq.0.0d+0) then
call error(27)
return
endif
sr=sr/e1
si=si/e1
e1=e1*(sr*sr+si*si)
sr=sr/e1
si=-si/e1
c call multiplication with scalar inverse
goto 14
c
c left division
25 if ( .not.a1_is_scalar ) then
c left division by a matrix -->macro coded
top=top0
fin=-fin
return
endif
c left division by a scalar
sr=stk(l1)
si=0.0d+0
if(it1.eq.1) si=stk(l1+1)
e1=max(abs(sr),abs(si))
if(e1.eq.0.0d+0) then
call error(27)
return
endif
sr=sr/e1
si=si/e1
e1=e1*(sr*sr+si*si)
sr=sr/e1
si=-si/e1
if(istk(il2).eq.1) then
call icopy(4,istk(il2),1,istk(il1),1)
l1=sadr(il1+4)
nel2=mn2
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(l1),1)
else
call icopy(5+2*nel2,istk(il2),1,istk(il1),1)
l1=sadr(il1+5+m2+nel2)
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(l1),1)
endif
m1=m2
n1=n2
it=it1
it1=it2
it2=it
mn1=mn2
nel1=nel2
goto 14
*
* power operations: sp^pow or sp.^pow
* (modified by Bruno jan 19 2006 to fix bug 1769)
*
* notes : dstar corresponds to ^
* dstar+dot corresponds to .^
* at the beginning of this toooooooo big subroutine the code is
* branched here in these 2 cases.
*
30 if (mn2 .ne. 1) then
call error(30)
return
endif
* for sp^pow with a sp square and not scalar (scalar case is faster handle
* by the element wize power op)
if ( op.eq.dstar .and. m1.eq.n1 .and. .not.a1_is_scalar ) goto 31
* sp^pow is nevertheless "authorized" when sp is a vector (and done
* as an element wize power operation)
if ( op.eq.dstar .and. m1.ne.1 .and. n1.ne.1 ) then
err=1
call error(20)
return
endif
* so the following concerns only element wise power
*
************end of the modif for bug 1769****************
*
err=l1+nel1*2-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
if(it2.eq.0) then
powr=stk(l2)
if(it1.eq.0) then
call ddpow(nel1,stk(l1),stk(l1+nel1),1,powr,err,itr)
else
call wdpow(nel1,stk(l1),stk(l1+nel1),1,powr,err)
endif
else
powr=stk(l2)
powi=stk(l2+1)
if(it1.eq.0) then
call dwpow(nel1,stk(l1),stk(l1+nel1),1,
& powr,powi,err)
else
call wwpow(nel1,stk(l1),stk(l1+nel1),1,
& powr,powi,err)
endif
endif
if(err.eq.1) then
call error(30)
return
endif
if(err.eq.2) then
call error(27)
return
endif
istk(il1+3)=itr
lstk(top+1)=l1+nel1*(itr+1)
goto 999
c
c elevation d'une matrice carree a une puissance
31 continue
top=top0
fin=-fin
return
c
c operations elements a elements
55 continue
i1=1
i2=1
op = op - dot
if(a1_is_empty .or. a2_is_empty) then
c [].*a a.*[] -->[]
istk(il1)=1
istk(il1+1)=0
istk(il1+2)=0
istk(il1+3)=0
lstk(top+1)=sadr(il1+4)+1
goto 999
endif
if(a1_is_scalar .or. a2_is_scalar) then
goto(06,07,08,10,20,25,130,05,05,60) op+1-colon
endif
c
c check dimensions
if (m1.ne.m2 .or. n1.ne.n2) then
call error(6)
return
endif
if(op.eq.slash) then
if(istk(il2).eq.1) then
if(it2.eq.0) then
do 56 i=0,mn1-1
if(stk(l2+i).eq.0.0d0) then
call error(27)
return
endif
stk(l2+i)=1.0d0/stk(l2+i)
56 continue
else
do 57 i=0,mn2-1
sr=stk(l2+i)
si=stk(l2+mn2+i)
e1=abs(sr)+abs(si)
if(e1.eq.0.0d+0) then
call error(27)
return
endif
sr=sr/e1
si=si/e1
e1=e1*(sr*sr+si*si)
stk(l2+i)=sr/e1
stk(l2+mn2+i)=-si/e1
57 continue
endif
else
top=top0
fin=-fin
return
endif
elseif(op.eq.bslash) then
if(istk(il1).eq.1) then
if(it1.eq.0) then
do 58 i=0,mn1-1
if(stk(l1+i).eq.0.0d0) then
call error(27)
return
endif
stk(l1+i)=1.0d0/stk(l1+i)
58 continue
else
do 59 i=0,mn1-1
sr=stk(l1+i)
si=stk(l1+mn1+i)
e1=abs(sr)+abs(si)
if(e1.eq.0.0d+0) then
call error(27)
return
endif
sr=sr/e1
si=si/e1
e1=e1*(sr*sr+si*si)
stk(l1+i)=sr/e1
stk(l1+mn1+i)=-si/e1
59 continue
endif
else
top=top0
fin=-fin
return
endif
endif
if(nel1.eq.0.or.nel2.eq.0) then
istk(il1)=5
istk(il1+3)=0
istk(il1+4)=0
call iset(m1,0,istk(il1+5),1)
lstk(top+1)=sadr(il1+5+m1)
return
endif
if(istk(il1).eq.1) then
c full.*sparse
nel=nel2
if(it1.eq.0.and.it2.eq.0) then
call dspxs(m1,n1,stk(l2),nel2,istk(irc2),stk(l1),m1,
$ stk(l2),nel,istk(irc2),ierr)
else
if(it2.eq.0) then
err=l2+2*nel2-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
endif
call wspxs(m1,n1,stk(l2),stk(l2+nel2),nel2,istk(irc2),
$ stk(l1),stk(l1+nel1),m1,
$ stk(l2),stk(l2+nel2),nel,istk(irc2),ierr,it2,it1)
endif
istk(il1)=5
istk(il1+3)=itr
istk(il1+4)=nel
l=sadr(il1+5+m1+nel)
call icopy(m1+nel,istk(irc2),1,istk(il1+5),1)
call unsfdcopy(nel,stk(l2),1,stk(l),1)
if(itr.eq.1) call unsfdcopy(nel,stk(l2+nel2),1,stk(l+nel),1)
lstk(top+1)=l+nel*(itr+1)
return
elseif(istk(il2).eq.1) then
c sparse.*full
nel=nel1
if(it1.eq.0.and.it2.eq.0) then
call dspxs(m1,n1,stk(l1),nel1,istk(irc1),stk(l2),m1,
$ stk(l1),nel,istk(irc1),ierr)
else
lri=l1+nel1
if(it1.eq.0) then
lri=lw
err=lri+nel1-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
endif
call wspxs(m1,n1,stk(l1),stk(l1+nel1),nel1,istk(irc1),
$ stk(l2),stk(l2+nel2),m1,
$ stk(l1),stk(lri),nel,istk(irc1),ierr,it1,it2)
endif
istk(il1)=5
istk(il1+3)=itr
istk(il1+4)=nel
l=sadr(il1+5+m1+nel)
call icopy(m1+nel,istk(irc1),1,istk(il1+5),1)
call unsfdcopy(nel,stk(l1),1,stk(l),1)
if(itr.eq.1) call unsfdcopy(nel,stk(lri),1,stk(l+nel),1)
lstk(top+1)=l+nel*(itr+1)
return
endif
c sparse.*sparse
nel=nel1
if(it1.eq.0.and.it2.eq.0) then
call dspxsp(m1,n1,stk(l1),nel1,istk(irc1),
$ stk(l2),nel2,istk(irc2),stk(l1),nel,istk(irc1),ierr)
lrr=l1
else
lrr=lw
lri=lrr+min(nel1,nel2)
err=lri+min(nel1,nel2)-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
call wspxsp(m1,n1,stk(l1),stk(l1+nel1),nel1,istk(irc1),
$ stk(l2),stk(l2+nel2),nel2,istk(irc2),
$ stk(lrr),stk(lri),nel,istk(irc1),ierr,it1,it2)
endif
istk(il1+3)=itr
istk(il1+4)=nel
l=sadr(il1+5+m1+nel)
call unsfdcopy(nel,stk(lrr),1,stk(l),1)
if(itr.eq.1) call unsfdcopy(nel,stk(lri),1,stk(l+nel),1)
lstk(top+1)=l+nel*(itr+1)
return
c
c
c transposition (modified by bruno)
60 istk(il1+1)=n1
istk(il1+2)=m1
if(nel1.eq.0) then
lw=sadr(il1+5+n1)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
call iset(n1,0,istk(il1+5),1)
lstk(top+1)=lw
goto 999
endif
iptr=iadr(lw) ! for work array ptr of size n1
irc2=iptr+n1
l2=sadr(irc2+n1+nel1)
lw=l2+nel1*(it1+1)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
if (it1 .eq. 0) then
inc = 0
else
inc = nel1
endif
call spt(m1, n1, nel1, it1, istk(iptr),
$ stk(l1), stk(l1+inc), istk(irc1), istk(irc1+m1),
$ stk(l2), stk(l2+inc), istk(irc2), istk(irc2+n1))
* recopie en "top"
call icopy(n1+nel1,istk(irc2),1,istk(irc1),1)
l1=sadr(irc1+n1+nel1)
call unsfdcopy(nel1*(it1+1),stk(l2),1,stk(l1),1)
if(it1.eq.1 .and. op.ne.quote+dot) then
call dscal(nel1,-1.0d0,stk(l1+nel1),1) ! complexe conjugue si A' et it=1
endif
lstk(top+1)=l1+nel1*(it1+1)
goto 999
c
c concatenation [a b]
65 continue
if(m1.lt.0.or.m2.lt.0) then
call error(14)
return
endif
if(m2.eq.0) then
return
elseif(m1.eq.0) then
call icopy(5+m2+nel2,istk(il2),1,istk(il1),1)
l1=sadr(il1+5+m2+nel2)
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(l1),1)
lstk(top+1)=l1+nel2*(it2+1)
return
elseif(m1.ne.m2) then
call error(5)
return
endif
if(istk(il1).ne.5.or.istk(il2).ne.5) then
top=top0
fin=-fin
return
endif
c
nelr=nel1+nel2
istk(il1+2)=n1+n2
istk(il1+3)=itr
istk(il1+4)=nelr
lr=lw
irc=iadr(lr+nelr*(itr+1))
lw=sadr(irc+m1+nelr)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
if(itr.eq.0) then
call dspcsp(0,m1,n1,stk(l1),nel1,istk(irc1),
$ m2,n2,stk(l2),nel2,istk(irc2),
$ stk(lr),nelr,istk(irc))
else
call wspcsp(0,m1,n1,stk(l1),stk(l1+nel1),nel1,istk(irc1),
$ m2,n2,stk(l2),stk(l2+nel2),nel2,istk(irc2),
$ stk(lr),stk(lr+nelr),nelr,istk(irc),it1,it2)
endif
call icopy(m1+nelr,istk(irc),1,istk(irc1),1)
l1=sadr(irc1+m1+nelr)
call unsfdcopy(nelr*(itr+1),stk(lr),1,stk(l1),1)
lstk(top+1)=l1+nelr*(itr+1)
return
c
c concatenation [a;b]
66 continue
if(n1.lt.0.or.n2.lt.0) then
call error(14)
return
endif
if(n2.eq.0) then
goto 999
elseif(n1.eq.0)then
call icopy(5+m2+nel2,istk(il2),1,istk(il1),1)
l1=sadr(il1+5+m2+nel2)
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(l1),1)
lstk(top+1)=l1+nel2*(it2+1)
goto 999
elseif(n1.ne.n2) then
call error(6)
return
endif
if(istk(il1).ne.5.or.istk(il2).ne.5) then
top=top0
fin=-fin
return
endif
nelr=nel1+nel2
istk(il1+1)=m1+m2
istk(il1+3)=itr
istk(il1+4)=nelr
lr=lw
irc=iadr(lr+nelr*(itr+1))
lw=sadr(irc+m1+m2+nelr)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
if(itr.eq.0) then
call dspcsp(1,m1,n1,stk(l1),nel1,istk(irc1),
$ m2,n2,stk(l2),nel2,istk(irc2),
$ stk(lr),nelr,istk(irc))
else
call wspcsp(1,m1,n1,stk(l1),stk(l1+nel1),nel1,istk(irc1),
$ m2,n2,stk(l2),stk(l2+nel2),nel2,istk(irc2),
$ stk(lr),stk(lr+nelr),nelr,istk(irc),it1,it2)
endif
call icopy(m1+m2+nelr,istk(irc),1,istk(irc1),1)
l1=sadr(irc1+m1+m2+nelr)
call unsfdcopy(nelr*(itr+1),stk(lr),1,stk(l1),1)
lstk(top+1)=l1+nelr*(itr+1)
goto 999
c
c extraction (modified by bruno)
c
70 continue
if(rhs.lt.2) then
call error(227)
return
endif
if(rhs.gt.2) goto 75 ! goto extraction arg3(arg1,arg2)
c****** extraction arg2(arg1) *************************************
*
c get arg2
il2=iadr(lstk(top))
if(istk(il2).lt.0) il2=iadr(istk(il2+1))
m2=istk(il2+1)
n2=istk(il2+2)
it2=istk(il2+3)
nel2=istk(il2+4)
irc2=il2+5
l2=sadr(irc2+m2+nel2)
a2_is_empty = m2.eq.0 .or. n2.eq.0
a2_is_scalar = (.not.a2_is_empty) .and. (m2.eq.1 .and. n2.eq.1)
mn2=m2*n2
top=top-1
c get arg1
il1=iadr(lstk(top))
ilrs=il1
if(istk(il1).lt.0) il1=iadr(istk(il1+1))
m1=istk(il1+1)
n1=istk(il1+2)
a1_is_empty = m1.eq.0 .or. n1.eq.0
a1_is_scalar = (.not.a1_is_empty) .and. (m1.eq.1 .and. n1.eq.1)
if(a2_is_empty) then
c . arg2=[] -> return an empty matrix []
ilrs=iadr(lstk(top))
istk(ilrs)=1
istk(ilrs+1)=0
istk(ilrs+2)=0
istk(ilrs+3)=0
lstk(top+1)=sadr(ilrs+4)+1
goto 999
elseif(m2.lt.0) then
c . arg2=eye
call error(14)
return
elseif(m1.lt.0) then ! case arg2(:) => just reshape to column vector
if(n2.eq.1) then
c . already a column vector
ilrs=iadr(lstk(top))
call icopy(5+m2+nel2,istk(il2),1,istk(ilrs),1)
l1=sadr(ilrs+5+m2+nel2)
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(l1),1)
lstk(top+1)=l1+nel2*(it2+1)
else ! n2 > 1
c . reshape to column vector via spmat (reshape is named matrix in scilab)
ilrs=iadr(lstk(top))
istk(ilrs)=5
istk(ilrs+1)=mn2
istk(ilrs+2)=1
istk(ilrs+3)=it2
istk(ilrs+4)=nel2
irc1=ilrs+5
l1=sadr(ilrs+5+m2*n2+nel2)
ircr=iadr(lw)
iw=ircr+m2*n2+nel2
** correction d'un bug
lr=sadr(iw+3*nel2)
lw= lr + nel2*(it2+1)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
! copie des valeurs de arg2
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(lr),1)
if(it2.eq.0) then
*** le bug etait du au fait que stk(l2) (remplace par stk(lr)) est remanie
*** (via une permutation) et donc pb si arg2 est passe par reference
*** il faudrait peut utiliser spreshape maintenant
call dspmat(m2,n2,stk(lr),nel2,istk(irc2),m2*n2
$ ,istk(ircr),istk(iw))
else
call wspmat(m2,n2,stk(lr),stk(lr+mn2),nel2,istk(irc2)
$ ,m2*n2,istk(ircr),istk(iw))
endif
call icopy(m2*n2+nel2,istk(ircr),1,istk(irc1),1)
call unsfdcopy(nel2*(it2+1),stk(lr),1,stk(l1),1)
lstk(top+1)=l1+nel2*(it2+1)
endif
return
endif
*** extraction arg2(arg1) (suite)
call indxg(il1,mn2,ilr,mi,mx,lw,1) ! analysis of the index vector arg1
if(err.gt.0) return
if(mx.gt.mn2) then
call error(21)
return
endif
72 if(mi.eq.0) then ! case arg2([]) => return a void matrix (type = 1)
ilrs=iadr(lstk(top))
istk(ilrs)=1
istk(ilrs+1)=0
istk(ilrs+2)=0
istk(ilrs+3)=0
lstk(top+1)=sadr(ilrs+4)+1
goto 999
endif
c set output sizes ! extraction arg2(arg1)
if ( m2 .eq. 1 ) then ! A is a row sparse => B also (and only in this case)
mr = 1
nr = mi
else ! A not a row sparse => B a column sparse
mr = mi
nr = 1
endif
c get memory for the result
lptr=iadr(lw)
irc=lptr+m2
lw=sadr(irc+mr)
nelrm=(2*(lstk(bot)-lw)-1)/(3+2*it2)
if(nelrm.le.0) then
err=lw-lstk(bot)
call error(17)
return
endif
lr=sadr(irc+mr+nelrm)
lw=lr+nelrm*(it2+1)
inc2 = nel2*it2
incr = nelrm*it2
* subroutine spextr1(A_m, A_n, A_nel, A_mnel, A_icol, A_R, A_I,
* $ B_m, B_n, B_nel, B_mnel, B_icol, B_R, B_I,
* $ it, i, ni, nel_max, ptr, ierr)
call spextr1(m2, n2, nel2, istk(irc2), istk(irc2+m2), stk(l2),
$ stk(l2+inc2),
$ mr, nr, nelr, istk(irc), istk(irc+mr), stk(lr),
$ stk(lr+incr),
$ it2, istk(ilr), mi, nelrm, istk(lptr), ierr)
c form resulting variable
ilrs=iadr(lstk(top))
istk(ilrs)=5
istk(ilrs+1)=mr
istk(ilrs+2)=nr
istk(ilrs+3)=it2
istk(ilrs+4)=nelr
call icopy(mr+nelr,istk(irc),1,istk(ilrs+5),1)
l1=sadr(ilrs+5+mr+nelr)
call unsfdcopy(nelr,stk(lr),1,stk(l1),1)
if(it2.eq.1) call unsfdcopy(nelr,stk(lr+nelrm),1,stk(l1+nelr),1)
lstk(top+1)=l1+nelr*(it2+1)
go to 999
c
c arg3(arg1,arg2)
75 if(rhs.gt.3) then
call error(36)
return
endif
c get arg3
il3=iadr(lstk(top))
if(istk(il3).lt.0) il3=iadr(istk(il3+1))
m3=istk(il3+1)
n3=istk(il3+2)
it3=istk(il3+3)
nel3=istk(il3+4)
irc3=il3+5
l3=sadr(irc3+m3+nel3)
mn3=m3*n3
top=top-1
c get arg2
il2=iadr(lstk(top))
if(istk(il2).lt.0) il2=iadr(istk(il2+1))
m2=istk(il2+1)
top=top-1
c get arg1
il1=iadr(lstk(top))
ilrs=il1
if(istk(il1).lt.0) il1=iadr(istk(il1+1))
m1=istk(il1+1)
if(mn3.eq.0) then
c . arg3=[]
ilrs=iadr(lstk(top))
istk(ilrs)=1
istk(ilrs+1)=0
istk(ilrs+2)=0
istk(ilrs+3)=0
lstk(top+1)=sadr(ilrs+4)+1
goto 999
elseif(m3.lt.0) then
c .arg3=eye
call error(14)
return
endif
c check and convert indices variables
call indxg(il1,m3,ili,mi,mxi,lw,11)
if(err.gt.0) return
if(mxi.gt.m3) then
call error(21)
return
endif
if(mi.lt.0) then
mr=m3 ! modif bruno
else
mr=mi
endif
call indxg(il2,n3,ilj,nj,mxj,lw,11)
if(err.gt.0) return
if(mxj.gt.n3) then
call error(21)
return
endif
if(nj.lt.0) then
nr=n3 ! modif bruno
else
nr=nj
endif
c
76 continue
if(mr.eq.0 .or. nr.eq.0) then
c . arg1=[] or arg2=[]
ilrs=iadr(lstk(top))
istk(ilrs)=1
istk(ilrs+1)=0
istk(ilrs+2)=0
istk(ilrs+3)=0
lstk(top+1)=sadr(ilrs+4)+1
goto 999
endif
c get memory for the result
lptr=iadr(lw) ! istk(lptr) = ptr(1)
irc=lptr+m3+1 ! m3+1 cases pour le tableau ptr => istk(irc) = p(1)
ircr = irc + nr ! nr cases pour le tableau p de la permutation mnelr(1) = istk(ircr)
lw=sadr(ircr+mr) !
nelrmax = (lstk(bot)-lw)/(1+2*(it3+1)) ! nb max possible d'elts pour la matrice resultat
if(nelrmax.le.0) then
err=lw-lstk(bot)
call error(17)
return
endif
lr=sadr(ircr+mr+nelrmax)
lw=lr+nelrmax*(it3+1)
c perform extraction
if(it3.eq.0) then ! les parties imaginaires (inutilises)
inc3 = 0 ! pointeront sur les parties relles
incr = 0
else
inc3 = nel3
incr = nelrmax
endif
call spextr(m3, n3, nel3, istk(irc3), istk(irc3+m3), stk(l3),
$ stk(l3+inc3),
$ mr, nr, nelr, istk(ircr), istk(ircr+mr), stk(lr),
$ stk(lr+incr),
$ it3, istk(ili), mi, istk(ilj), nj, nelrmax,
$ istk(lptr), istk(irc), ierr)
* subroutine spextr(A_m, A_n, A_nel, A_mnel, A_icol, A_R, A_I,
* $ B_m, B_n, B_nel, B_mnel, B_icol, B_R, B_I,
* $ it, i, ni, j, nj, nel_max, ptr, p, ierr)
if(ierr .eq. -1) then ! not enough memory
err=1 ! valeur bidon : j'imagine qu'il faut donner
call error(17) ! une idee a l'utilisateur de la mmoire manquante
return
endif
c form resulting variable
ilrs=iadr(lstk(top))
istk(ilrs)=5
istk(ilrs+1)=mr
istk(ilrs+2)=nr
istk(ilrs+3)=it3
istk(ilrs+4)=nelr
call icopy(mr+nelr,istk(ircr),1,istk(ilrs+5),1)
l1=sadr(ilrs+5+mr+nelr)
call unsfdcopy(nelr,stk(lr),1,stk(l1),1)
if(it3.eq.1) call unsfdcopy(nelr,stk(lr+nelrmax),1,stk(l1+nelr),1)
lstk(top+1)=l1+nelr*(it3+1)
go to 999
c
c insertion
80 continue
if(rhs.gt.4) then
top=top0
fin=-fin
return
endif
if(rhs.eq.4) goto 90
c arg3(arg1)=arg2
c get arg3
tops = top
il3=iadr(lstk(top))
if(istk(il3).lt.0) il3=iadr(istk(il3+1))
m3=istk(il3+1)
n3=istk(il3+2)
it3=istk(il3+3)
if(istk(il3).eq.5) then
nel3=istk(il3+4)
irc3=il3+5
l3=sadr(irc3+m3+nel3)
else
top=top0
fin=-fin
return
endif
mn3=m3*n3
c get arg2
top=top-1
il2=iadr(lstk(top))
if(istk(il2).lt.0) il2=iadr(istk(il2+1))
m2=istk(il2+1)
n2=istk(il2+2)
it2=istk(il2+3)
if(istk(il2).eq.5) then
nel2=istk(il2+4)
irc2=il2+5
l2=sadr(irc2+m2+nel2)
elseif(istk(il2).eq.1) then
l2=sadr(il2+4)
nel2=m2*n2
else
top=top0
fin=-fin
return
endif
mn2=m2*n2
c get arg1
top=top-1
il1=iadr(lstk(top))
ilrs=il1
if(istk(il1).lt.0) il1=iadr(istk(il1+1))
if (istk(il1).eq.10.or.istk(il1).eq.15) then
top=top0
fin=-fin
return
endif
m1=istk(il1+1)
n1=istk(il1+2)
****************************************************************
*
* code added by bruno to treat the case arg3(arg1)=arg2
* with:
* arg1 a sparse boolean matrix of the same dimension than arg3
* arg2 is a full vector or a scalar with nel1 elements
*
if (istk(il1).eq.6 .and. m1.eq.m3 .and. n1.eq.n3 .and.
$ istk(il2).eq.1 .and. (m2.eq.1 .or. n2.eq.1) ) then
nel1 = istk(il1+4)
a2_is_scalar = m2.eq.1 .and. n2.eq.1
if (a2_is_scalar .or. m2*n2.eq.nel1) then
ip = iadr(lstk(tops+1))
if (.not. a2_is_scalar) then
iq = ip + n1+1
ilr = iq + nel1
else
iq = ip
ilr = ip
endif
lr = sadr(ilr + 5 + m1)
itr = max(it3,it2)
nelmax = (2*(lstk(bot)-lr)-1)/(3+2*itr)
if(nelmax .le. 0) then
buf='not enough memory'
call error(9999)
return
endif
ilrc = ilr + 5 + m1
lr = sadr(ilrc+nelmax)
if (itr .eq. 0) then
lri = lr
else
lri = lr + nelmax
endif
call spif1b(m3, n3, nel3, it3, istk(irc3), istk(irc3+m3),
$ stk(l3), stk(l3+nel3), nel1, istk(il1+5),
$ istk(il1+5+m1), it2, stk(l2), stk(l2+mn2),
$ a2_is_scalar, nelr, itr, istk(ilr+5),
$ istk(ilrc), stk(lr), stk(lri), nelmax, istk(ip),
$ istk(iq), ierr)
if(ierr.ne.0) then
buf='not enough memory'
call error(9999)
return
endif
* form the resulting var
istk(ilrs) = 5
istk(ilrs+1) = m3
istk(ilrs+2) = n3
istk(ilrs+3) = itr
istk(ilrs+4) = nelr
call icopy(m3+nelr,istk(ilr+5),1,istk(ilrs+5),1)
lrs = sadr(ilrs+5+m3+nelr)
call unsfdcopy(nelr,stk(lr),1,stk(lrs),1)
if (itr .eq. 1) then
call unsfdcopy(nelr,stk(lri),1,stk(lrs+nelr),1)
endif
lstk(top+1) = lrs + (1+itr)*nelr
go to 999
endif
endif
*
* end of the case added by Bruno
*
****************************************************************
if (m2.eq.0) then
c . arg3(arg1)=[] -->[]
if(m1.eq.-1) then
c . arg3(:)=[]
istk(ilrs)=1
istk(ilrs+1)=0
istk(ilrs+2)=0
istk(ilrs+3)=0
lstk(top+1)=sadr(ilrs+4)+1
goto 999
elseif(m1.eq.0) then
c . arg3([])=[] --> arg3
call icopy(5+m3+nel3,istk(il3),1,istk(ilrs),1)
l=sadr(ilrs+5+m3+nel3)
call unsfdcopy(nel3*(it3+1),stk(l3),1,stk(l),1)
* lstk(top+1)=l+mn3*(it3+1)
lstk(top+1)=l+nel3*(it3+1)
goto 999
else
c . arg3(arg1)=[]
if(istk(il1).eq.4.and.m3.eq.m1.and.n3.eq.n1) then
if(.not.isany(il1)) then
c . arg3([])=[] --> arg3
call icopy(5+m3+nel3,istk(il3),1,istk(ilrs),1)
l=sadr(ilrs+5+m3+nel3)
call unsfdcopy(nel3*(it3+1),stk(l3),1,stk(l),1)
* lstk(top+1)=l+mn3*(it3+1)
lstk(top+1)=l+nel3*(it3+1)
goto 999
endif
endif
c . arg3(arg1)=[] -->arg3(compl(arg1),:)
if(m3.gt.1.and.n3.gt.1) then
c . call macro coded op to reshape and insert
top=top0
fin=-fin
return
else
call indxgc(il1,mn3,ilr,mi,mx,lw)
if(err.gt.0) return
l2=l3
n2=n3
m2=m3
mn2=m2*n2
it2=it3
nel2=nel3
irc2=irc3
c . call extraction
goto 72
endif
endif
elseif(m2.lt.0.or.m3.lt.0) then
c . arg3=eye,arg2=eye
call error(14)
return
elseif(m1.lt.0) then
c . arg3(:)=arg2 reshape arg2 according to arg3
* CAUTION: bug if arg2 is a full matrix !
if(mn2.eq.mn3) then
if(m2.ne.m3) then
top=top0
fin=-fin
return
endif
istk(ilrs)=5
istk(ilrs+1)=m3
istk(ilrs+2)=n3
call icopy(2+m2+nel2,istk(il2+3),1,istk(ilrs+3),1)
l1=sadr(ilrs+5+m2+nel2)
call unsfdcopy(nel2*(it2+1),stk(l2),1,stk(l1),1)
lstk(top+1)=l1+nel2*(it2+1)
return
elseif(mn2.eq.1) then
istk(ilrs)=1
istk(ilrs+1)=m3
istk(ilrs+2)=n3
istk(ilrs+3)=it2
l1=sadr(ilrs+4)
call dset(mn3,stk(l2),stk(l1),1)
if(it2.eq.1) call dset(mn3,stk(l2+1),stk(l1+mn3),1)
lstk(top+1)=l1+mn3*(it2+1)
return
else
call error(15)
return
endif
elseif(m3.gt.1.and.n3.gt.1) then
c . arg3(arg1)=arg2 with arg3 not a vector
top=top0
fin=-fin
return
endif
81 call indxg(il1,mn3,ili,mi,mxi,lw,1)
if(err.gt.0) return
if(mi.eq.0) then
c . arg3([])=arg2
if(mn2.eq.1) then
c . arg3([])=c --> arg3
call icopy(5+m3+nel3,istk(il3),1,istk(ilrs),1)
l=sadr(ilrs+5+m3+nel3)
call unsfdcopy(nel3*(it3+1),stk(l3),1,stk(l),1)
* lstk(top+1)=l+mn3*(it3+1)
lstk(top+1)=l+nel3*(it3+1)
goto 999
else
call error(15)
return
endif
endif
if(mi.ne.mn2) then
if(mn2.gt.1) then
call error(15)
return
elseif(istk(il2).ne.1) then
top=top0
fin=-fin
return
endif
endif
c
if (n3.gt.1.and.m3.gt.1) then ! ce test est inutile puisque ce cas est traite par macro
c . arg3 is not a vector
if(n2.gt.1.and.m2.gt.1) then
call error(15)
return
endif
if(mxi.gt.m3*n3) then
call error(21)
return
endif
mr=m3
nr=n3
elseif (n3.le.1.and.n2.le.1) then
c . arg3 and arg2 are column vectors
mr=max(m3,mxi)
nr=max(n3,1)
elseif (m3.le.1.and.m2.le.1) then
c . row vectors
nr=max(n3,mxi)
mr=max(m3,1)
else
c . arg3 and arg2 dimensions dont agree
call error(15)
return
endif
c set output sizes
if (m3 .gt. 1.or.m1.lt.0) then
c . column vector
m=mi
n=-1
mr = mi
nr = 1
else
c . row vector
m=-1
n=mi
nr = mi
mr = 1
endif
itr=max(it2,it3)
lptr=iadr(lw)
irc=lptr+mr+1
lw=sadr(irc+mr)
nelr=(lstk(bot)-lw-1)/(1+2*(itr+1))
if(nelr.le.0) then
err=lw-lstk(bot)
call error(17)
return
endif
lr=sadr(irc+mr+nelr)
lw=lr+nelr*(itr+1)
nel=nelr
if(istk(il2).eq.5) then
if(itr.eq.0) then
call dspisp(m3,n3,stk(l3),nel3,istk(irc3),
$ istk(ili),m,istk(ili),n,
$ m2,n2,stk(l2),nel2,istk(irc2),
$ mr,nr,stk(lr),nelr,istk(irc),istk(lptr),ierr)
else
call wspisp(m3,n3,stk(l3),stk(l3+nel3),nel3,istk(irc3),
$ istk(ili),m,istk(ili),n,
$ m2,n2,stk(l2),stk(l2+nel2),nel2,istk(irc2),
$ mr,nr,stk(lr),stk(lr+nelr),nelr,istk(irc),
$ istk(lptr),ierr,it3,it2)
endif
else
if(itr.eq.0) then
call dspis(m3,n3,stk(l3),nel3,istk(irc3),
$ istk(ili),m,istk(ili),n,
$ m2,n2,stk(l2),
$ mr,nr,stk(lr),nelr,istk(irc),ierr)
else
call wspis(m3,n3,stk(l3),stk(l3+nel3),nel3,istk(irc3),
$ istk(ili),m,istk(ili),n,
$ m2,n2,stk(l2),stk(l2+nel2),
$ mr,nr,stk(lr),stk(lr+nelr),nelr,istk(irc),
$ ierr,it3,it2)
endif
endif
if(ierr.ne.0) then
buf='not enough memory'
call error(9999)
return
endif
istk(ilrs)=5
istk(ilrs+1)=mr
istk(ilrs+2)=nr
istk(ilrs+3)=itr
istk(ilrs+4)=nelr
call icopy(mr+nelr,istk(irc),1,istk(ilrs+5),1)
l1=sadr(ilrs+5+mr+nelr)
call unsfdcopy(nelr,stk(lr),1,stk(l1),1)
if(itr.eq.1) call unsfdcopy(nelr,stk(lr+nel),1,stk(l1+nelr),1)
lstk(top+1)=l1+nelr*(itr+1)
go to 999 ! c'est un return
90 continue
c **** insertion arg4(arg1,arg2)=arg3 *****
c (comments added by Bruno to try to understand this stuff)
c get arg4
il4=iadr(lstk(top))
top4 = top ! pour le cas en place
if(istk(il4).lt.0) il4=iadr(istk(il4+1))
m4=istk(il4+1)
n4=istk(il4+2)
it4=istk(il4+3)
if(istk(il4).eq.5) then ! arg4 is a sparse matrix
nel4=istk(il4+4)
irc4=il4+5 ! irc4 index in istk for the arrays mnel(m4 elts) and icol(nel4 elts)
l4=sadr(irc4+m4+nel4) ! l4 index in stk for the coef arrays (real and complex if any)
else
top=top0
fin=-fin
return
endif
mn4=m4*n4
c get arg3 ! for insertion arg4(arg1,arg2)=arg3
top=top-1
il3=iadr(lstk(top))
if(istk(il3).lt.0) il3=iadr(istk(il3+1))
m3=istk(il3+1)
n3=istk(il3+2)
it3=istk(il3+3)
if(istk(il3).eq.5) then ! arg3 is a sparse matrix
nel3=istk(il3+4)
irc3=il3+5
l3=sadr(irc3+m3+nel3)
elseif(istk(il3).eq.1) then ! arg3 is a full matrix
l3=sadr(il3+4)
nel3=m3*n3
else
top=top0
fin=-fin
return
endif
mn3=m3*n3
c get arg2 ! for insertion arg4(arg1,arg2)=arg3
top=top-1
il2=iadr(lstk(top))
if(istk(il2).lt.0) il2=iadr(istk(il2+1))
m2=istk(il2+1)
c get arg1 ! for insertion arg4(arg1,arg2)=arg3
top=top-1
il1=iadr(lstk(top))
ilrs=il1
if(istk(il1).lt.0) il1=iadr(istk(il1+1))
m1=istk(il1+1)
if (m3.eq.0) then ! So this is the operation arg4(arg1,arg2) = [] => all rows of
! of indices arg1 and all columns of indices arg2 must be deleted.
! In the following many special cases are taken into account
! this is certainly not necessary.
if(m1.eq.-1.and.m2.eq.-1) then
! this is arg4(:,:)=[] and so arg4 becomes a empty matrix arg4 <- []
istk(ilrs)=1
istk(ilrs+1)=0
istk(ilrs+2)=0
istk(ilrs+3)=0
lstk(top+1)=sadr(ilrs+4)+1
goto 999 ! goto the end
elseif(m1.eq.0.or.m2.eq.0) then
! this is arg4([],arg2)=[] or arg4(arg1,[])=[] --> arg4 is not modified
call icopy(5+m4+nel4,istk(il4),1,istk(ilrs),1) ! ilrs index in istk of the result
l=sadr(ilrs+5+m4+nel4)
call unsfdcopy(nel4*(it4+1),stk(l4),1,stk(l),1)
lstk(top+1)=l+mn4*(it4+1)
goto 999
elseif(m2.eq.-1) then
! this is arg3(arg1,:)=[] --> arg3(compl(arg1),:)
call indxgc(il1,m4,ili,mi,mxi,lw)
if(err.gt.0) return
mr=mi
call indxg(il2,n4,ilj,nj,mxj,lw,11)
if(err.gt.0) return
if(nj.lt.0) then
nr=mxj
else
nr=nj
endif
l3=l4
n3=n4
m3=m4
mn3=m3*n3
it3=it4
irc3=irc4
nel3=nel4
c . call extraction (the result is arg3(compl(arg1),:))
goto 76
elseif(m1.eq.-1) then
! this is arg4(:,arg2)=[] --> arg4(:,compl(arg2))
call indxgc(il2,n4,ilj,nj,mxj,lw)
if(err.gt.0) return
nr=nj
call indxg(il1,m4,ili,mi,mxi,lw,11)
if(err.gt.0) return
if(mi.lt.0) then
mr=mxi
else
mr=mi
endif
l3=l4
n3=n4
m3=m4
mn3=m3*n3
it3=it4
irc3=irc4
nel3=nel4
c . call extraction (the result is arg3(:,compl(arg2)))
goto 76
else
! this is arg4(arg1,arg2)=[]
lw1=lw
call indxgc(il2,n4,ilj,nj,mxj,lw)
if(err.gt.0) return
nr=nj
if(nj.eq.0) then
c . arg4(arg1,1:n4)=[]
call indxgc(il1,m4,ili,mi,mxi,lw)
lw2=lw
if(err.gt.0) return
mr=mi
c . arg2=1:n3
if(mi.eq.0) then
c . arg4(1:m4,1:n4)=[]
istk(ilrs)=1
istk(ilrs+1)=0
istk(ilrs+2)=0
istk(ilrs+3)=0
lstk(top+1)=sadr(ilrs+4)+1
goto 999
else
c . arg4(arg1,1:n4)=[]
c . replace arg2 by ":"
il2=iadr(lw2)
istk(il2)=1
istk(il2+1)=-1
istk(il2+2)=-1
istk(il2+3)=0
c .
lw=lw2+2
call indxg(il2,n4,ilj,nj,mxj,lw,11)
if(err.gt.0) return
if(nj.lt.0) then
nr=mxj
else
nr=nj
endif
l3=l4
n3=n4
m3=m4
it3=it4
mn3=m3*n3
irc3=irc4
nel3=nel4
c . call extraction
goto 76
endif
else
c lw=lw1
call indxgc(il1,m4,ili,mi,mxi,lw)
if(err.gt.0) return
if(mi.eq.0) then
c . arg4(1:m4,arg2)=[]
call indxg(il1,m4,ili,mi,mxi,lw,11)
if(err.gt.0) return
if(mi.lt.0) then
mr=mxi
else
mr=mi
endif
l3=l4
n3=n4
m3=m4
it3=it4
mn3=m3*n3
irc3=irc4
nel3=nel4
c . call extraction
goto 76
else
call error(15)
return
endif
endif
endif
elseif(m3.lt.0.or.m4.lt.0) then
c . arg3=eye , arg4=eye
call error(14)
return
elseif(m1.eq.-1.and.m2.eq.-1) then
c . arg4(:,:)=arg3
if(mn3.eq.mn4) then
if(m3.ne.m4) then ! bizarre ca on a alors A(:,:)=B qui ne change pas A
top=top0 ! en fait on imagine plutot une erreur a indiquer
fin=-fin
return
c . reshape arg3 according to arg4 : ici on a donc des matrices de tailles identiques
c il ne semble pas y avoir de distinctions entre sparse ou pleine pour arg3 (B)
c ca peut expliquer le plantage ... OUI
c remede : cependant ce cas peut etre pris en compte par les routines generiques
c plutot que de le traiter dans l'interface. De plus ce n'est pas si
c court comme code vu qu'il faut tester les coefs de B. L'interface
c ne doit s'occuper que des cas triviaux et des cas d'erreurs
*
* A signaler a Serge.
*
elseif (istk(il3) .eq. 5) then ! ajout bruno (si arg3 est pleine le code suivant n'est pas bon)
istk(ilrs)=5
istk(ilrs+1)=m4
istk(ilrs+2)=n4
call icopy(2+m3+nel3,istk(il3+3),1,istk(ilrs+3),1)
l1=sadr(ilrs+5+m3+nel3)
call unsfdcopy(nel3*(it3+1),stk(l3),1,stk(l1),1)
lstk(top+1)=l1+nel3*(it3+1)
return
endif
elseif(mn3.eq.1) then ! arg4(:,:)=arg3 avec arg3 un scalaire
istk(ilrs)=1 ! on change de type (matrice pleine)
istk(ilrs+1)=m4
istk(ilrs+2)=n4
istk(ilrs+3)=it3
l1=sadr(ilrs+4)
call dset(mn4,stk(l3),stk(l1),1)
if(it3.eq.1) call dset(mn4,stk(l3+1),stk(l1+mn4),1)
lstk(top+1)=l1+mn4*(it3+1)
return
else
call error(15)
return
endif
endif
! insertion arg4(arg1,arg2)=arg3 ... suite
call indxg(il1,m4,ili,mi,mxi,lw,11)
if(err.gt.0) return
if(mi.lt.0) then
mr1=mxi ! car indice implicite :
else
mr1=mi
endif
call indxg(il2,n4,ilj,mj,mxj,lw,11)
if(err.gt.0) return
if(mj.lt.0) then
nr1=mxj ! car indice implicite :
else
nr1=mj
endif
if(mr1.ne.m3.or.nr1.ne.n3) then
c . sizes of arg1 or arg2 dont agree with arg3 sizes
if(m3*n3.eq.1) then
if(mr1.eq.0.or.nr1.eq.0) then
call icopy(5+m4+nel4,istk(il4),1,istk(ilrs),1)
l=sadr(ilrs+5+m4+nel4)
call unsfdcopy(nel4*(it4+1),stk(l4),1,stk(l),1)
lstk(top+1)=l+mn4*(it4+1)
goto 999
endif
if(istk(il3).ne.1) then
top=top0
fin=-fin
return
endif
else
call error(15)
return
endif
else
if(mr1.eq.0.or.nr1.eq.0) then ! est-ce possible ?
call error(15)
return
endif
endif
mr=max(m4,mxi)
nr=max(n4,mxj)
c ! insertion arg4(arg1,arg2)=arg3 ... suite
! try if we can do insertion in place
if ( (istk(il3).eq.1) .and. (it4.ge.it3)
$ .and. (mi.gt.0).and.(mj.gt.0).and.(mi.le.m4).and.(mj.le.n4)
$ .and. (mi*mj.lt.nel4/4) ) then
*
lws = lw ! sauvegarde
lptr=iadr(lw) ! for ptr (size m4)
lka = lptr + m4 ! for ka (size mi*mj)
lw = sadr(lka+mi*mj)
err=lw-lstk(bot)
if (err .gt. 0) then
call error(17)
return
endif
call spifp(m4, n4, nel4, istk(irc4), istk(irc4+m4), stk(l4),
$ stk(l4+it4*nel4), it4, istk(ili), mi, istk(ilj), mj,
$ istk(lptr), istk(lka), it3, stk(l3),
$ stk(l3+mi*mj*it3), iflag)
if (iflag .eq. 1) then ! yes insertion in place is OK (and also done by spifp)
k=istk(iadr(lstk(top4))+2)
top = top - 1
call setref(k)
goto 999
else
lw = lws
endif
endif
itr=max(it4,it3)
if(istk(il3).eq.5) then ! insertion sparse(ind_i, ind_j) = sparse matrix
lptr=iadr(lw)
irc=lptr+mr+1
lw=sadr(irc+mr)
nelr=(lstk(bot)-lw)/(1+2*(itr+1))
if(nelr.le.0) then
err=lw-lstk(bot)
call error(17)
return
endif
lr=sadr(irc+mr+nelr)
lw=lr+nelr*(itr+1)
nel=nelr
if(itr.eq.0) then
call dspisp(m4,n4,stk(l4),nel4,istk(irc4),
$ istk(ili),mi,istk(ilj),mj,
$ m3,n3,stk(l3),nel3,istk(irc3),
$ mr,nr,stk(lr),nelr,istk(irc),istk(lptr),ierr)
else
call wspisp(m4,n4,stk(l4),stk(l4+nel4),nel4,istk(irc4),
$ istk(ili),mi,istk(ilj),mj,
$ m3,n3,stk(l3),stk(l3+nel3),nel3,istk(irc3),
$ mr,nr,stk(lr),stk(lr+nelr),nelr,istk(irc),
$ istk(lptr),ierr,it4,it3)
endif
else ! insertion sparse(ind_i, ind_j) = full matrix
ipi = iadr(lw) ! indice pour pi
ipj = ipi + max(0,mi) ! indice pour pj
irc = ipj + max(0,mj) ! indice pour C_mnel
lw = sadr(irc + mr) ! indice de stk partir duquel il faut caser C_icol, C_R et C_I
nelmax = 2*(lstk(bot)-lw)/(1+2*(itr+1))
if(nelmax .le. 0) then
err = lw-lstk(bot)
call error(17)
return
endif
lr = sadr(irc + mr + nelmax)
lw = lr + nelmax*(itr + 1)
c arg4(arg1,arg2)=arg3 A(i,j) = B
* subroutine spif(A_m, A_n, A_nel, A_it, A_mnel, A_icol, A_R, A_I,
* $ B_m, B_n, B_it, B_R, B_I,
* $ C_m, C_n, C_nel, C_it, C_mnel, C_icol, C_R, C_I,
* $ i, pi, ni, j, pj, nj, nelmax, ierr)
*
call spif(m4,n4,nel4,it4,istk(irc4),istk(irc4+m4),
$ stk(l4),stk(l4+it4*nel4),
$ m3,n3,it3,stk(l3),stk(l3+it3*m3*n3),
$ mr,nr,nelr,itr,istk(irc), istk(irc+mr),
$ stk(lr), stk(lr+itr*nelmax),
$ istk(ili), istk(ipi), mi, istk(ilj), istk(ipj), mj,
$ nelmax, ierr)
nel = nelmax
endif
if(ierr.ne.0) then ! methode a utiliser lorsque l'on peut difficilement
buf='not enough memory' ! evaluer la memoire manquante
call error(9999)
return
endif
istk(ilrs)=5
istk(ilrs+1)=mr
istk(ilrs+2)=nr
istk(ilrs+3)=itr
istk(ilrs+4)=nelr
call icopy(mr+nelr,istk(irc),1,istk(ilrs+5),1)
l1=sadr(ilrs+5+mr+nelr)
call unsfdcopy(nelr,stk(lr),1,stk(l1),1)
if(itr.eq.1) call unsfdcopy(nelr,stk(lr+nel),1,stk(l1+nelr),1)
lstk(top+1)=l1+nelr*(itr+1)
go to 999
c
c *. /. \.
120 fin=-fin
top=top+1
goto 999
c
130 continue
if(fin.eq.61) then
fin=-fin
top=top+1
goto 999
endif
c comparaisons
if(max(it1,it2).eq.1) then
if(op.ne.equal.and.op.ne.less+great) then
fin=-fin
top=top0
return
endif
endif
if (a1_is_empty .and. a2_is_empty) then
if(op.eq.equal.or.op.eq.less+great) then
istk(il1)=4
istk(il1+1)=1
istk(il1+2)=1
istk(il1+3)=1
if(op.eq.less+great) istk(il1+3)=0
lstk(top+1)=sadr(il1+4)
goto 999
else
call error(60)
return
endif
endif
if( (a1_is_empty .or. a2_is_empty).or.
& (.not.a1_is_scalar .and. .not. a2_is_scalar)) then
if(n1.ne.n2.or.m1.ne.m2) then
if(op.eq.equal.or.op.eq.less+great) then
istk(il1)=4
istk(il1+1)=1
istk(il1+2)=1
istk(il1+3)=0
if(op.eq.less+great) istk(il1+3)=1
lstk(top+1)=sadr(il1+4)
return
else
call error(60)
return
endif
endif
endif
c
mr=m1
nr=n1
if( a1_is_scalar ) then
mr=m2
nr=n2
endif
irc=iadr(lw)
nelmx=(iadr(lstk(bot))-irc-mr-10)
lw=sadr(irc+mr+nelmx)
err=lw-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
nel=nelmx
if(istk(il1).eq.1) then
if(itr.eq.1) then
call wsosp(op,m1,n1,stk(l1),stk(l1+nel1),
$ m2,n2,stk(l2),stk(l2+nel2),nel2,istk(irc2),
$ nel,istk(irc),ierr,it1,it2)
else
call dsosp(op,m1,n1,stk(l1),m2,n2,stk(l2),nel2,
$ istk(irc2),nel,istk(irc),ierr)
endif
elseif(istk(il2).eq.1) then
if(itr.eq.1) then
call wspos(op,m1,n1,stk(l1),stk(l1+nel1),nel1,istk(irc1),
$ m2,n2,stk(l2),stk(l2+nel2),
$ nel,istk(irc),ierr,it1,it2)
else
call dspos(op,m1,n1,stk(l1),nel1,istk(irc1),
$ m2,n2,stk(l2),nel,istk(irc),ierr)
endif
else
if(itr.eq.1) then
call wsposp(op,m1,n1,stk(l1),stk(l1+nel1),nel1,
$ istk(irc1),m2,n2,stk(l2),stk(l2+nel2),nel2,istk(irc2),
$ nel,istk(irc),ierr,it1,it2)
else
call dsposp(op,m1,n1,stk(l1),nel1,istk(irc1),
$ m2,n2,stk(l2),nel2,istk(irc2),
$ nel,istk(irc),ierr)
endif
endif
if(ierr.ne.0) then
buf='not enough memory'
call error(9999)
return
endif
istk(il1)=6
istk(il1+1)=mr
istk(il1+2)=nr
istk(il1+3)=0
istk(il1+4)=nel
irc1=il1+5
call icopy(mr+nel,istk(irc),1,istk(irc1),1)
l1=sadr(irc1+mr+nel)
lstk(top+1)=l1
go to 999
c
c kronecker
200 continue
top=top0
fin=-fin
return
c
999 return
end
|