1 | /* --- Programme de test des matrices carres speciales
|
---|
2 | --- This code is part of the SOPHYA library ---
|
---|
3 | (C) Univ. Paris-Sud (C) LAL-IN2P3/CNRS (C) IRFU-CEA
|
---|
4 | (C) R. Ansari, C.Magneville 2009
|
---|
5 |
|
---|
6 | Appel:
|
---|
7 | # Pour verification visuelle (/impression)
|
---|
8 | csh> tssqmx 0
|
---|
9 | # Test matrices diagonales (Rc=0 -> OK)
|
---|
10 | csh> tssqmx d
|
---|
11 | # Test matrices triangulaires (Rc=0 -> OK)
|
---|
12 | csh> tssqmx t
|
---|
13 | # Test matrices symmetriques (Rc=0 -> OK)
|
---|
14 | csh> tssqmx s
|
---|
15 | ---------------------------------------------------------- */
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 | #include <iostream>
|
---|
20 | #include <string>
|
---|
21 |
|
---|
22 | #include "trngmtx.h"
|
---|
23 | #include "diagmtx.h"
|
---|
24 | #include "symmtx.h"
|
---|
25 | #include "fiospsqmtx.h"
|
---|
26 | #include "tarrinit.h"
|
---|
27 |
|
---|
28 | using namespace std;
|
---|
29 | using namespace SOPHYA;
|
---|
30 |
|
---|
31 | // --- Declaration des fonctions de ce fichier
|
---|
32 | static int SSQM_Check0();
|
---|
33 | static int TriangMtxCheck(sa_size_t NR=7);
|
---|
34 | static int DiagMtxCheck(sa_size_t NR=7);
|
---|
35 | static int SymmMtxCheck(sa_size_t NR=7);
|
---|
36 |
|
---|
37 |
|
---|
38 | static int PrtLev = 0;
|
---|
39 | //-----------------------------------------------------------
|
---|
40 | //-----------------------------------------------------------
|
---|
41 | int main(int narg, char* arg[])
|
---|
42 | {
|
---|
43 | int rc = 0;
|
---|
44 | if(narg<2) {
|
---|
45 | cout << "Usage: tssqmx Action \n Action= 0/t/d/s [NR=7] [PrtLev=0] " << endl;
|
---|
46 | return 1;
|
---|
47 | }
|
---|
48 | sa_size_t NR = 7;
|
---|
49 | if (narg>2) NR = atoi(arg[2]);
|
---|
50 | if (narg>3) PrtLev = atoi(arg[3]);
|
---|
51 | try {
|
---|
52 | // appel enregistrement des handlers PPF (devra etre fait par l'initialiseur de TArray
|
---|
53 | SophyaInit();
|
---|
54 | cout << " ---- tssqmx : Test of Special Square Matrix classes ----- " << endl;
|
---|
55 | if (*arg[1] == 'd') rc = DiagMtxCheck(NR);
|
---|
56 | else if (*arg[1] == 't') rc = TriangMtxCheck(NR);
|
---|
57 | else if (*arg[1] == 's') rc = SymmMtxCheck(NR);
|
---|
58 | else rc = SSQM_Check0();
|
---|
59 | }
|
---|
60 | catch (PThrowable exc) {
|
---|
61 | cerr << " tssqmx.cc: catched Exception " << exc.Msg() << endl;
|
---|
62 | rc = 97;
|
---|
63 | }
|
---|
64 | catch (...) {
|
---|
65 | cerr << " tssqmx.cc: catched unknown (...) exception " << endl;
|
---|
66 | rc = 99;
|
---|
67 | }
|
---|
68 |
|
---|
69 | cout << " ---- End of tssqmx : Rc= " << rc << " ---- " << endl;
|
---|
70 | return rc;
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 | //-------------------------
|
---|
76 | // Fonction de test avec impression
|
---|
77 | static int SSQM_Check0()
|
---|
78 | {
|
---|
79 | cout << " ========== SSQM_Check0() =========== " << endl;
|
---|
80 | cout << "1- LowerTriangularMatrix<int_4> trmx(5) ..." << endl;
|
---|
81 | LowerTriangularMatrix<int_4> trmx(5);
|
---|
82 | cout << "2- trmx = 5 ..." << endl;
|
---|
83 | // int_4 c = 5;
|
---|
84 | trmx = 5;
|
---|
85 | // trmx.SetCst(6);
|
---|
86 | cout << "3- trmx += 3 ..." << endl;
|
---|
87 | trmx += 3;
|
---|
88 | cout << "4- cout << trmx , t2=trmx t2.print " << endl;
|
---|
89 | cout << trmx;
|
---|
90 | LowerTriangularMatrix<int_4> t2;
|
---|
91 | t2 = trmx;
|
---|
92 | t2.Print(cout, 10);
|
---|
93 |
|
---|
94 | cout << "5.a- tt = trmx + t2 " << endl;
|
---|
95 | LowerTriangularMatrix<int_4> tt;
|
---|
96 | tt = trmx + t2;
|
---|
97 | cout << tt ;
|
---|
98 | tt.Print(cout, 60);
|
---|
99 | cout << "5.b- tt2 = tt - 4*t2 " << endl;
|
---|
100 | LowerTriangularMatrix<int_4> tt2 = tt - 4*t2;
|
---|
101 | tt2.Print(cout, 60);
|
---|
102 |
|
---|
103 | cout << "6- LowerTriangularMatrix<r_4> rtt; rtt= RegularSequence(5.6, 0.2)" << endl;
|
---|
104 | LowerTriangularMatrix<r_4> rtt(7);
|
---|
105 | rtt= RegularSequence(5.6, 0.2);
|
---|
106 | rtt.Print(cout,60);
|
---|
107 |
|
---|
108 | cout << "11- diag = 16 " << endl;
|
---|
109 | DiagonalMatrix<int_4> diag(5), dmx(7);
|
---|
110 | diag = 16;
|
---|
111 | cout << diag;
|
---|
112 | diag.Print(cout);
|
---|
113 |
|
---|
114 | cout << "11.b- dmx = RegularSequence(1., 2.) " << endl;
|
---|
115 | dmx = RegularSequence(1., 2.);
|
---|
116 | dmx.Print(cout);
|
---|
117 | cout << "12- dd = diag*2+3 , dd2 = dd/5-diag/4+4 " << endl;
|
---|
118 | DiagonalMatrix<int_4> dd = diag*2+3;
|
---|
119 | dd.Print(cout);
|
---|
120 | DiagonalMatrix<int_4> dd2;
|
---|
121 | dd2 = dd/5-diag/4+4;
|
---|
122 | dd2.Print(cout);
|
---|
123 |
|
---|
124 | {
|
---|
125 | cout << "12- Writing dd , dd2 to POutPersist po(diagmtx.ppf) " << endl;
|
---|
126 | POutPersist po("diagmtx.ppf");
|
---|
127 | po << dd << dd2;
|
---|
128 | }
|
---|
129 | {
|
---|
130 | cout << "12.b- Reading rdd , rdd2 from PInPersist po(diagmtx.ppf) " << endl;
|
---|
131 | PInPersist pi("diagmtx.ppf");
|
---|
132 | DiagonalMatrix<int_4> rdd,rdd2;
|
---|
133 | pi >> rdd >> rdd2;
|
---|
134 | rdd.Print(cout);
|
---|
135 | rdd2.Print(cout);
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | cout << "21- Symmetric = RegularSequence " << endl;
|
---|
140 | SymmetricMatrix<int_4> sym(5);
|
---|
141 | sym = RegularSequence(1,2);
|
---|
142 | sym.Print(cout,-1);
|
---|
143 |
|
---|
144 | {
|
---|
145 | cout << "22- Writing sym to POutPersist po(symmtx.ppf) " << endl;
|
---|
146 | POutPersist po("symmtx.ppf");
|
---|
147 | po << sym ;
|
---|
148 | }
|
---|
149 | {
|
---|
150 | cout << "22.b- Reading rsym from PInPersist po(symmtx.ppf) " << endl;
|
---|
151 | PInPersist pi("symmtx.ppf");
|
---|
152 | SymmetricMatrix<int_4> rsym;
|
---|
153 | pi >> rsym;
|
---|
154 | rsym.Print(cout,-1);
|
---|
155 | }
|
---|
156 |
|
---|
157 | cout << "23: Matrix multiplication on SymmetricMatrix<r_8>" << endl;
|
---|
158 | SymmetricMatrix<r_8> tmxa(3), tmxb(3);
|
---|
159 | tmxa = RandomSequence(RandomSequence::Gaussian);
|
---|
160 | tmxb = RandomSequence(RandomSequence::Gaussian,3.);
|
---|
161 | TMatrix<r_8> mxd = tmxa * tmxb;
|
---|
162 | tmxa.Print(cout,-1);
|
---|
163 | tmxb.Print(cout,-1);
|
---|
164 | mxd.Print(cout,-1);
|
---|
165 |
|
---|
166 | return 0;
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | //-------------------------
|
---|
171 | // Fonction de test pour matrices triangulaires
|
---|
172 | static int TriangMtxCheck(sa_size_t NR)
|
---|
173 | {
|
---|
174 | cout << " ========== TriangMtxCheck() LowerTriangularMatrix<T> check - NR= " << NR
|
---|
175 | << " =========== " << endl;
|
---|
176 | int rc = 0;
|
---|
177 | //----- Test 1
|
---|
178 | cout << "1/ Test 1 : Element Access Check LowerTriangularMatrix<int_8>" << endl;
|
---|
179 | LowerTriangularMatrix<int_8> tmx(NR), tmx2(NR);
|
---|
180 | tmx2 = RegularSequence(5., 3.);
|
---|
181 | int_8 vv=5;
|
---|
182 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
183 | for (sa_size_t r=c; r<tmx.NRows(); r++) {
|
---|
184 | tmx(r,c) = vv; vv+=3;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | int nzz = 0;
|
---|
188 | for (sa_size_t r=0; r<tmx.NRows()-1; r++) {
|
---|
189 | for (sa_size_t c=r+1; c<tmx.NCols(); c++) {
|
---|
190 | tmx(r,c) = 4.5; if (tmx(r,c)!=0) nzz++;
|
---|
191 | }
|
---|
192 | }
|
---|
193 | if (nzz>0) {
|
---|
194 | cout << " !!! Test_1.a ERROR : nzz= " << nzz << endl;
|
---|
195 | rc += 1;
|
---|
196 | }
|
---|
197 | else cout << " ---> Test_1.a OK " << endl;
|
---|
198 |
|
---|
199 | LowerTriangularMatrix<int_8> td8 = tmx-tmx2;
|
---|
200 | int_8 min8, max8;
|
---|
201 | td8.MinMax(min8, max8);
|
---|
202 | if (PrtLev>2) {
|
---|
203 | cout << " LowerTriangularMatrix<int_8> tmx : " << endl;
|
---|
204 | tmx.Print(cout, -1);
|
---|
205 | cout << " LowerTriangularMatrix<int_8> td8=tmx-tmx2 : " << endl;
|
---|
206 | td8.Print(cout, -1);
|
---|
207 | }
|
---|
208 | if ((min8!=0)||(max8!=0)) {
|
---|
209 | cout << " !!! Test_1.b ERROR : diff::min=" << min8 << " diff::max=" << max8 << endl;
|
---|
210 | rc += 2;
|
---|
211 | }
|
---|
212 | else cout << " ---> Test_1.b OK " << endl;
|
---|
213 |
|
---|
214 | //----- Test 2
|
---|
215 | cout << "2/ Test 2 : Operator =, PPF write check LowerTriangularMatrix<int_8>" << endl;
|
---|
216 | {
|
---|
217 | LowerTriangularMatrix<int_8> ctmx;
|
---|
218 | ctmx = tmx;
|
---|
219 | POutPersist po("ttrngmtx.ppf");
|
---|
220 | po << ctmx;
|
---|
221 | }
|
---|
222 | {
|
---|
223 | PInPersist pi("ttrngmtx.ppf");
|
---|
224 | LowerTriangularMatrix<int_8> rtmx;
|
---|
225 | pi >> rtmx;
|
---|
226 | td8 = rtmx-tmx;
|
---|
227 | if (PrtLev>2) {
|
---|
228 | cout << " LowerTriangularMatrix<int_8> rtmx : " << endl;
|
---|
229 | rtmx.Print(cout, -1);
|
---|
230 | }
|
---|
231 | }
|
---|
232 | td8.MinMax(min8, max8);
|
---|
233 | if (PrtLev>2) {
|
---|
234 | cout << " LowerTriangularMatrix<int_8> td8=tmx-tmx2 : " << endl;
|
---|
235 | td8.Print(cout, -1);
|
---|
236 | }
|
---|
237 | if ((min8!=0)||(max8!=0)) {
|
---|
238 | cout << " !!! Test_2 ERROR : diff::min=" << min8 << " diff::max=" << max8 << endl;
|
---|
239 | rc += 4;
|
---|
240 | }
|
---|
241 | else cout << " ---> Test_2 OK " << endl;
|
---|
242 |
|
---|
243 |
|
---|
244 | //----- Test 3
|
---|
245 | cout << "3/ Test 3 : ConvertToStdmatrix() + operations on LowerTriangularMatrix<r_8>" << endl;
|
---|
246 | LowerTriangularMatrix<r_8> tdmx(NR);
|
---|
247 | tdmx = RandomSequence(RandomSequence::Gaussian);
|
---|
248 | TMatrix<r_8> dmx = tdmx.ConvertToStdMatrix();
|
---|
249 | int nerr = 0;
|
---|
250 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
251 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
252 | if (tdmx(r,c) != dmx(r,c)) nerr++;
|
---|
253 | }
|
---|
254 | }
|
---|
255 | if (nerr>0) {
|
---|
256 | cout << " !!! Test_3.a ERROR : nerr = " << nerr << endl;
|
---|
257 | rc += 8;
|
---|
258 | }
|
---|
259 | else cout << " ---> Test_3.a OK " << endl;
|
---|
260 |
|
---|
261 |
|
---|
262 | tdmx *= M_PI; tdmx -= 0.67;
|
---|
263 | dmx *= M_PI; dmx -= 0.67;
|
---|
264 | LowerTriangularMatrix<r_8> tdmx2(dmx);
|
---|
265 | LowerTriangularMatrix<r_8> tdd8 = tdmx-tdmx2;
|
---|
266 | r_8 mind, maxd;
|
---|
267 | tdd8.MinMax(mind, maxd);
|
---|
268 | if (PrtLev>2) {
|
---|
269 | cout << " LowerTriangularMatrix<r_8> tdmx : " << endl;
|
---|
270 | tdmx.Print(cout, -1);
|
---|
271 | cout << " LowerTriangularMatrix<int_8> tdd8=tdmx-tdmx2 : " << endl;
|
---|
272 | tdd8.Print(cout, -1);
|
---|
273 | }
|
---|
274 | if ((fabs(mind)>1.e-19)||(fabs(maxd)>1e-19)) {
|
---|
275 | cout << " !!! Test_3.b ERROR : diff::min=" << mind << " diff::max=" << maxd << endl;
|
---|
276 | rc += 16;
|
---|
277 | }
|
---|
278 | else cout << " ---> Test_3.b OK " << endl;
|
---|
279 |
|
---|
280 | LowerTriangularMatrix<r_8> tdmxa(NR);
|
---|
281 | tdmxa = RegularSequence(2.,3.);
|
---|
282 | TMatrix<r_8> dmxa = tdmxa.ConvertToStdMatrix();
|
---|
283 | LowerTriangularMatrix<r_8> tdmxb = (74.32*((5.89*tdmx-tdmxa)&&tdmxa)+14.5)/tdmx;
|
---|
284 | TMatrix<r_8> dmxb = (74.32*((5.89*dmx-dmxa)&&dmxa)+14.5)/dmx;
|
---|
285 | LowerTriangularMatrix<r_8> tdmxc(dmxb);
|
---|
286 | tdd8 = tdmxb-tdmxc;
|
---|
287 | tdd8.MinMax(mind, maxd);
|
---|
288 | if (PrtLev>2) {
|
---|
289 | cout << " LowerTriangularMatrix<r_8> tdmxb : " << endl;
|
---|
290 | tdmx.Print(cout, -1);
|
---|
291 | cout << " LowerTriangularMatrix<int_8> tdd8=tdmxb-tdmxc : " << endl;
|
---|
292 | tdd8.Print(cout, -1);
|
---|
293 | }
|
---|
294 | if ((fabs(mind)>1.e-19)||(fabs(maxd)>1e-19)) {
|
---|
295 | cout << " !!! Test_3.c ERROR : diff::min=" << mind << " diff::max=" << maxd << endl;
|
---|
296 | rc += 32;
|
---|
297 | }
|
---|
298 | else cout << " ---> Test_3.c OK " << endl;
|
---|
299 |
|
---|
300 | //----- Test 4
|
---|
301 | cout << "4/ Test 4 : Matrix multiplication on LowerTriangularMatrix<r_8>" << endl;
|
---|
302 | LowerTriangularMatrix<r_8> tmxa(NR), tmxb(NR);
|
---|
303 | tmxa = RandomSequence(RandomSequence::Gaussian);
|
---|
304 | tmxb = RandomSequence(RandomSequence::Gaussian,3.);
|
---|
305 | LowerTriangularMatrix<r_8> tmxc = tmxa * tmxb;
|
---|
306 | TMatrix<r_8> mxa = tmxa.ConvertToStdMatrix();
|
---|
307 | TMatrix<r_8> mxb = tmxb.ConvertToStdMatrix();
|
---|
308 | TMatrix<r_8> mxc = mxa * mxb;
|
---|
309 |
|
---|
310 | nerr = 0;
|
---|
311 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
312 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
313 | if (fabs(tmxc(r,c)-mxc(r,c))>1e-15) nerr++;
|
---|
314 | }
|
---|
315 | }
|
---|
316 | if (nerr>0) {
|
---|
317 | cout << " !!! Test_4.a ERROR : nerr = " << nerr << endl;
|
---|
318 | rc += 64;
|
---|
319 | }
|
---|
320 | else cout << " ---> Test_4.a OK " << endl;
|
---|
321 |
|
---|
322 | mxb = RandomSequence(RandomSequence::Gaussian, 9.);
|
---|
323 | TMatrix<r_8> mxd = tmxa*mxb;
|
---|
324 | mxc = mxa*mxb;
|
---|
325 | if (PrtLev>2) {
|
---|
326 | cout << " DiagonalMatrix<r_8> tmxa : " << endl;
|
---|
327 | tmxa.Print(cout, -1);
|
---|
328 | cout << " TMatrix<r_8> mxb : " << endl;
|
---|
329 | mxb.Print(cout, -1);
|
---|
330 | cout << " TMatrix<r_8> mxd=tmxa*mxb : " << endl;
|
---|
331 | mxd.Print(cout, -1);
|
---|
332 | }
|
---|
333 |
|
---|
334 | nerr = 0;
|
---|
335 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
336 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
337 | if (fabs(mxd(r,c)-mxc(r,c))>1e-15) nerr++;
|
---|
338 | }
|
---|
339 | }
|
---|
340 | if (nerr>0) {
|
---|
341 | cout << " !!! Test_4.b ERROR : nerr = " << nerr << endl;
|
---|
342 | rc += 128;
|
---|
343 | }
|
---|
344 | else cout << " ---> Test_4.b OK " << endl;
|
---|
345 |
|
---|
346 | mxd = mxb*tmxa;
|
---|
347 | mxc = mxb*mxa;
|
---|
348 | nerr = 0;
|
---|
349 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
350 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
351 | if (fabs(mxd(r,c)-mxc(r,c))>1e-15) nerr++;
|
---|
352 | }
|
---|
353 | }
|
---|
354 | if (nerr>0) {
|
---|
355 | cout << " !!! Test_4.c ERROR : nerr = " << nerr << endl;
|
---|
356 | rc += 256;
|
---|
357 | }
|
---|
358 | else cout << " ---> Test_4.c OK " << endl;
|
---|
359 |
|
---|
360 |
|
---|
361 | return rc;
|
---|
362 | }
|
---|
363 |
|
---|
364 | //-------------------------
|
---|
365 | // Fonction de test pour matrices diagonales
|
---|
366 | static int DiagMtxCheck(sa_size_t NR)
|
---|
367 | {
|
---|
368 | cout << " ========== DiagMtxCheck() DiagonalMatrix<T> check - NR= " << NR
|
---|
369 | << " =========== " << endl;
|
---|
370 | int rc = 0;
|
---|
371 | //----- Test 1
|
---|
372 | cout << "1/ Test 1 : Element Access Check DiagonalMatrix<int_8>" << endl;
|
---|
373 | DiagonalMatrix<int_8> tmx(NR), tmx2(NR);
|
---|
374 | tmx2 = RegularSequence(5., 3.);
|
---|
375 | int_8 vv=5;
|
---|
376 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
377 | tmx(r,r) = vv; vv+=3;
|
---|
378 | }
|
---|
379 | int nzz = 0;
|
---|
380 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
381 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
382 | if (r==c) continue;
|
---|
383 | tmx(r,c) = 4.5; if (tmx(r,c)!=0) nzz++;
|
---|
384 | }
|
---|
385 | }
|
---|
386 | if (nzz>0) {
|
---|
387 | cout << " !!! Test_1.a ERROR : nzz= " << nzz << endl;
|
---|
388 | rc += 1;
|
---|
389 | }
|
---|
390 | else cout << " ---> Test_1.a OK " << endl;
|
---|
391 |
|
---|
392 | DiagonalMatrix<int_8> td8 = tmx-tmx2;
|
---|
393 | int_8 min8, max8;
|
---|
394 | td8.MinMax(min8, max8);
|
---|
395 | if (PrtLev>2) {
|
---|
396 | cout << " DiagonalMatrix<int_8> tmx : " << endl;
|
---|
397 | tmx.Print(cout, -1);
|
---|
398 | cout << " DiagonalMatrix<int_8> td8=tmx-tmx2 : " << endl;
|
---|
399 | td8.Print(cout, -1);
|
---|
400 | }
|
---|
401 | if ((min8!=0)||(max8!=0)) {
|
---|
402 | cout << " !!! Test_1.b ERROR : diff::min=" << min8 << " diff::max=" << max8 << endl;
|
---|
403 | rc += 2;
|
---|
404 | }
|
---|
405 | else cout << " ---> Test_1.b OK " << endl;
|
---|
406 |
|
---|
407 | //----- Test 2
|
---|
408 | cout << "2/ Test 2 : Operator =, PPF write check DiagonalMatrix<int_8>" << endl;
|
---|
409 | {
|
---|
410 | DiagonalMatrix<int_8> ctmx;
|
---|
411 | ctmx = tmx;
|
---|
412 | POutPersist po("ttrngmtx.ppf");
|
---|
413 | po << ctmx;
|
---|
414 | }
|
---|
415 | {
|
---|
416 | PInPersist pi("ttrngmtx.ppf");
|
---|
417 | DiagonalMatrix<int_8> rtmx;
|
---|
418 | pi >> rtmx;
|
---|
419 | td8 = rtmx-tmx;
|
---|
420 | if (PrtLev>2) {
|
---|
421 | cout << " DiagonalMatrix<int_8> rtmx : " << endl;
|
---|
422 | rtmx.Print(cout, -1);
|
---|
423 | }
|
---|
424 | }
|
---|
425 | td8.MinMax(min8, max8);
|
---|
426 | if (PrtLev>2) {
|
---|
427 | cout << " DiagonalMatrix<int_8> td8=tmx-tmx2 : " << endl;
|
---|
428 | td8.Print(cout, -1);
|
---|
429 | }
|
---|
430 | if ((min8!=0)||(max8!=0)) {
|
---|
431 | cout << " !!! Test_2 ERROR : diff::min=" << min8 << " diff::max=" << max8 << endl;
|
---|
432 | rc += 4;
|
---|
433 | }
|
---|
434 | else cout << " ---> Test_2 OK " << endl;
|
---|
435 |
|
---|
436 |
|
---|
437 | //----- Test 3
|
---|
438 | cout << "3/ Test 3 : ConvertToStdmatrix() + operations on DiagonalMatrix<r_8>" << endl;
|
---|
439 | DiagonalMatrix<r_8> tdmx(NR);
|
---|
440 | tdmx = RandomSequence(RandomSequence::Gaussian);
|
---|
441 | TMatrix<r_8> dmx = tdmx.ConvertToStdMatrix();
|
---|
442 | int nerr = 0;
|
---|
443 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
444 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
445 | if (tdmx(r,c) != dmx(r,c)) nerr++;
|
---|
446 | }
|
---|
447 | }
|
---|
448 | if (nerr>0) {
|
---|
449 | cout << " !!! Test_3.a ERROR : nerr = " << nerr << endl;
|
---|
450 | rc += 8;
|
---|
451 | }
|
---|
452 | else cout << " ---> Test_3.a OK " << endl;
|
---|
453 |
|
---|
454 |
|
---|
455 | tdmx *= M_PI; tdmx -= 0.67;
|
---|
456 | dmx *= M_PI; dmx -= 0.67;
|
---|
457 | DiagonalMatrix<r_8> tdmx2(dmx);
|
---|
458 | DiagonalMatrix<r_8> tdd8 = tdmx-tdmx2;
|
---|
459 | r_8 mind, maxd;
|
---|
460 | tdd8.MinMax(mind, maxd);
|
---|
461 | if (PrtLev>2) {
|
---|
462 | cout << " DiagonalMatrix<r_8> tdmx : " << endl;
|
---|
463 | tdmx.Print(cout, -1);
|
---|
464 | cout << " DiagonalMatrix<int_8> tdd8=tdmx-tdmx2 : " << endl;
|
---|
465 | tdd8.Print(cout, -1);
|
---|
466 | }
|
---|
467 | if ((fabs(mind)>1.e-19)||(fabs(maxd)>1e-19)) {
|
---|
468 | cout << " !!! Test_3.b ERROR : diff::min=" << mind << " diff::max=" << maxd << endl;
|
---|
469 | rc += 16;
|
---|
470 | }
|
---|
471 | else cout << " ---> Test_3.b OK " << endl;
|
---|
472 |
|
---|
473 | DiagonalMatrix<r_8> tdmxa(NR);
|
---|
474 | tdmxa = RegularSequence(2.,3.);
|
---|
475 | TMatrix<r_8> dmxa = tdmxa.ConvertToStdMatrix();
|
---|
476 | DiagonalMatrix<r_8> tdmxb = (74.32*((5.89*tdmx-tdmxa)&&tdmxa)+14.5)/tdmx;
|
---|
477 | TMatrix<r_8> dmxb = (74.32*((5.89*dmx-dmxa)&&dmxa)+14.5)/dmx;
|
---|
478 | DiagonalMatrix<r_8> tdmxc(dmxb);
|
---|
479 | tdd8 = tdmxb-tdmxc;
|
---|
480 | tdd8.MinMax(mind, maxd);
|
---|
481 | if (PrtLev>2) {
|
---|
482 | cout << " DiagonalMatrix<r_8> tdmxb : " << endl;
|
---|
483 | tdmx.Print(cout, -1);
|
---|
484 | cout << " DiagonalMatrix<int_8> tdd8=tdmxb-tdmxc : " << endl;
|
---|
485 | tdd8.Print(cout, -1);
|
---|
486 | }
|
---|
487 | if ((fabs(mind)>1.e-19)||(fabs(maxd)>1e-19)) {
|
---|
488 | cout << " !!! Test_3.c ERROR : diff::min=" << mind << " diff::max=" << maxd << endl;
|
---|
489 | rc += 32;
|
---|
490 | }
|
---|
491 | else cout << " ---> Test_3.c OK " << endl;
|
---|
492 |
|
---|
493 | //----- Test 4
|
---|
494 | cout << "4/ Test 4 : Matrix multiplication on DiagonalMatrix<r_8>" << endl;
|
---|
495 | DiagonalMatrix<r_8> tmxa(NR), tmxb(NR);
|
---|
496 | tmxa = RandomSequence(RandomSequence::Gaussian);
|
---|
497 | tmxb = RandomSequence(RandomSequence::Gaussian,3.);
|
---|
498 | DiagonalMatrix<r_8> tmxc = tmxa * tmxb;
|
---|
499 | TMatrix<r_8> mxa = tmxa.ConvertToStdMatrix();
|
---|
500 | TMatrix<r_8> mxb = tmxb.ConvertToStdMatrix();
|
---|
501 | TMatrix<r_8> mxc = mxa * mxb;
|
---|
502 |
|
---|
503 | nerr = 0;
|
---|
504 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
505 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
506 | if (fabs(tmxc(r,c)-mxc(r,c))>1e-15) nerr++;
|
---|
507 | }
|
---|
508 | }
|
---|
509 | if (nerr>0) {
|
---|
510 | cout << " !!! Test_4.a ERROR : nerr = " << nerr << endl;
|
---|
511 | rc += 64;
|
---|
512 | }
|
---|
513 | else cout << " ---> Test_4.a OK " << endl;
|
---|
514 |
|
---|
515 | mxb = RandomSequence(RandomSequence::Gaussian, 9.);
|
---|
516 | TMatrix<r_8> mxd = tmxa*mxb;
|
---|
517 | mxc = mxa*mxb;
|
---|
518 | if (PrtLev>2) {
|
---|
519 | cout << " DiagonalMatrix<r_8> tmxa : " << endl;
|
---|
520 | tmxa.Print(cout, -1);
|
---|
521 | cout << " TMatrix<r_8> mxb : " << endl;
|
---|
522 | mxb.Print(cout, -1);
|
---|
523 | cout << " TMatrix<r_8> mxd=tmxa*mxb : " << endl;
|
---|
524 | mxd.Print(cout, -1);
|
---|
525 | }
|
---|
526 |
|
---|
527 | nerr = 0;
|
---|
528 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
529 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
530 | if (fabs(mxd(r,c)-mxc(r,c))>1e-15) nerr++;
|
---|
531 | }
|
---|
532 | }
|
---|
533 | if (nerr>0) {
|
---|
534 | cout << " !!! Test_4.b ERROR : nerr = " << nerr << endl;
|
---|
535 | rc += 128;
|
---|
536 | }
|
---|
537 | else cout << " ---> Test_4.b OK " << endl;
|
---|
538 |
|
---|
539 | mxd = mxb*tmxa;
|
---|
540 | mxc = mxb*mxa;
|
---|
541 | nerr = 0;
|
---|
542 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
543 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
544 | if (fabs(mxd(r,c)-mxc(r,c))>1e-15) nerr++;
|
---|
545 | }
|
---|
546 | }
|
---|
547 | if (nerr>0) {
|
---|
548 | cout << " !!! Test_4.c ERROR : nerr = " << nerr << endl;
|
---|
549 | rc += 256;
|
---|
550 | }
|
---|
551 | else cout << " ---> Test_4.c OK " << endl;
|
---|
552 |
|
---|
553 |
|
---|
554 | return rc;
|
---|
555 | }
|
---|
556 |
|
---|
557 | //-------------------------
|
---|
558 | // Fonction de test pour matrices diagonales
|
---|
559 | static int SymmMtxCheck(sa_size_t NR)
|
---|
560 | {
|
---|
561 | cout << " ========== SymmMtxCheck() SymmetricMatrix<T> check - NR= " << NR
|
---|
562 | << " =========== " << endl;
|
---|
563 | int rc = 0;
|
---|
564 | //----- Test 1
|
---|
565 | cout << "1/ Test 1 : Element Access Check SymmetricMatrix<int_8>" << endl;
|
---|
566 | SymmetricMatrix<int_8> tmx(NR), tmx2(NR);
|
---|
567 | tmx2 = RegularSequence(5., 3.);
|
---|
568 | int_8 vv=5;
|
---|
569 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
570 | for (sa_size_t r=c; r<tmx.NRows(); r++) {
|
---|
571 | tmx(r,c) = vv; vv+=3;
|
---|
572 | }
|
---|
573 | }
|
---|
574 | int nzz = 0;
|
---|
575 | for (sa_size_t r=0; r<tmx.NRows()-1; r++) {
|
---|
576 | for (sa_size_t c=r+1; c<tmx.NCols(); c++) {
|
---|
577 | if (tmx(r,c)!=tmx(c,r)) nzz++;
|
---|
578 | }
|
---|
579 | }
|
---|
580 | if (nzz>0) {
|
---|
581 | cout << " !!! Test_1.a ERROR : nzz= " << nzz << endl;
|
---|
582 | rc += 1;
|
---|
583 | }
|
---|
584 | else cout << " ---> Test_1.a OK " << endl;
|
---|
585 |
|
---|
586 | SymmetricMatrix<int_8> td8 = tmx-tmx2;
|
---|
587 | int_8 min8, max8;
|
---|
588 | td8.MinMax(min8, max8);
|
---|
589 | if (PrtLev>2) {
|
---|
590 | cout << " SymmetricMatrix<int_8> tmx : " << endl;
|
---|
591 | tmx.Print(cout, -1);
|
---|
592 | cout << " SymmetricMatrix<int_8> td8=tmx-tmx2 : " << endl;
|
---|
593 | td8.Print(cout, -1);
|
---|
594 | }
|
---|
595 | if ((min8!=0)||(max8!=0)) {
|
---|
596 | cout << " !!! Test_1.b ERROR : diff::min=" << min8 << " diff::max=" << max8 << endl;
|
---|
597 | rc += 2;
|
---|
598 | }
|
---|
599 | else cout << " ---> Test_1.b OK " << endl;
|
---|
600 |
|
---|
601 | //----- Test 2
|
---|
602 | cout << "2/ Test 2 : Operator =, PPF write check SymmetricMatrix<int_8>" << endl;
|
---|
603 | {
|
---|
604 | SymmetricMatrix<int_8> ctmx;
|
---|
605 | ctmx = tmx;
|
---|
606 | POutPersist po("ttrngmtx.ppf");
|
---|
607 | po << ctmx;
|
---|
608 | }
|
---|
609 | {
|
---|
610 | PInPersist pi("ttrngmtx.ppf");
|
---|
611 | SymmetricMatrix<int_8> rtmx;
|
---|
612 | pi >> rtmx;
|
---|
613 | td8 = rtmx-tmx;
|
---|
614 | if (PrtLev>2) {
|
---|
615 | cout << " SymmetricMatrix<int_8> rtmx : " << endl;
|
---|
616 | rtmx.Print(cout, -1);
|
---|
617 | }
|
---|
618 | }
|
---|
619 | td8.MinMax(min8, max8);
|
---|
620 | if (PrtLev>2) {
|
---|
621 | cout << " SymmetricMatrix<int_8> td8=tmx-tmx2 : " << endl;
|
---|
622 | td8.Print(cout, -1);
|
---|
623 | }
|
---|
624 | if ((min8!=0)||(max8!=0)) {
|
---|
625 | cout << " !!! Test_2 ERROR : diff::min=" << min8 << " diff::max=" << max8 << endl;
|
---|
626 | rc += 4;
|
---|
627 | }
|
---|
628 | else cout << " ---> Test_2 OK " << endl;
|
---|
629 |
|
---|
630 |
|
---|
631 | //----- Test 3
|
---|
632 | cout << "3/ Test 3 : ConvertToStdmatrix() + operations on SymmetricMatrix<r_8>" << endl;
|
---|
633 | SymmetricMatrix<r_8> tdmx(NR);
|
---|
634 | tdmx = RandomSequence(RandomSequence::Gaussian);
|
---|
635 | TMatrix<r_8> dmx = tdmx.ConvertToStdMatrix();
|
---|
636 | int nerr = 0;
|
---|
637 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
638 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
639 | if (tdmx(r,c) != dmx(r,c)) nerr++;
|
---|
640 | }
|
---|
641 | }
|
---|
642 | if (nerr>0) {
|
---|
643 | cout << " !!! Test_3.a ERROR : nerr = " << nerr << endl;
|
---|
644 | rc += 8;
|
---|
645 | }
|
---|
646 | else cout << " ---> Test_3.a OK " << endl;
|
---|
647 |
|
---|
648 |
|
---|
649 | tdmx *= M_PI; tdmx -= 0.67;
|
---|
650 | dmx *= M_PI; dmx -= 0.67;
|
---|
651 | SymmetricMatrix<r_8> tdmx2(dmx);
|
---|
652 | SymmetricMatrix<r_8> tdd8 = tdmx-tdmx2;
|
---|
653 | r_8 mind, maxd;
|
---|
654 | tdd8.MinMax(mind, maxd);
|
---|
655 | if (PrtLev>2) {
|
---|
656 | cout << " SymmetricMatrix<r_8> tdmx : " << endl;
|
---|
657 | tdmx.Print(cout, -1);
|
---|
658 | cout << " SymmetricMatrix<int_8> tdd8=tdmx-tdmx2 : " << endl;
|
---|
659 | tdd8.Print(cout, -1);
|
---|
660 | }
|
---|
661 | if ((fabs(mind)>1.e-19)||(fabs(maxd)>1e-19)) {
|
---|
662 | cout << " !!! Test_3.b ERROR : diff::min=" << mind << " diff::max=" << maxd << endl;
|
---|
663 | rc += 16;
|
---|
664 | }
|
---|
665 | else cout << " ---> Test_3.b OK " << endl;
|
---|
666 |
|
---|
667 | SymmetricMatrix<r_8> tdmxa(NR);
|
---|
668 | tdmxa = RegularSequence(2.,3.);
|
---|
669 | TMatrix<r_8> dmxa = tdmxa.ConvertToStdMatrix();
|
---|
670 | SymmetricMatrix<r_8> tdmxb = (74.32*((5.89*tdmx-tdmxa)&&tdmxa)+14.5)/tdmx;
|
---|
671 | TMatrix<r_8> dmxb = (74.32*((5.89*dmx-dmxa)&&dmxa)+14.5)/dmx;
|
---|
672 | SymmetricMatrix<r_8> tdmxc(dmxb);
|
---|
673 | tdd8 = tdmxb-tdmxc;
|
---|
674 | tdd8.MinMax(mind, maxd);
|
---|
675 | if (PrtLev>2) {
|
---|
676 | cout << " SymmetricMatrix<r_8> tdmxb : " << endl;
|
---|
677 | tdmx.Print(cout, -1);
|
---|
678 | cout << " SymmetricMatrix<int_8> tdd8=tdmxb-tdmxc : " << endl;
|
---|
679 | tdd8.Print(cout, -1);
|
---|
680 | }
|
---|
681 | if ((fabs(mind)>1.e-19)||(fabs(maxd)>1e-19)) {
|
---|
682 | cout << " !!! Test_3.c ERROR : diff::min=" << mind << " diff::max=" << maxd << endl;
|
---|
683 | rc += 32;
|
---|
684 | }
|
---|
685 | else cout << " ---> Test_3.c OK " << endl;
|
---|
686 |
|
---|
687 | //----- Test 4
|
---|
688 | cout << "4/ Test 4 : Matrix multiplication on SymmetricMatrix<r_8>" << endl;
|
---|
689 | SymmetricMatrix<r_8> tmxa(NR), tmxb(NR);
|
---|
690 | tmxa = RandomSequence(RandomSequence::Gaussian);
|
---|
691 | tmxb = RandomSequence(RandomSequence::Gaussian,3.);
|
---|
692 | TMatrix<r_8> mxd = tmxa * tmxb;
|
---|
693 | TMatrix<r_8> mxa = tmxa.ConvertToStdMatrix();
|
---|
694 | TMatrix<r_8> mxb = tmxb.ConvertToStdMatrix();
|
---|
695 | TMatrix<r_8> mxc = mxa * mxb;
|
---|
696 |
|
---|
697 | nerr = 0;
|
---|
698 | for (sa_size_t c=0; c<mxd.NCols(); c++) {
|
---|
699 | for (sa_size_t r=0; r<mxd.NRows(); r++) {
|
---|
700 | if (fabs(mxd(r,c)-mxc(r,c))>1e-15) nerr++;
|
---|
701 | }
|
---|
702 | }
|
---|
703 | if (nerr>0) {
|
---|
704 | cout << " !!! Test_4.a ERROR : nerr = " << nerr << endl;
|
---|
705 | rc += 64;
|
---|
706 | }
|
---|
707 | else cout << " ---> Test_4.a OK " << endl;
|
---|
708 |
|
---|
709 | mxb = RandomSequence(RandomSequence::Gaussian, 9.);
|
---|
710 | mxd = tmxa*mxb;
|
---|
711 | mxc = mxa*mxb;
|
---|
712 | if (PrtLev>2) {
|
---|
713 | cout << " SymmetricMatrix<r_8> tmxa : " << endl;
|
---|
714 | tmxa.Print(cout, -1);
|
---|
715 | cout << " TMatrix<r_8> mxb : " << endl;
|
---|
716 | mxb.Print(cout, -1);
|
---|
717 | cout << " TMatrix<r_8> mxd=tmxa*mxb : " << endl;
|
---|
718 | mxd.Print(cout, -1);
|
---|
719 | }
|
---|
720 |
|
---|
721 | nerr = 0;
|
---|
722 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
723 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
724 | if (fabs(mxd(r,c)-mxc(r,c))>1e-15) nerr++;
|
---|
725 | }
|
---|
726 | }
|
---|
727 | if (nerr>0) {
|
---|
728 | cout << " !!! Test_4.b ERROR : nerr = " << nerr << endl;
|
---|
729 | rc += 128;
|
---|
730 | }
|
---|
731 | else cout << " ---> Test_4.b OK " << endl;
|
---|
732 |
|
---|
733 | mxd = mxb*tmxa;
|
---|
734 | mxc = mxb*mxa;
|
---|
735 | nerr = 0;
|
---|
736 | for (sa_size_t c=0; c<tmx.NCols(); c++) {
|
---|
737 | for (sa_size_t r=0; r<tmx.NRows(); r++) {
|
---|
738 | if (fabs(mxd(r,c)-mxc(r,c))>1e-15) nerr++;
|
---|
739 | }
|
---|
740 | }
|
---|
741 | if (nerr>0) {
|
---|
742 | cout << " !!! Test_4.c ERROR : nerr = " << nerr << endl;
|
---|
743 | rc += 256;
|
---|
744 | }
|
---|
745 | else cout << " ---> Test_4.c OK " << endl;
|
---|
746 |
|
---|
747 |
|
---|
748 | return rc;
|
---|
749 | }
|
---|
750 |
|
---|