1 
2 #include "TMV_Test.h"
3 #include "TMV_Test_1.h"
4 #include "TMV.h"
5 #include <fstream>
6 
7 #include "TMV_TestMatrixArith.h"
8 #define CT std::complex<T>
9 
TestMatrixArith_1()10 template <class T> void TestMatrixArith_1()
11 {
12     tmv::Matrix<T,tmv::RowMajor> a1x(4,4);
13     for(int i=0;i<4;++i) for(int j=0;j<4;++j) {
14         a1x(i,j) = T(2+4*i-5*j);
15     }
16     a1x(0,0) = 14;
17     a1x(1,0) = -2;
18     a1x(2,0) = 7;
19     a1x(3,0) = -10;
20     a1x(2,2) = 30;
21 
22     tmv::Matrix<CT,tmv::RowMajor> ca1x = a1x;
23     ca1x(2,3) += CT(2,3);
24     ca1x(1,0) *= CT(0,2);
25     ca1x.col(1) *= CT(-1,3);
26     ca1x.row(3) += tmv::Vector<CT>(4,CT(1,9));
27 
28     tmv::Matrix<T,tmv::ColMajor> a2x = a1x.transpose();
29     a2x.row(1) *= T(3);
30     a2x.col(2) -= tmv::Vector<T>(4,4);
31     tmv::Matrix<CT,tmv::ColMajor> ca2x = ca1x;
32     ca2x -= a2x;
33     ca2x *= CT(1,-2);
34 
35     tmv::MatrixView<T> a1 = a1x.view();
36     tmv::MatrixView<CT> ca1 = ca1x.view();
37     tmv::MatrixView<T> a2 = a2x.view();
38     tmv::MatrixView<CT> ca2 = ca2x.view();
39 
40     TestMatrixArith1(a1,ca1,"Square 1");
41     TestMatrixArith1(a2,ca2,"Square 2");
42 #if (XTEST & 1)
43     tmv::Matrix<T> a3x(12,16);
44     for(int i=0;i<12;++i) for(int j=0;j<16;++j) a3x(i,j) = T(1-2*i+3*j);
45     a3x.diag().addToAll(30);
46     tmv::Matrix<CT> ca3x = a3x*CT(1,-2);
47     ca3x.diag().addToAll(CT(-22,15));
48 
49     tmv::MatrixView<T> a3 = a3x.subMatrix(0,12,0,16,3,4);
50     tmv::MatrixView<CT> ca3 = ca3x.subMatrix(0,12,0,16,3,4);
51     TestMatrixArith1(a3,ca3,"Square 3");
52 #endif
53 
54     tmv::Matrix<T,tmv::RowMajor> a4x(7,4);
55     for(int i=0;i<7;++i) for(int j=0;j<4;++j) a4x(i,j) = T(1-3*i+2*j);
56     tmv::Matrix<T,tmv::ColMajor> a5x = a4x.transpose();
57     a4x.subMatrix(2,6,0,4) += a1x;
58     a5x.subMatrix(0,4,1,5) -= a2x;
59 
60     tmv::Matrix<CT,tmv::RowMajor> ca4x = a4x*CT(1,2);
61     tmv::Matrix<CT,tmv::ColMajor> ca5x = ca4x.adjoint();
62     ca4x.subMatrix(2,6,0,4) += ca1x;
63     ca5x.subMatrix(0,4,1,5) -= ca2x;
64     ca4x.col(1) *= CT(2,1);
65     ca4x.row(6).addToAll(CT(-7,2));
66     ca5x.col(3) *= CT(-1,3);
67     ca5x.row(0).addToAll(CT(1,9));
68 
69     tmv::MatrixView<T> a4 = a4x.view();
70     tmv::MatrixView<CT> ca4 = ca4x.view();
71     tmv::MatrixView<T> a5 = a5x.view();
72     tmv::MatrixView<CT> ca5 = ca5x.view();
73     TestMatrixArith1(a4,ca4,"NonSquare 1");
74     TestMatrixArith1(a5,ca5,"NonSquare 2");
75 
76 #if (XTEST & 8)
77     tmv::Matrix<T> a6x(4,0,1);
78     tmv::Matrix<T> a7x(0,4,1);
79     tmv::Matrix<CT> ca6x = a6x;
80     tmv::Matrix<CT> ca7x = a7x;
81 
82     tmv::MatrixView<T> a6 = a6x.view();
83     tmv::MatrixView<CT> ca6 = ca6x.view();
84     tmv::MatrixView<T> a7 = a7x.view();
85     tmv::MatrixView<CT> ca7 = ca7x.view();
86     TestMatrixArith1(a6,ca6,"Degenerate 1");
87     TestMatrixArith1(a7,ca7,"Degenerate 2");
88 #endif
89 }
90 
91 #ifdef TEST_DOUBLE
92 template void TestMatrixArith_1<double>();
93 #endif
94 #ifdef TEST_FLOAT
95 template void TestMatrixArith_1<float>();
96 #endif
97 #ifdef TEST_LONGDOUBLE
98 template void TestMatrixArith_1<long double>();
99 #endif
100 #ifdef TEST_INT
101 template void TestMatrixArith_1<int>();
102 #endif
103