I want to shift a sparse matrix (A
) one digit to left with adding zeros in the first column at the right. For that I am multiplying the matrix with Rotate
. However, when the matrix is big in size and diversity of values, it turn on to be slow. Is there a function in Julia to do that more efficiently?
Rotate=sparse([zeros(1,33); Matrix(1.0I, 33-1, 33-1) zeros(33-1,1)])
A=[-3 -4 -4 -4 -4 -3 -3 -3 -4 -4 -4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-3782 -3828 -3873 -3919 -3964 -4008 -4052 -4096 -4140 -4184 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
4000 3966 3932 3898 3863 3828 3792 3756 3719 3682 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
677 667 658 649 639 630 620 610 601 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
960 967 974 980 987 993 1000 1006 1012 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
606 604 603 601 599 598 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
107 113 119 124 130 135 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-784 -783 -782 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-65 -73 -80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
687 674 661 648 635 621 608 595 581 568 555 541 527 514 500 486 473 459 445 431 417 403 0 0 0 0 0 0 0 0 0 0 0;
1352 1359 1366 1372 1379 1385 1391 1397 1403 1409 1415 1420 1426 1431 1436 1441 1446 1450 1455 1459 1464 1468 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
588 569 550 531 512 493 474 455 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1980 1986 1992 1997 2003 2008 2013 2018 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-1 -1 -1 -2 -2 -2 -2 -2 -2 -2 -2 -2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1081 1079 1077 1075 1073 1071 1068 1066 1064 1061 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
223 234 244 254 265 275 285 295 306 316 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1428 1420 1413 1405 1397 1390 1382 1374 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
742 756 769 783 796 810 823 837 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1867 1844 1821 1798 1774 1751 1727 1703 1679 1654 1630 1605 1581 1556 1531 1506 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
2458 2476 2493 2511 2528 2545 2562 2579 2595 2611 2627 2643 2658 2674 2688 2703 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0;
2262 2235 2208 2180 2152 2124 2096 2067 2039 2010 1981 1952 1922 1893 1863 1833 1803 1773 1743 1712 0 0 0 0 0 0 0 0 0 0 0 0 0;
2918 2939 2961 2982 3003 3023 3044 3064 3083 3103 3122 3141 3160 3178 3196 3214 3232 3249 3266 3283 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1703 1699 1696 1692 1688 1684 1680 1676 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
313 330 346 363 379 395 411 428 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-174 -171 -168 -165 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-343 -345 -346 -347 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
4 4 3 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-413 -440 -468 -495 -522 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
2855 2852 2849 2845 2841 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-4 -4 -4 -5 -5 -5 -5 -5 -5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1313 1293 1273 1253 1233 1212 1191 1171 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
2396 2408 2420 2431 2443 2454 2465 2476 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
-1564 -1557 -1551 -1544 -1537 -1530 -1523 -1516 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
julia> A*Rotate