From a24a72afe5c83c145faae1dfcac5fb4d5542d340 Mon Sep 17 00:00:00 2001 From: Gareth Aneurin Tribello Date: Tue, 16 Jul 2024 12:01:51 +0100 Subject: [PATCH] Optimisation of MatrixVectorProduct to improve performance when multiplying matrix by vector of ones If you are multiplying the matrix by a vector of ones you don't need to do any multiplication. You can just sum each row of the matrix. This is now used to calculate this type of matrix-vector product. The change speeds up the code slightly in an operation that is done reasonably often. Changes to regtests are due to the derivatives on the constant vector of ones no longer being stored or used. --- .../adjmat/rt-basic-matrix/deriv.reference | 238 ++++----- .../envsim/rt-env-sim-deriv/deriv.reference | 500 +++++++++--------- regtest/pamm/rt-hbpamm/deriv.reference | 8 +- regtest/pamm/rt-hbpamm/deriv2.reference | 6 +- regtest/pamm/rt-hbpamm/deriv3.reference | 8 +- .../derivatives.reference | 100 ++-- src/matrixtools/MatrixTimesVector.cpp | 27 +- 7 files changed, 455 insertions(+), 432 deletions(-) diff --git a/regtest/adjmat/rt-basic-matrix/deriv.reference b/regtest/adjmat/rt-basic-matrix/deriv.reference index 6becfd73d3..5570704697 100644 --- a/regtest/adjmat/rt-basic-matrix/deriv.reference +++ b/regtest/adjmat/rt-basic-matrix/deriv.reference @@ -29,13 +29,13 @@ 0.000000 27 -0.2261 0.000000 28 0.2433 0.000000 29 12.0120 - 0.000000 30 3.1500 - 0.000000 31 2.0092 - 0.000000 32 2.5569 - 0.000000 33 2.6536 - 0.000000 34 2.5500 - 0.000000 35 2.0168 - 0.000000 36 1.8642 + 0.000000 30 0.0000 + 0.000000 31 0.0000 + 0.000000 32 0.0000 + 0.000000 33 0.0000 + 0.000000 34 0.0000 + 0.000000 35 0.0000 + 0.000000 36 0.0000 1.000000 0 -4.1853 1.000000 1 1.1156 1.000000 2 -0.1042 @@ -66,13 +66,13 @@ 1.000000 27 0.6358 1.000000 28 4.9862 1.000000 29 10.1720 - 1.000000 30 2.1750 - 1.000000 31 3.4387 - 1.000000 32 3.1960 - 1.000000 33 2.2718 - 1.000000 34 3.4027 - 1.000000 35 3.3940 - 1.000000 36 2.4658 + 1.000000 30 0.0000 + 1.000000 31 0.0000 + 1.000000 32 0.0000 + 1.000000 33 0.0000 + 1.000000 34 0.0000 + 1.000000 35 0.0000 + 1.000000 36 0.0000 2.000000 0 -1.1577 2.000000 1 0.3744 2.000000 2 -0.0623 @@ -103,13 +103,13 @@ 2.000000 27 -0.3126 2.000000 28 3.6636 2.000000 29 7.0672 - 2.000000 30 1.9864 - 2.000000 31 1.2723 - 2.000000 32 1.7105 - 2.000000 33 1.6167 - 2.000000 34 1.6259 - 2.000000 35 1.7598 - 2.000000 36 2.0571 + 2.000000 30 0.0000 + 2.000000 31 0.0000 + 2.000000 32 0.0000 + 2.000000 33 0.0000 + 2.000000 34 0.0000 + 2.000000 35 0.0000 + 2.000000 36 0.0000 3.000000 0 -3.0752 3.000000 1 0.0004 3.000000 2 0.0961 @@ -140,13 +140,13 @@ 3.000000 27 0.0486 3.000000 28 0.0444 3.000000 29 9.5142 - 3.000000 30 1.6184 - 3.000000 31 2.4247 - 3.000000 32 2.1079 - 3.000000 33 1.9399 - 3.000000 34 1.8526 - 3.000000 35 2.2500 - 3.000000 36 2.3311 + 3.000000 30 0.0000 + 3.000000 31 0.0000 + 3.000000 32 0.0000 + 3.000000 33 0.0000 + 3.000000 34 0.0000 + 3.000000 35 0.0000 + 3.000000 36 0.0000 4.000000 0 -1.6243 4.000000 1 -0.1528 4.000000 2 0.1406 @@ -177,13 +177,13 @@ 4.000000 27 -1.1831 4.000000 28 0.5552 4.000000 29 12.6378 - 4.000000 30 2.6553 - 4.000000 31 1.7604 - 4.000000 32 2.5729 - 4.000000 33 2.4249 - 4.000000 34 2.1443 - 4.000000 35 2.1089 - 4.000000 36 2.4091 + 4.000000 30 0.0000 + 4.000000 31 0.0000 + 4.000000 32 0.0000 + 4.000000 33 0.0000 + 4.000000 34 0.0000 + 4.000000 35 0.0000 + 4.000000 36 0.0000 5.000000 0 0.5418 5.000000 1 0.1694 5.000000 2 0.2520 @@ -214,13 +214,13 @@ 5.000000 27 0.0001 5.000000 28 -0.0004 5.000000 29 3.5041 - 5.000000 30 0.6401 - 5.000000 31 0.6401 - 5.000000 32 0.6516 - 5.000000 33 0.6516 - 5.000000 34 0.6351 - 5.000000 35 0.6351 - 5.000000 36 0.6582 + 5.000000 30 0.0000 + 5.000000 31 0.0000 + 5.000000 32 0.0000 + 5.000000 33 0.0000 + 5.000000 34 0.0000 + 5.000000 35 0.0000 + 5.000000 36 0.0000 6.000000 0 1.6176 6.000000 1 2.4456 6.000000 2 -0.9183 @@ -251,13 +251,13 @@ 6.000000 27 2.8834 6.000000 28 -3.3605 6.000000 29 5.1466 - 6.000000 30 1.3643 - 6.000000 31 2.7047 - 6.000000 32 1.2990 - 6.000000 33 2.6892 - 6.000000 34 2.5161 - 6.000000 35 1.0621 - 6.000000 36 1.0309 + 6.000000 30 0.0000 + 6.000000 31 0.0000 + 6.000000 32 0.0000 + 6.000000 33 0.0000 + 6.000000 34 0.0000 + 6.000000 35 0.0000 + 6.000000 36 0.0000 7.000000 0 1.5828 7.000000 1 0.6758 7.000000 2 0.2480 @@ -288,13 +288,13 @@ 7.000000 27 -0.1813 7.000000 28 -0.6017 7.000000 29 0.7069 - 7.000000 30 1.2467 - 7.000000 31 2.8112 - 7.000000 32 2.5584 - 7.000000 33 1.2594 - 7.000000 34 2.8544 - 7.000000 35 1.4572 - 7.000000 36 1.6125 + 7.000000 30 0.0000 + 7.000000 31 0.0000 + 7.000000 32 0.0000 + 7.000000 33 0.0000 + 7.000000 34 0.0000 + 7.000000 35 0.0000 + 7.000000 36 0.0000 8.000000 0 -0.9176 8.000000 1 0.4528 8.000000 2 -1.1395 @@ -325,13 +325,13 @@ 8.000000 27 2.6078 8.000000 28 -2.0658 8.000000 29 2.8882 - 8.000000 30 3.4515 - 8.000000 31 3.4521 - 8.000000 32 2.1283 - 8.000000 33 3.3715 - 8.000000 34 2.1283 - 8.000000 35 2.1510 - 8.000000 36 1.2032 + 8.000000 30 0.0000 + 8.000000 31 0.0000 + 8.000000 32 0.0000 + 8.000000 33 0.0000 + 8.000000 34 0.0000 + 8.000000 35 0.0000 + 8.000000 36 0.0000 9.000000 0 -0.4583 9.000000 1 0.0332 9.000000 2 -0.1815 @@ -362,13 +362,13 @@ 9.000000 27 -0.3805 9.000000 28 1.5300 9.000000 29 0.6692 - 9.000000 30 3.0861 - 9.000000 31 1.2940 - 9.000000 32 2.7151 - 9.000000 33 2.7151 - 9.000000 34 1.2940 - 9.000000 35 1.8200 - 9.000000 36 0.4348 + 9.000000 30 0.0000 + 9.000000 31 0.0000 + 9.000000 32 0.0000 + 9.000000 33 0.0000 + 9.000000 34 0.0000 + 9.000000 35 0.0000 + 9.000000 36 0.0000 10.000000 0 0.2296 10.000000 1 -0.0319 10.000000 2 0.2869 @@ -399,13 +399,13 @@ 10.000000 27 0.7413 10.000000 28 -2.6069 10.000000 29 6.7351 - 10.000000 30 2.8118 - 10.000000 31 1.1821 - 10.000000 32 2.4341 - 10.000000 33 2.4662 - 10.000000 34 1.0432 - 10.000000 35 1.7090 - 10.000000 36 0.3802 + 10.000000 30 0.0000 + 10.000000 31 0.0000 + 10.000000 32 0.0000 + 10.000000 33 0.0000 + 10.000000 34 0.0000 + 10.000000 35 0.0000 + 10.000000 36 0.0000 11.000000 0 -0.0008 11.000000 1 0.0000 11.000000 2 -0.0015 @@ -436,13 +436,13 @@ 11.000000 27 0.0098 11.000000 28 0.0000 11.000000 29 0.0337 - 11.000000 30 0.0079 - 11.000000 31 0.0043 - 11.000000 32 0.0019 - 11.000000 33 0.0081 - 11.000000 34 0.0055 - 11.000000 35 0.0025 - 11.000000 36 0.0008 + 11.000000 30 0.0000 + 11.000000 31 0.0000 + 11.000000 32 0.0000 + 11.000000 33 0.0000 + 11.000000 34 0.0000 + 11.000000 35 0.0000 + 11.000000 36 0.0000 12.000000 0 0.5252 12.000000 1 3.2121 12.000000 2 0.5459 @@ -473,13 +473,13 @@ 12.000000 27 -1.2697 12.000000 28 1.4907 12.000000 29 0.6659 - 12.000000 30 1.2423 - 12.000000 31 3.1151 - 12.000000 32 1.2424 - 12.000000 33 2.6744 - 12.000000 34 2.6744 - 12.000000 35 1.6248 - 12.000000 36 0.4961 + 12.000000 30 0.0000 + 12.000000 31 0.0000 + 12.000000 32 0.0000 + 12.000000 33 0.0000 + 12.000000 34 0.0000 + 12.000000 35 0.0000 + 12.000000 36 0.0000 13.000000 0 0.2000 13.000000 1 3.3301 13.000000 2 -0.0176 @@ -510,13 +510,13 @@ 13.000000 27 0.0043 13.000000 28 -0.0463 13.000000 29 0.0003 - 13.000000 30 1.2007 - 13.000000 31 3.0617 - 13.000000 32 1.2025 - 13.000000 33 2.6169 - 13.000000 34 2.6467 - 13.000000 35 1.6902 - 13.000000 36 0.5966 + 13.000000 30 0.0000 + 13.000000 31 0.0000 + 13.000000 32 0.0000 + 13.000000 33 0.0000 + 13.000000 34 0.0000 + 13.000000 35 0.0000 + 13.000000 36 0.0000 14.000000 0 0.3029 14.000000 1 3.0058 14.000000 2 -0.6902 @@ -547,13 +547,13 @@ 14.000000 27 0.1165 14.000000 28 -0.5887 14.000000 29 0.7712 - 14.000000 30 1.3378 - 14.000000 31 2.9302 - 14.000000 32 1.1877 - 14.000000 33 2.6162 - 14.000000 34 2.5164 - 14.000000 35 1.6436 - 14.000000 36 0.6848 + 14.000000 30 0.0000 + 14.000000 31 0.0000 + 14.000000 32 0.0000 + 14.000000 33 0.0000 + 14.000000 34 0.0000 + 14.000000 35 0.0000 + 14.000000 36 0.0000 15.000000 0 1.1413 15.000000 1 -1.8689 15.000000 2 0.0495 @@ -584,13 +584,13 @@ 15.000000 27 0.0378 15.000000 28 -0.2717 15.000000 29 0.0068 - 15.000000 30 2.5001 - 15.000000 31 2.0389 - 15.000000 32 2.9140 - 15.000000 33 2.1558 - 15.000000 34 2.4064 - 15.000000 35 2.5594 - 15.000000 36 1.6052 + 15.000000 30 0.0000 + 15.000000 31 0.0000 + 15.000000 32 0.0000 + 15.000000 33 0.0000 + 15.000000 34 0.0000 + 15.000000 35 0.0000 + 15.000000 36 0.0000 16.000000 0 -1.5136 16.000000 1 -2.5965 16.000000 2 1.5726 @@ -621,10 +621,10 @@ 16.000000 27 -0.6392 16.000000 28 -0.7778 16.000000 29 5.9309 - 16.000000 30 2.1657 - 16.000000 31 3.6819 - 16.000000 32 2.1658 - 16.000000 33 2.2287 - 16.000000 34 3.5447 - 16.000000 35 2.2288 - 16.000000 36 2.6660 + 16.000000 30 0.0000 + 16.000000 31 0.0000 + 16.000000 32 0.0000 + 16.000000 33 0.0000 + 16.000000 34 0.0000 + 16.000000 35 0.0000 + 16.000000 36 0.0000 diff --git a/regtest/envsim/rt-env-sim-deriv/deriv.reference b/regtest/envsim/rt-env-sim-deriv/deriv.reference index ae925ec020..72d7654ff4 100644 --- a/regtest/envsim/rt-env-sim-deriv/deriv.reference +++ b/regtest/envsim/rt-env-sim-deriv/deriv.reference @@ -758,253 +758,253 @@ 0.000000 756 0.00004 0.000000 757 -0.00005 0.000000 758 0.00844 - 0.000000 759 0.00400 - 0.000000 760 0.00401 - 0.000000 761 0.00400 - 0.000000 762 0.00400 - 0.000000 763 0.00401 - 0.000000 764 0.00400 - 0.000000 765 0.00401 - 0.000000 766 0.00401 - 0.000000 767 0.00401 - 0.000000 768 0.00400 - 0.000000 769 0.00401 - 0.000000 770 0.00400 - 0.000000 771 0.00400 - 0.000000 772 0.00401 - 0.000000 773 0.00400 - 0.000000 774 0.00401 - 0.000000 775 0.00401 - 0.000000 776 0.00400 - 0.000000 777 0.00400 - 0.000000 778 0.00400 - 0.000000 779 0.00400 - 0.000000 780 0.00400 - 0.000000 781 0.00400 - 0.000000 782 0.00400 - 0.000000 783 0.00400 - 0.000000 784 0.00401 - 0.000000 785 0.00401 - 0.000000 786 0.00401 - 0.000000 787 0.00400 - 0.000000 788 0.00400 - 0.000000 789 0.00400 - 0.000000 790 0.00400 - 0.000000 791 0.00401 - 0.000000 792 0.00401 - 0.000000 793 0.00401 - 0.000000 794 0.00400 - 0.000000 795 0.00401 - 0.000000 796 0.00400 - 0.000000 797 0.00401 - 0.000000 798 0.00401 - 0.000000 799 0.00400 - 0.000000 800 0.00400 - 0.000000 801 0.00401 - 0.000000 802 0.00400 - 0.000000 803 0.00401 - 0.000000 804 0.00400 - 0.000000 805 0.00401 - 0.000000 806 0.00400 - 0.000000 807 0.00401 - 0.000000 808 0.00401 - 0.000000 809 0.00400 - 0.000000 810 0.00400 - 0.000000 811 0.00401 - 0.000000 812 0.00401 - 0.000000 813 0.00400 - 0.000000 814 0.00401 - 0.000000 815 0.00401 - 0.000000 816 0.00401 - 0.000000 817 0.00401 - 0.000000 818 0.00401 - 0.000000 819 0.00401 - 0.000000 820 0.00401 - 0.000000 821 0.00400 - 0.000000 822 0.00401 - 0.000000 823 0.00400 - 0.000000 824 0.00400 - 0.000000 825 0.00401 - 0.000000 826 0.00400 - 0.000000 827 0.00401 - 0.000000 828 0.00400 - 0.000000 829 0.00400 - 0.000000 830 0.00400 - 0.000000 831 0.00400 - 0.000000 832 0.00401 - 0.000000 833 0.00400 - 0.000000 834 0.00401 - 0.000000 835 0.00400 - 0.000000 836 0.00400 - 0.000000 837 0.00401 - 0.000000 838 0.00400 - 0.000000 839 0.00400 - 0.000000 840 0.00400 - 0.000000 841 0.00400 - 0.000000 842 0.00400 - 0.000000 843 0.00400 - 0.000000 844 0.00400 - 0.000000 845 0.00401 - 0.000000 846 0.00401 - 0.000000 847 0.00400 - 0.000000 848 0.00400 - 0.000000 849 0.00401 - 0.000000 850 0.00400 - 0.000000 851 0.00401 - 0.000000 852 0.00400 - 0.000000 853 0.00400 - 0.000000 854 0.00401 - 0.000000 855 0.00400 - 0.000000 856 0.00400 - 0.000000 857 0.00400 - 0.000000 858 0.00401 - 0.000000 859 0.00400 - 0.000000 860 0.00401 - 0.000000 861 0.00401 - 0.000000 862 0.00401 - 0.000000 863 0.00401 - 0.000000 864 0.00401 - 0.000000 865 0.00400 - 0.000000 866 0.00401 - 0.000000 867 0.00400 - 0.000000 868 0.00400 - 0.000000 869 0.00401 - 0.000000 870 0.00401 - 0.000000 871 0.00401 - 0.000000 872 0.00401 - 0.000000 873 0.00400 - 0.000000 874 0.00401 - 0.000000 875 0.00401 - 0.000000 876 0.00400 - 0.000000 877 0.00401 - 0.000000 878 0.00400 - 0.000000 879 0.00400 - 0.000000 880 0.00401 - 0.000000 881 0.00401 - 0.000000 882 0.00401 - 0.000000 883 0.00400 - 0.000000 884 0.00401 - 0.000000 885 0.00401 - 0.000000 886 0.00401 - 0.000000 887 0.00401 - 0.000000 888 0.00401 - 0.000000 889 0.00401 - 0.000000 890 0.00400 - 0.000000 891 0.00400 - 0.000000 892 0.00401 - 0.000000 893 0.00400 - 0.000000 894 0.00401 - 0.000000 895 0.00401 - 0.000000 896 0.00400 - 0.000000 897 0.00401 - 0.000000 898 0.00400 - 0.000000 899 0.00400 - 0.000000 900 0.00401 - 0.000000 901 0.00401 - 0.000000 902 0.00400 - 0.000000 903 0.00400 - 0.000000 904 0.00401 - 0.000000 905 0.00400 - 0.000000 906 0.00400 - 0.000000 907 0.00400 - 0.000000 908 0.00401 - 0.000000 909 0.00401 - 0.000000 910 0.00401 - 0.000000 911 0.00401 - 0.000000 912 0.00401 - 0.000000 913 0.00400 - 0.000000 914 0.00400 - 0.000000 915 0.00400 - 0.000000 916 0.00400 - 0.000000 917 0.00401 - 0.000000 918 0.00400 - 0.000000 919 0.00400 - 0.000000 920 0.00400 - 0.000000 921 0.00401 - 0.000000 922 0.00401 - 0.000000 923 0.00400 - 0.000000 924 0.00401 - 0.000000 925 0.00400 - 0.000000 926 0.00401 - 0.000000 927 0.00400 - 0.000000 928 0.00401 - 0.000000 929 0.00400 - 0.000000 930 0.00400 - 0.000000 931 0.00400 - 0.000000 932 0.00401 - 0.000000 933 0.00400 - 0.000000 934 0.00400 - 0.000000 935 0.00401 - 0.000000 936 0.00400 - 0.000000 937 0.00400 - 0.000000 938 0.00400 - 0.000000 939 0.00401 - 0.000000 940 0.00400 - 0.000000 941 0.00401 - 0.000000 942 0.00401 - 0.000000 943 0.00400 - 0.000000 944 0.00400 - 0.000000 945 0.00400 - 0.000000 946 0.00401 - 0.000000 947 0.00401 - 0.000000 948 0.00401 - 0.000000 949 0.00401 - 0.000000 950 0.00401 - 0.000000 951 0.00400 - 0.000000 952 0.00400 - 0.000000 953 0.00400 - 0.000000 954 0.00400 - 0.000000 955 0.00400 - 0.000000 956 0.00400 - 0.000000 957 0.00400 - 0.000000 958 0.00400 - 0.000000 959 0.00400 - 0.000000 960 0.00400 - 0.000000 961 0.00401 - 0.000000 962 0.00400 - 0.000000 963 0.00400 - 0.000000 964 0.00400 - 0.000000 965 0.00400 - 0.000000 966 0.00401 - 0.000000 967 0.00400 - 0.000000 968 0.00400 - 0.000000 969 0.00400 - 0.000000 970 0.00400 - 0.000000 971 0.00401 - 0.000000 972 0.00401 - 0.000000 973 0.00401 - 0.000000 974 0.00401 - 0.000000 975 0.00401 - 0.000000 976 0.00401 - 0.000000 977 0.00401 - 0.000000 978 0.00400 - 0.000000 979 0.00401 - 0.000000 980 0.00401 - 0.000000 981 0.00400 - 0.000000 982 0.00401 - 0.000000 983 0.00401 - 0.000000 984 0.00401 - 0.000000 985 0.00400 - 0.000000 986 0.00401 - 0.000000 987 0.00400 - 0.000000 988 0.00401 - 0.000000 989 0.00400 - 0.000000 990 0.00401 - 0.000000 991 0.00400 - 0.000000 992 0.00400 - 0.000000 993 0.00401 - 0.000000 994 0.00400 - 0.000000 995 0.00400 - 0.000000 996 0.00401 - 0.000000 997 0.00400 - 0.000000 998 0.00400 - 0.000000 999 0.00400 - 0.000000 1000 0.00400 - 0.000000 1001 0.00401 - 0.000000 1002 0.00400 - 0.000000 1003 0.00401 - 0.000000 1004 0.00401 - 0.000000 1005 0.00401 - 0.000000 1006 0.00400 - 0.000000 1007 0.00401 - 0.000000 1008 0.00401 + 0.000000 759 0.00000 + 0.000000 760 0.00000 + 0.000000 761 0.00000 + 0.000000 762 0.00000 + 0.000000 763 0.00000 + 0.000000 764 0.00000 + 0.000000 765 0.00000 + 0.000000 766 0.00000 + 0.000000 767 0.00000 + 0.000000 768 0.00000 + 0.000000 769 0.00000 + 0.000000 770 0.00000 + 0.000000 771 0.00000 + 0.000000 772 0.00000 + 0.000000 773 0.00000 + 0.000000 774 0.00000 + 0.000000 775 0.00000 + 0.000000 776 0.00000 + 0.000000 777 0.00000 + 0.000000 778 0.00000 + 0.000000 779 0.00000 + 0.000000 780 0.00000 + 0.000000 781 0.00000 + 0.000000 782 0.00000 + 0.000000 783 0.00000 + 0.000000 784 0.00000 + 0.000000 785 0.00000 + 0.000000 786 0.00000 + 0.000000 787 0.00000 + 0.000000 788 0.00000 + 0.000000 789 0.00000 + 0.000000 790 0.00000 + 0.000000 791 0.00000 + 0.000000 792 0.00000 + 0.000000 793 0.00000 + 0.000000 794 0.00000 + 0.000000 795 0.00000 + 0.000000 796 0.00000 + 0.000000 797 0.00000 + 0.000000 798 0.00000 + 0.000000 799 0.00000 + 0.000000 800 0.00000 + 0.000000 801 0.00000 + 0.000000 802 0.00000 + 0.000000 803 0.00000 + 0.000000 804 0.00000 + 0.000000 805 0.00000 + 0.000000 806 0.00000 + 0.000000 807 0.00000 + 0.000000 808 0.00000 + 0.000000 809 0.00000 + 0.000000 810 0.00000 + 0.000000 811 0.00000 + 0.000000 812 0.00000 + 0.000000 813 0.00000 + 0.000000 814 0.00000 + 0.000000 815 0.00000 + 0.000000 816 0.00000 + 0.000000 817 0.00000 + 0.000000 818 0.00000 + 0.000000 819 0.00000 + 0.000000 820 0.00000 + 0.000000 821 0.00000 + 0.000000 822 0.00000 + 0.000000 823 0.00000 + 0.000000 824 0.00000 + 0.000000 825 0.00000 + 0.000000 826 0.00000 + 0.000000 827 0.00000 + 0.000000 828 0.00000 + 0.000000 829 0.00000 + 0.000000 830 0.00000 + 0.000000 831 0.00000 + 0.000000 832 0.00000 + 0.000000 833 0.00000 + 0.000000 834 0.00000 + 0.000000 835 0.00000 + 0.000000 836 0.00000 + 0.000000 837 0.00000 + 0.000000 838 0.00000 + 0.000000 839 0.00000 + 0.000000 840 0.00000 + 0.000000 841 0.00000 + 0.000000 842 0.00000 + 0.000000 843 0.00000 + 0.000000 844 0.00000 + 0.000000 845 0.00000 + 0.000000 846 0.00000 + 0.000000 847 0.00000 + 0.000000 848 0.00000 + 0.000000 849 0.00000 + 0.000000 850 0.00000 + 0.000000 851 0.00000 + 0.000000 852 0.00000 + 0.000000 853 0.00000 + 0.000000 854 0.00000 + 0.000000 855 0.00000 + 0.000000 856 0.00000 + 0.000000 857 0.00000 + 0.000000 858 0.00000 + 0.000000 859 0.00000 + 0.000000 860 0.00000 + 0.000000 861 0.00000 + 0.000000 862 0.00000 + 0.000000 863 0.00000 + 0.000000 864 0.00000 + 0.000000 865 0.00000 + 0.000000 866 0.00000 + 0.000000 867 0.00000 + 0.000000 868 0.00000 + 0.000000 869 0.00000 + 0.000000 870 0.00000 + 0.000000 871 0.00000 + 0.000000 872 0.00000 + 0.000000 873 0.00000 + 0.000000 874 0.00000 + 0.000000 875 0.00000 + 0.000000 876 0.00000 + 0.000000 877 0.00000 + 0.000000 878 0.00000 + 0.000000 879 0.00000 + 0.000000 880 0.00000 + 0.000000 881 0.00000 + 0.000000 882 0.00000 + 0.000000 883 0.00000 + 0.000000 884 0.00000 + 0.000000 885 0.00000 + 0.000000 886 0.00000 + 0.000000 887 0.00000 + 0.000000 888 0.00000 + 0.000000 889 0.00000 + 0.000000 890 0.00000 + 0.000000 891 0.00000 + 0.000000 892 0.00000 + 0.000000 893 0.00000 + 0.000000 894 0.00000 + 0.000000 895 0.00000 + 0.000000 896 0.00000 + 0.000000 897 0.00000 + 0.000000 898 0.00000 + 0.000000 899 0.00000 + 0.000000 900 0.00000 + 0.000000 901 0.00000 + 0.000000 902 0.00000 + 0.000000 903 0.00000 + 0.000000 904 0.00000 + 0.000000 905 0.00000 + 0.000000 906 0.00000 + 0.000000 907 0.00000 + 0.000000 908 0.00000 + 0.000000 909 0.00000 + 0.000000 910 0.00000 + 0.000000 911 0.00000 + 0.000000 912 0.00000 + 0.000000 913 0.00000 + 0.000000 914 0.00000 + 0.000000 915 0.00000 + 0.000000 916 0.00000 + 0.000000 917 0.00000 + 0.000000 918 0.00000 + 0.000000 919 0.00000 + 0.000000 920 0.00000 + 0.000000 921 0.00000 + 0.000000 922 0.00000 + 0.000000 923 0.00000 + 0.000000 924 0.00000 + 0.000000 925 0.00000 + 0.000000 926 0.00000 + 0.000000 927 0.00000 + 0.000000 928 0.00000 + 0.000000 929 0.00000 + 0.000000 930 0.00000 + 0.000000 931 0.00000 + 0.000000 932 0.00000 + 0.000000 933 0.00000 + 0.000000 934 0.00000 + 0.000000 935 0.00000 + 0.000000 936 0.00000 + 0.000000 937 0.00000 + 0.000000 938 0.00000 + 0.000000 939 0.00000 + 0.000000 940 0.00000 + 0.000000 941 0.00000 + 0.000000 942 0.00000 + 0.000000 943 0.00000 + 0.000000 944 0.00000 + 0.000000 945 0.00000 + 0.000000 946 0.00000 + 0.000000 947 0.00000 + 0.000000 948 0.00000 + 0.000000 949 0.00000 + 0.000000 950 0.00000 + 0.000000 951 0.00000 + 0.000000 952 0.00000 + 0.000000 953 0.00000 + 0.000000 954 0.00000 + 0.000000 955 0.00000 + 0.000000 956 0.00000 + 0.000000 957 0.00000 + 0.000000 958 0.00000 + 0.000000 959 0.00000 + 0.000000 960 0.00000 + 0.000000 961 0.00000 + 0.000000 962 0.00000 + 0.000000 963 0.00000 + 0.000000 964 0.00000 + 0.000000 965 0.00000 + 0.000000 966 0.00000 + 0.000000 967 0.00000 + 0.000000 968 0.00000 + 0.000000 969 0.00000 + 0.000000 970 0.00000 + 0.000000 971 0.00000 + 0.000000 972 0.00000 + 0.000000 973 0.00000 + 0.000000 974 0.00000 + 0.000000 975 0.00000 + 0.000000 976 0.00000 + 0.000000 977 0.00000 + 0.000000 978 0.00000 + 0.000000 979 0.00000 + 0.000000 980 0.00000 + 0.000000 981 0.00000 + 0.000000 982 0.00000 + 0.000000 983 0.00000 + 0.000000 984 0.00000 + 0.000000 985 0.00000 + 0.000000 986 0.00000 + 0.000000 987 0.00000 + 0.000000 988 0.00000 + 0.000000 989 0.00000 + 0.000000 990 0.00000 + 0.000000 991 0.00000 + 0.000000 992 0.00000 + 0.000000 993 0.00000 + 0.000000 994 0.00000 + 0.000000 995 0.00000 + 0.000000 996 0.00000 + 0.000000 997 0.00000 + 0.000000 998 0.00000 + 0.000000 999 0.00000 + 0.000000 1000 0.00000 + 0.000000 1001 0.00000 + 0.000000 1002 0.00000 + 0.000000 1003 0.00000 + 0.000000 1004 0.00000 + 0.000000 1005 0.00000 + 0.000000 1006 0.00000 + 0.000000 1007 0.00000 + 0.000000 1008 0.00000 diff --git a/regtest/pamm/rt-hbpamm/deriv.reference b/regtest/pamm/rt-hbpamm/deriv.reference index 643c414e66..e377789d77 100644 --- a/regtest/pamm/rt-hbpamm/deriv.reference +++ b/regtest/pamm/rt-hbpamm/deriv.reference @@ -21,8 +21,8 @@ 0.000000 19 0.0000 0.000000 20 0.0000 0.000000 21 0.0000 - 0.000000 22 -0.0000 - 0.000000 23 -0.0000 + 0.000000 22 0.0000 + 0.000000 23 0.0000 0.000000 24 -0.0024 0.000000 25 -0.0060 0.000000 26 -0.0068 @@ -35,6 +35,6 @@ 0.000000 33 -0.0011 0.000000 34 -0.0054 0.000000 35 -0.0056 - 0.000000 36 0.9990 - 0.000000 37 0.9992 + 0.000000 36 0.0000 + 0.000000 37 0.0000 0.000000 38 0.0000 diff --git a/regtest/pamm/rt-hbpamm/deriv2.reference b/regtest/pamm/rt-hbpamm/deriv2.reference index 4f808819b6..9adb7caa1e 100644 --- a/regtest/pamm/rt-hbpamm/deriv2.reference +++ b/regtest/pamm/rt-hbpamm/deriv2.reference @@ -33,7 +33,7 @@ 0.000000 31 0.0001 0.000000 32 -0.0000 0.000000 33 0.0000 - 0.000000 34 -0.0000 + 0.000000 34 0.0000 0.000000 35 0.0000 0.000000 36 -0.0018 0.000000 37 -0.0005 @@ -44,6 +44,6 @@ 0.000000 42 -0.0011 0.000000 43 -0.0054 0.000000 44 -0.0056 - 0.000000 45 0.9992 + 0.000000 45 0.0000 0.000000 46 0.0000 - 0.000000 47 0.9990 + 0.000000 47 0.0000 diff --git a/regtest/pamm/rt-hbpamm/deriv3.reference b/regtest/pamm/rt-hbpamm/deriv3.reference index 3589be9564..6b87c3a4d8 100644 --- a/regtest/pamm/rt-hbpamm/deriv3.reference +++ b/regtest/pamm/rt-hbpamm/deriv3.reference @@ -21,8 +21,8 @@ 0.000000 19 0.0000 0.000000 20 0.0000 0.000000 21 0.0000 - 0.000000 22 -0.0000 - 0.000000 23 -0.0000 + 0.000000 22 0.0000 + 0.000000 23 0.0000 0.000000 24 -0.0024 0.000000 25 -0.0060 0.000000 26 -0.0068 @@ -35,6 +35,6 @@ 0.000000 33 -0.0011 0.000000 34 -0.0054 0.000000 35 -0.0056 - 0.000000 36 0.9992 + 0.000000 36 0.0000 0.000000 37 0.0000 - 0.000000 38 0.9990 + 0.000000 38 0.0000 diff --git a/regtest/symfunc/rt-coordination-powers/derivatives.reference b/regtest/symfunc/rt-coordination-powers/derivatives.reference index ac8ef69303..e2a5fae55e 100644 --- a/regtest/symfunc/rt-coordination-powers/derivatives.reference +++ b/regtest/symfunc/rt-coordination-powers/derivatives.reference @@ -38,16 +38,16 @@ 0.000000 36 -0.0777 0.000000 37 0.0031 0.000000 38 2.5442 - 0.000000 39 0.1770 - 0.000000 40 0.2054 - 0.000000 41 0.1816 - 0.000000 42 0.2093 - 0.000000 43 0.2161 - 0.000000 44 0.1767 - 0.000000 45 0.2121 - 0.000000 46 0.1757 - 0.000000 47 0.1408 - 0.000000 48 0.1489 + 0.000000 39 0.0000 + 0.000000 40 0.0000 + 0.000000 41 0.0000 + 0.000000 42 0.0000 + 0.000000 43 0.0000 + 0.000000 44 0.0000 + 0.000000 45 0.0000 + 0.000000 46 0.0000 + 0.000000 47 0.0000 + 0.000000 48 0.0000 0.005000 0 0.3287 0.005000 1 0.2323 0.005000 2 0.1100 @@ -87,16 +87,16 @@ 0.005000 36 -0.0442 0.005000 37 0.0049 0.005000 38 2.4945 - 0.005000 39 0.1754 - 0.005000 40 0.1982 - 0.005000 41 0.1833 - 0.005000 42 0.2084 - 0.005000 43 0.2171 - 0.005000 44 0.1734 - 0.005000 45 0.2119 - 0.005000 46 0.1766 - 0.005000 47 0.1345 - 0.005000 48 0.1481 + 0.005000 39 0.0000 + 0.005000 40 0.0000 + 0.005000 41 0.0000 + 0.005000 42 0.0000 + 0.005000 43 0.0000 + 0.005000 44 0.0000 + 0.005000 45 0.0000 + 0.005000 46 0.0000 + 0.005000 47 0.0000 + 0.005000 48 0.0000 0.010000 0 0.3057 0.010000 1 0.2219 0.010000 2 0.1122 @@ -136,16 +136,16 @@ 0.010000 36 -0.0324 0.010000 37 0.0117 0.010000 38 2.4481 - 0.010000 39 0.1774 - 0.010000 40 0.1908 - 0.010000 41 0.1789 - 0.010000 42 0.2092 - 0.010000 43 0.2257 - 0.010000 44 0.1696 - 0.010000 45 0.2137 - 0.010000 46 0.1744 - 0.010000 47 0.1280 - 0.010000 48 0.1490 + 0.010000 39 0.0000 + 0.010000 40 0.0000 + 0.010000 41 0.0000 + 0.010000 42 0.0000 + 0.010000 43 0.0000 + 0.010000 44 0.0000 + 0.010000 45 0.0000 + 0.010000 46 0.0000 + 0.010000 47 0.0000 + 0.010000 48 0.0000 0.015000 0 0.2784 0.015000 1 0.2040 0.015000 2 0.0908 @@ -185,16 +185,16 @@ 0.015000 36 -0.0365 0.015000 37 -0.0103 0.015000 38 2.3506 - 0.015000 39 0.1764 - 0.015000 40 0.1828 - 0.015000 41 0.1686 - 0.015000 42 0.2043 - 0.015000 43 0.2286 - 0.015000 44 0.1635 - 0.015000 45 0.2136 - 0.015000 46 0.1684 - 0.015000 47 0.1220 - 0.015000 48 0.1479 + 0.015000 39 0.0000 + 0.015000 40 0.0000 + 0.015000 41 0.0000 + 0.015000 42 0.0000 + 0.015000 43 0.0000 + 0.015000 44 0.0000 + 0.015000 45 0.0000 + 0.015000 46 0.0000 + 0.015000 47 0.0000 + 0.015000 48 0.0000 0.020000 0 0.2666 0.020000 1 0.1868 0.020000 2 0.0703 @@ -234,13 +234,13 @@ 0.020000 36 -0.0319 0.020000 37 -0.0388 0.020000 38 2.2835 - 0.020000 39 0.1758 - 0.020000 40 0.1758 - 0.020000 41 0.1589 - 0.020000 42 0.1945 - 0.020000 43 0.2222 - 0.020000 44 0.1581 - 0.020000 45 0.2085 - 0.020000 46 0.1612 - 0.020000 47 0.1182 - 0.020000 48 0.1459 + 0.020000 39 0.0000 + 0.020000 40 0.0000 + 0.020000 41 0.0000 + 0.020000 42 0.0000 + 0.020000 43 0.0000 + 0.020000 44 0.0000 + 0.020000 45 0.0000 + 0.020000 46 0.0000 + 0.020000 47 0.0000 + 0.020000 48 0.0000 diff --git a/src/matrixtools/MatrixTimesVector.cpp b/src/matrixtools/MatrixTimesVector.cpp index 7554c96a89..4725b5131c 100644 --- a/src/matrixtools/MatrixTimesVector.cpp +++ b/src/matrixtools/MatrixTimesVector.cpp @@ -36,6 +36,7 @@ namespace matrixtools { class MatrixTimesVector : public ActionWithMatrix { private: + bool sumrows; unsigned nderivatives; std::vector stored_arg; public: @@ -78,7 +79,8 @@ std::string MatrixTimesVector::getOutputComponentDescription( const std::string& MatrixTimesVector::MatrixTimesVector(const ActionOptions&ao): Action(ao), - ActionWithMatrix(ao) + ActionWithMatrix(ao), + sumrows(false) { if( getNumberOfArguments()<2 ) error("Not enough arguments specified"); unsigned nvectors=0, nmatrices=0; @@ -114,6 +116,16 @@ MatrixTimesVector::MatrixTimesVector(const ActionOptions&ao): addComponent( name, shape ); componentIsNotPeriodic( name ); } } + if( (getPntrToArgument(n)->getPntrToAction())->getName()=="CONSTANT" ) { + sumrows=true; + if( getPntrToArgument(n)->getRank()==0 ) { + if( fabs( getPntrToArgument(n)->get() - 1.0 )>epsilon ) sumrows = false; + } else { + for(unsigned i=0; igetShape()[0]; ++i) { + if( fabs( getPntrToArgument(n)->get(i) - 1.0 )>epsilon ) { sumrows=false; break; } + } + } + } } else if( nmatrices==1 ) { if( getPntrToArgument(0)->getRank()!=2 || getPntrToArgument(0)->hasDerivatives() ) error("first argument to this action should be a matrix"); for(unsigned i=1; i=getPntrToArgument(0)->getShape()[0] ) ind2 = index2 - getPntrToArgument(0)->getShape()[0]; - if( getPntrToArgument(1)->getRank()==1 ) { + if( sumrows ) { + unsigned n=getNumberOfArguments()-1; double matval = 0; + for(unsigned i=0; igetPositionInStream(); + Value* myarg = getPntrToArgument(i); + if( !myarg->valueHasBeenSet() ) myvals.addValue( ostrn, myvals.get( myarg->getPositionInStream() ) ); + else myvals.addValue( ostrn, myarg->get( index1*myarg->getNumberOfColumns() + ind2, false ) ); + // Now lets work out the derivatives + if( doNotCalculateDerivatives() ) continue; + addDerivativeOnMatrixArgument( stored_arg[i], i, i, index1, ind2, 1.0, myvals ); + } + } else if( getPntrToArgument(1)->getRank()==1 ) { double matval = 0; Value* myarg = getPntrToArgument(0); unsigned vcol = ind2; if( !myarg->valueHasBeenSet() ) matval = myvals.get( myarg->getPositionInStream() ); else {