1 | |
---|
2 | //#define WANT_STREAM |
---|
3 | |
---|
4 | #include "include.h" |
---|
5 | |
---|
6 | #include "newmatap.h" |
---|
7 | //#include "newmatio.h" |
---|
8 | |
---|
9 | #include "tmt.h" |
---|
10 | |
---|
11 | #ifdef use_namespace |
---|
12 | using namespace NEWMAT; |
---|
13 | #endif |
---|
14 | |
---|
15 | |
---|
16 | void WillNotConverge() |
---|
17 | { |
---|
18 | Matrix A(10,10); |
---|
19 | Throw(ConvergenceException(A)); |
---|
20 | } |
---|
21 | |
---|
22 | void ReSizeMatrix(Matrix& A) |
---|
23 | // for seeing if we can redimension a vector as a matrix |
---|
24 | { A.ReSize(4,5); } |
---|
25 | |
---|
26 | void trymati() |
---|
27 | { |
---|
28 | #ifndef DisableExceptions |
---|
29 | Tracer et("Eighteenth test of Matrix package"); |
---|
30 | Matrix RUStillThere(10,20); RUStillThere = 1553; |
---|
31 | Tracer::PrintTrace(); |
---|
32 | |
---|
33 | ColumnVector checks(23); checks = 1.0; checks(1) = 0.0; |
---|
34 | |
---|
35 | Try { WillNotConverge(); } |
---|
36 | Catch(ConvergenceException) { checks(2) = 0; } |
---|
37 | CatchAll { checks(1) = 1; } |
---|
38 | |
---|
39 | |
---|
40 | Try { Matrix M(10,10); SymmetricMatrix S = M; } |
---|
41 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
42 | Catch(InternalException) { checks(1) = 1; } |
---|
43 | Catch(ProgramException) { checks(3) = 0; } |
---|
44 | CatchAll { checks(1) = 1; } |
---|
45 | |
---|
46 | |
---|
47 | Try { Matrix M(10,10); M(10,11) = 2.0; } |
---|
48 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
49 | Catch(InternalException) { checks(1) = 1; } |
---|
50 | Catch(IndexException) { checks(4) = 0; } |
---|
51 | CatchAll { checks(1) = 1; } |
---|
52 | |
---|
53 | Try { Matrix M(10,10); M = 0.0; M = M.i(); } |
---|
54 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
55 | Catch(InternalException) { checks(1) = 1; } |
---|
56 | Catch(ProgramException) { checks(1) = 1; } |
---|
57 | Catch(SingularException) { checks(5) = 0; } |
---|
58 | Catch(Bad_alloc) { checks(1) = 1; } |
---|
59 | CatchAndThrow; |
---|
60 | |
---|
61 | Try { ColumnVector A(30), B(50); A = 5; B = 3; FFT(A,B,A,B); } |
---|
62 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
63 | Catch(InternalException) { checks(1) = 1; } |
---|
64 | Catch(ProgramException) { checks(6) = 0; } |
---|
65 | CatchAll { checks(1) = 1; } |
---|
66 | |
---|
67 | Try |
---|
68 | { |
---|
69 | ColumnVector A(30); A = 5; Matrix At = A.t(); |
---|
70 | DiagonalMatrix D; |
---|
71 | SVD(At,D); |
---|
72 | } |
---|
73 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
74 | Catch(InternalException) { checks(1) = 1; } |
---|
75 | Catch(Logic_error) { checks(6) = 0; } |
---|
76 | Catch(Bad_alloc) { checks(1) = 1; } |
---|
77 | CatchAndThrow; |
---|
78 | |
---|
79 | Try { BandMatrix X(10,3,4); X(1,10) = 4.0; } |
---|
80 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
81 | Catch(InternalException) { checks(1) = 1; } |
---|
82 | Catch(IndexException) { checks(7) = 0; } |
---|
83 | CatchAll { checks(1) = 1; } |
---|
84 | |
---|
85 | Try |
---|
86 | { |
---|
87 | SymmetricMatrix S(10); S = 5; |
---|
88 | LowerTriangularMatrix L = Cholesky(S); |
---|
89 | } |
---|
90 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
91 | Catch(InternalException) { checks(1) = 1; } |
---|
92 | Catch(ProgramException) { checks(1) = 1; } |
---|
93 | Catch(NPDException) { checks(8) = 0; } |
---|
94 | Catch(Bad_alloc) { checks(1) = 1; } |
---|
95 | CatchAndThrow; |
---|
96 | |
---|
97 | Try { BandMatrix M(10,3,5); M = 0.0; Matrix XM = M.i(); } |
---|
98 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
99 | Catch(InternalException) { checks(1) = 1; } |
---|
100 | Catch(ProgramException) { checks(1) = 1; } |
---|
101 | Catch(SingularException) { checks(9) = 0; } |
---|
102 | Catch(Bad_alloc) { checks(1) = 1; } |
---|
103 | CatchAndThrow; |
---|
104 | |
---|
105 | Try { ColumnVector X(10); ColumnVector Y; X = 5; X = X - Y; } |
---|
106 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
107 | Catch(InternalException) { checks(1) = 1; } |
---|
108 | Catch(IncompatibleDimensionsException) { checks(10) = 0; } |
---|
109 | Catch(Bad_alloc) { checks(1) = 1; } |
---|
110 | CatchAndThrow; |
---|
111 | |
---|
112 | Try |
---|
113 | { |
---|
114 | UpperTriangularMatrix U(3); RowVector RV(3); RV = 10; |
---|
115 | U.Row(2) = RV; |
---|
116 | } |
---|
117 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
118 | Catch(InternalException) { checks(1) = 1; } |
---|
119 | Catch(ProgramException) { checks(11) = 0; } |
---|
120 | Catch(Bad_alloc) { checks(1) = 1; } |
---|
121 | CatchAndThrow; |
---|
122 | |
---|
123 | Try { DiagonalMatrix D(3); D << 12 << 13 << 14 << 15; } |
---|
124 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
125 | Catch(InternalException) { checks(1) = 1; } |
---|
126 | Catch(ProgramException) { checks(12) = 0; } |
---|
127 | CatchAndThrow; |
---|
128 | |
---|
129 | Try { ColumnVector D(3); D << 12 << 13; D << 1 << 2 << 3; } |
---|
130 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
131 | Catch(InternalException) { checks(1) = 1; } |
---|
132 | Catch(ProgramException) { checks(13) = 0; } |
---|
133 | CatchAndThrow; |
---|
134 | |
---|
135 | |
---|
136 | Try { { ColumnVector D(3); D << 12 << 13; } } |
---|
137 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
138 | Catch(InternalException) { checks(1) = 1; } |
---|
139 | Catch(ProgramException) { checks(14) = 0; } |
---|
140 | CatchAndThrow; |
---|
141 | |
---|
142 | Try { ColumnVector CV; ReSizeMatrix(CV); } |
---|
143 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
144 | Catch(InternalException) { checks(1) = 1; } |
---|
145 | Catch(VectorException) { checks(15) = 0; } |
---|
146 | CatchAndThrow; |
---|
147 | |
---|
148 | Try { RowVector RV(20); ReSizeMatrix(RV); } |
---|
149 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
150 | Catch(InternalException) { checks(1) = 1; } |
---|
151 | Catch(VectorException) { checks(16) = 0; } |
---|
152 | CatchAndThrow; |
---|
153 | |
---|
154 | Try |
---|
155 | { |
---|
156 | UpperTriangularMatrix U(10); U = 5; |
---|
157 | DiagonalMatrix D(10); D = 2; |
---|
158 | D += U; // illegal conversion |
---|
159 | } |
---|
160 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
161 | Catch(InternalException) { checks(1) = 1; } |
---|
162 | Catch(ProgramException) { checks(17) = 0; } |
---|
163 | CatchAndThrow; |
---|
164 | |
---|
165 | Try { Matrix A(2,3), B(2,3); if (A < B) A = B; } |
---|
166 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
167 | Catch(InternalException) { checks(1) = 1; } |
---|
168 | Catch(NotDefinedException) { checks(18) = 0; } |
---|
169 | CatchAndThrow; |
---|
170 | |
---|
171 | Try { SymmetricBandMatrix A(3,1); A = 1; A = A.Reverse(); } |
---|
172 | Catch(ConvergenceException) { checks(1) = 1; } |
---|
173 | Catch(InternalException) { checks(1) = 1; } |
---|
174 | Catch(NotDefinedException) { checks(19) = 0; } |
---|
175 | CatchAndThrow; |
---|
176 | |
---|
177 | Try |
---|
178 | { |
---|
179 | Matrix A(5,5); A = 1.0; |
---|
180 | UpperTriangularMatrix B(10); |
---|
181 | B.SubMatrix(3,7,3,7) = A; |
---|
182 | } |
---|
183 | Catch(ProgramException) { checks(20) = 0; } |
---|
184 | CatchAndThrow; |
---|
185 | |
---|
186 | Try { { RowVector D(1); D << 12 << 13; } } |
---|
187 | Catch(InternalException) { checks(1) = 1; } |
---|
188 | Catch(ProgramException) { checks(21) = 0; } |
---|
189 | CatchAndThrow; |
---|
190 | |
---|
191 | Try { { RowVector D(0); D << 12; } } |
---|
192 | Catch(InternalException) { checks(1) = 1; } |
---|
193 | Catch(ProgramException) { checks(22) = 0; } |
---|
194 | CatchAndThrow; |
---|
195 | |
---|
196 | Try { Matrix M(10,10); Matrix XM(3,3); M = 0.0; XM = M.i(); } |
---|
197 | Catch(SingularException) { checks(23) = 0; } |
---|
198 | CatchAll { checks(1) = 1; } |
---|
199 | |
---|
200 | Print(checks); |
---|
201 | Matrix RUStillThere1(10,20); RUStillThere1 = 1553; |
---|
202 | RUStillThere = RUStillThere - RUStillThere1; |
---|
203 | Print(RUStillThere); |
---|
204 | #endif |
---|
205 | |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | |
---|