| [2615] | 1 | #include "sopnamsp.h" | 
|---|
| [1083] | 2 | #include "machdefs.h" | 
|---|
|  | 3 |  | 
|---|
|  | 4 | #include <math.h> | 
|---|
| [2322] | 5 | #include <iostream> | 
|---|
| [1083] | 6 |  | 
|---|
|  | 7 | #include "tarrinit.h" | 
|---|
|  | 8 | #include "array.h" | 
|---|
|  | 9 | #include "timing.h" | 
|---|
|  | 10 |  | 
|---|
| [2568] | 11 | /*  --------------------------------------------------------- */ | 
|---|
|  | 12 | /*  ---- Programme de test des operations et conversions ---  */ | 
|---|
|  | 13 | /*  ----    sur les TArray/TMatrix de SOPHYA    ----          */ | 
|---|
|  | 14 | /*  2000-2004      -   C. Magneville,  R. Ansari              */ | 
|---|
|  | 15 | /*  carrt -> Help/Usage                                       */ | 
|---|
|  | 16 | /*  Pour effectuer les tests :                                */ | 
|---|
|  | 17 | /* Conversions entre arr<int> et arr<float>                   */ | 
|---|
|  | 18 | /*  carrt  ac         -> Rc=0 OK                              */ | 
|---|
|  | 19 | /*  carrt  ace        -> Exception/Rc=9                       */ | 
|---|
|  | 20 | /*  carrt  oso        -> Rc=0 OK                              */ | 
|---|
|  | 21 | /*  carrt  odo        -> Rc=0 OK                              */ | 
|---|
|  | 22 | /*  --- carrt oso/odo NRow NCols  pour test grande tailles    */ | 
|---|
|  | 23 | /*  --------------------------------------------------------- */ | 
|---|
|  | 24 |  | 
|---|
|  | 25 | static int test_ac(bool fgszm=false); | 
|---|
| [1100] | 26 | static int test_oso(int r, int c); | 
|---|
|  | 27 | static int test_odo(int r, int c); | 
|---|
|  | 28 |  | 
|---|
|  | 29 | static int prtlev = 0; | 
|---|
| [1107] | 30 | static int nprt = 100; | 
|---|
| [1100] | 31 |  | 
|---|
|  | 32 | template <class T> | 
|---|
| [2581] | 33 | void getMinMax(TArray<T>& a, T& min, T& max) { a.MinMax(min, max); } | 
|---|
| [1100] | 34 |  | 
|---|
| [1083] | 35 | int main(int narg, char* arg[]) | 
|---|
|  | 36 | { | 
|---|
|  | 37 |  | 
|---|
|  | 38 | SophyaInit(); | 
|---|
|  | 39 | InitTim();   // Initializing the CPU timer | 
|---|
| [1100] | 40 |  | 
|---|
|  | 41 | if (narg < 2) { | 
|---|
| [2568] | 42 | cout << " carrt ac/ace/oso/odo [NRow=5] [NCols=10] [prtlev=0] [nprtmax=100] \n" | 
|---|
| [1100] | 43 | << "   ac : array conversion test   \n" | 
|---|
| [2568] | 44 | << "   ace : array conversion test + conversion with sizemismatch -> exception/rc=9  \n" | 
|---|
| [1100] | 45 | << "   oso : operation same memory organisation \n" | 
|---|
|  | 46 | << "   odo : operation different memory organisation \n" << endl; | 
|---|
| [2568] | 47 | return 1; | 
|---|
| [1100] | 48 | } | 
|---|
|  | 49 |  | 
|---|
|  | 50 | string opt = arg[1]; | 
|---|
|  | 51 | int nr = 5; | 
|---|
|  | 52 | int nc = 10; | 
|---|
|  | 53 | if (narg > 2) nr = atoi(arg[2]); | 
|---|
|  | 54 | if (narg > 3) nc = atoi(arg[3]); | 
|---|
|  | 55 | if (narg > 4) prtlev = atoi(arg[4]); | 
|---|
|  | 56 | if (narg > 5) nprt = atoi(arg[5]); | 
|---|
|  | 57 |  | 
|---|
| [2578] | 58 | BaseArray::SetMaxPrint(nprt); | 
|---|
| [2568] | 59 | int rc = 0; | 
|---|
| [1100] | 60 | PrtTim(" Start of Test "); | 
|---|
| [1083] | 61 | try { | 
|---|
| [2568] | 62 | if (opt == "ac") rc = test_ac(false); | 
|---|
|  | 63 | else if (opt == "ace") rc = test_ac(true); | 
|---|
|  | 64 | else if (opt == "oso") rc = test_oso(nr, nc); | 
|---|
|  | 65 | else if (opt == "odo") rc = test_odo(nr, nc); | 
|---|
| [1100] | 66 | } | 
|---|
|  | 67 | catch (PThrowable & exc) { | 
|---|
|  | 68 | cerr << " catched Exception " << exc.Msg() << endl; | 
|---|
| [2568] | 69 | rc = 9; | 
|---|
| [1100] | 70 | } | 
|---|
|  | 71 | catch (...) { | 
|---|
|  | 72 | cerr << " catched unknown (...) exception " << endl; | 
|---|
|  | 73 | } | 
|---|
|  | 74 |  | 
|---|
|  | 75 | PrtTim(" End of Test "); | 
|---|
| [2568] | 76 | cout << " ----- End of carrt - Rc= " << rc << " ----- " << endl; | 
|---|
|  | 77 | if (rc > 255) rc = 255; | 
|---|
|  | 78 | return rc; | 
|---|
| [1100] | 79 | } | 
|---|
|  | 80 |  | 
|---|
|  | 81 |  | 
|---|
| [2568] | 82 | int test_ac(bool fgszm) | 
|---|
| [1100] | 83 | { | 
|---|
| [2568] | 84 | cout << "\n -----> Testing TArray Conversion <---- " << endl; | 
|---|
|  | 85 | int rc = 0; | 
|---|
|  | 86 | int_4 min, max; | 
|---|
|  | 87 | TArray<int_4> ia(7,5),iac,iad; | 
|---|
|  | 88 | ia = RegularSequence(10., 2.); | 
|---|
|  | 89 | TArray<r_4> ra(7,5); | 
|---|
|  | 90 | ra = ia; | 
|---|
|  | 91 | if (prtlev>0) | 
|---|
|  | 92 | cout << " ra = ia(= RegularSequence(10., 2.)) = \n " << ra << endl; | 
|---|
|  | 93 | iac = ra; | 
|---|
|  | 94 | iad = iac-ia; | 
|---|
|  | 95 | getMinMax(iad, min, max); | 
|---|
|  | 96 | if ((min != 0) || (max != 0)) { | 
|---|
|  | 97 | cout << "(1) !!! ERROR ra(7,5)=ia(7,5)  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 98 | rc += 1; | 
|---|
|  | 99 | } | 
|---|
|  | 100 | else cout << "(1) OK  ra(7,5)=ia(7,5)  OK " << endl; | 
|---|
|  | 101 |  | 
|---|
|  | 102 | TArray<r_4> rb(5,3); | 
|---|
|  | 103 | rb =  RegularSequence(20., .5); | 
|---|
|  | 104 | TMatrix<int_4> mx(3,5); | 
|---|
|  | 105 | TMatrix<int_4> mxc(3,5); | 
|---|
|  | 106 | mxc = RegularSequence(20., .5); | 
|---|
|  | 107 | if (prtlev>0) | 
|---|
|  | 108 | cout << " TArray<r_4> rb(5,3); rb =  RegularSequence(20., .5); rb : " << rb << endl; | 
|---|
|  | 109 | mx = rb; | 
|---|
|  | 110 | if (prtlev>0) | 
|---|
|  | 111 | cout << " TMatrix<int_4> mx(3,5);       mx = rb;  mx: " << mx << endl; | 
|---|
|  | 112 | TMatrix<int_4> mxd = mxc-mx; | 
|---|
|  | 113 | getMinMax(mxd, min, max); | 
|---|
|  | 114 | if ((min != 0) || (max != 0)) { | 
|---|
|  | 115 | cout << "(2) !!! ERROR mx<int>(5,3)=rb<r_4>(5,3)  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 116 | rc += 2; | 
|---|
|  | 117 | } | 
|---|
|  | 118 | else cout << "(2) OK  mx<int>(5,3)=rb<r_4>(5,3)  OK " << endl; | 
|---|
|  | 119 |  | 
|---|
|  | 120 | TArray<r_4> rcv(10); | 
|---|
|  | 121 | rcv = 3.1415; | 
|---|
|  | 122 | TMatrix<r_8> mx2(rcv); | 
|---|
|  | 123 | if (prtlev>0) | 
|---|
|  | 124 | cout << "   TArray<r_4> rcv(10) = 3.1415 , TMatrix<r_8> mx2(rc)=rcv : " << mx2 << endl; | 
|---|
|  | 125 | TMatrix<int_4> mx2d = mx2-3.1415; | 
|---|
|  | 126 | getMinMax(mxd, min, max); | 
|---|
|  | 127 | if ((min != 0) || (max != 0)) { | 
|---|
|  | 128 | cout << "(3) !!! ERROR mx2<r_8>(10)=rcv<r_4>(10)  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 129 | rc += 4; | 
|---|
|  | 130 | } | 
|---|
|  | 131 | else cout << "(3) OK  mx2<r_8>(10)=rcv<r_4>(10)  OK " << endl; | 
|---|
|  | 132 | if (fgszm) { | 
|---|
|  | 133 | TMatrix<int_4> mx3(3,5); | 
|---|
|  | 134 | cout << "(4) Trying  TMatrix<int_4> mx3(3,5);  mx3 = rcv(10); ?? -> Exception " << endl; | 
|---|
|  | 135 | mx3 = rcv; | 
|---|
|  | 136 | } | 
|---|
|  | 137 | return(rc); | 
|---|
| [1100] | 138 | } | 
|---|
|  | 139 |  | 
|---|
|  | 140 | int test_oso(int nr, int nc) | 
|---|
|  | 141 | { | 
|---|
|  | 142 | cout << "\n -----> Testing TArray operation TArray<int_4>(nx=" << nr << ",ny=" | 
|---|
| [2568] | 143 | << nc << " ) " << endl; | 
|---|
|  | 144 | cout << " -----> OSO (Same Mem. Mapping) Same memory mapping (default) for all arrays" << endl; | 
|---|
| [1100] | 145 |  | 
|---|
|  | 146 | int rc = 0; | 
|---|
|  | 147 | int min,max; | 
|---|
|  | 148 |  | 
|---|
|  | 149 | TArray<int_4> a(nr,nc); | 
|---|
|  | 150 | a = 20; | 
|---|
|  | 151 | TArray<int_4> b(nr,nc); | 
|---|
|  | 152 | b = 9; | 
|---|
|  | 153 | if (prtlev > 0) { | 
|---|
|  | 154 | cout << " A = \n " << a << endl; | 
|---|
|  | 155 | cout << " B = \n " << b << endl; | 
|---|
| [1083] | 156 | } | 
|---|
|  | 157 |  | 
|---|
| [2568] | 158 | TArray<int_4> ar; | 
|---|
|  | 159 | ar = a+2; | 
|---|
|  | 160 | if (prtlev > 0) | 
|---|
|  | 161 | cout << "(1) AR = A+2=  " << ar << endl; | 
|---|
|  | 162 | getMinMax(ar, min, max); | 
|---|
|  | 163 | if ((min != 22) || (max != 22)) { | 
|---|
|  | 164 | cout << "(1) !!! ERROR Test AR=A+2  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 165 | rc += 1; | 
|---|
|  | 166 | } | 
|---|
|  | 167 | else cout << "(1) OK   Test AR=A+2  OK " << endl; | 
|---|
|  | 168 |  | 
|---|
|  | 169 | ar = 28-a; | 
|---|
|  | 170 | if (prtlev > 0) | 
|---|
|  | 171 | cout << "(2) AR = 28-A=  " << ar << endl; | 
|---|
|  | 172 | getMinMax(ar, min, max); | 
|---|
|  | 173 | if ((min != 8) || (max != 8)) { | 
|---|
|  | 174 | cout << "(2) !!! ERROR Test AR=28-A  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 175 | rc += 2; | 
|---|
|  | 176 | } | 
|---|
|  | 177 | else cout << "(2) OK   Test AR=28-A  OK " << endl; | 
|---|
|  | 178 |  | 
|---|
|  | 179 | ar = a*3; | 
|---|
|  | 180 | if (prtlev > 0) | 
|---|
|  | 181 | cout << "(3) AR = A*3=  " << ar << endl; | 
|---|
|  | 182 | getMinMax(ar, min, max); | 
|---|
|  | 183 | if ((min != 60) || (max != 60)) { | 
|---|
|  | 184 | cout << "(3) !!! ERROR Test AR=A*3  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 185 | rc += 4; | 
|---|
|  | 186 | } | 
|---|
|  | 187 | else cout << "(3) OK   Test AR=A*3  OK " << endl; | 
|---|
|  | 188 |  | 
|---|
|  | 189 | ar = a/5; | 
|---|
|  | 190 | if (prtlev > 0) | 
|---|
|  | 191 | cout << "(4) AR = A/5=  " << ar << endl; | 
|---|
|  | 192 | getMinMax(ar, min, max); | 
|---|
|  | 193 | if ((min != 4) || (max != 4)) { | 
|---|
|  | 194 | cout << "(4) !!! ERROR Test AR=A/5  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 195 | rc += 8; | 
|---|
|  | 196 | } | 
|---|
|  | 197 | else cout << "(4) OK   Test AR=A/5  OK " << endl; | 
|---|
|  | 198 |  | 
|---|
|  | 199 | ar = 140/a; | 
|---|
|  | 200 | if (prtlev > 0) | 
|---|
|  | 201 | cout << "(5) AR = 140/A= \n " << ar << endl; | 
|---|
|  | 202 | getMinMax(ar, min, max); | 
|---|
|  | 203 | if ((min != 7) || (max != 7)) { | 
|---|
|  | 204 | cout << "(5) !!! ERROR Test AR=140/A  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 205 | rc += 16; | 
|---|
|  | 206 | } | 
|---|
|  | 207 | else cout << "(5) OK   Test AR=140/A  OK " << endl; | 
|---|
|  | 208 |  | 
|---|
|  | 209 | ar -= 3; | 
|---|
|  | 210 | if (prtlev > 0) | 
|---|
|  | 211 | cout << "(6) AR -= 3  " << ar << endl; | 
|---|
|  | 212 | getMinMax(ar, min, max); | 
|---|
|  | 213 | if ((min != 4) || (max != 4)) { | 
|---|
|  | 214 | cout << "(6) !!! ERROR Test AR-=3  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 215 | rc += 32; | 
|---|
|  | 216 | } | 
|---|
|  | 217 | else cout << "(6) OK   Test AR-=3  OK " << endl; | 
|---|
|  | 218 |  | 
|---|
|  | 219 |  | 
|---|
|  | 220 | TArray<int_4> c = a-2*b; | 
|---|
|  | 221 | if (prtlev > 0) | 
|---|
|  | 222 | cout << "(7) C = A-2*B=  " << c << endl; | 
|---|
| [1100] | 223 | getMinMax(c, min, max); | 
|---|
|  | 224 | if ((min != 2) || (max != 2)) { | 
|---|
| [2568] | 225 | cout << "(7) !!! ERROR Test C=A+2*B  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 226 | rc += 64; | 
|---|
| [1100] | 227 | } | 
|---|
| [2568] | 228 | else cout << "(7) OK   Test C=A+2*B  OK " << endl; | 
|---|
| [1100] | 229 |  | 
|---|
| [2578] | 230 | (a*4+1).DivElt(b,c); | 
|---|
| [2568] | 231 | if (prtlev > 0) cout << "(8) C = (A*4+1)/B = " << c << endl; | 
|---|
| [1100] | 232 | getMinMax(c, min, max); | 
|---|
|  | 233 | if ((min != 9) || (max != 9)) { | 
|---|
| [2568] | 234 | cout << "(8) !!! ERROR Test C = (A*4+1)/B  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 235 | rc += 128; | 
|---|
| [1100] | 236 | } | 
|---|
| [2568] | 237 | else cout << "(8) OK   Test C = (A*4+1)/B ((DivElt) OK " << endl; | 
|---|
| [1100] | 238 |  | 
|---|
| [1107] | 239 | a = RegularSequence(1, 1); | 
|---|
|  | 240 | b = RegularSequence(nr*nc, -1); | 
|---|
|  | 241 | c = (a*2)+(b*2); | 
|---|
|  | 242 | if (prtlev > 0) { | 
|---|
| [2568] | 243 | cout << "(9) A =  " << a << endl; | 
|---|
|  | 244 | cout << "(9) B =  " << b << endl; | 
|---|
|  | 245 | cout << "(9) C = 2A-2*B=  " << c << endl; | 
|---|
| [1107] | 246 | } | 
|---|
|  | 247 | c /= (nr*nc+1); | 
|---|
|  | 248 | getMinMax(c, min, max); | 
|---|
|  | 249 | if ((min != 2) || (max != 2)) { | 
|---|
| [2568] | 250 | cout << "(9) !!! ERROR Test C=2A+2*B  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 251 | rc += 256; | 
|---|
| [1107] | 252 | } | 
|---|
| [2568] | 253 | else cout << "(9) OK   Test C=2A+2*B  OK " << endl; | 
|---|
| [2582] | 254 |  | 
|---|
|  | 255 | a = 10; | 
|---|
|  | 256 | b = 4; | 
|---|
|  | 257 | c = 3*a-2*b; | 
|---|
|  | 258 | if (prtlev > 0)  cout << "(10) A=10, B=4, C = 3*A-2*B = " << c << endl; | 
|---|
|  | 259 | getMinMax(c, min, max); | 
|---|
|  | 260 | if ((min != 22) || (max != 22)) { | 
|---|
|  | 261 | cout << "(10) !!! ERROR Test C = 3*A-2*B  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 262 | rc += 512; | 
|---|
|  | 263 | } | 
|---|
|  | 264 | else cout << "(10) OK   Test C = 3*A-2*B  OK " << endl; | 
|---|
|  | 265 |  | 
|---|
|  | 266 | c = 3*a+2*b; | 
|---|
|  | 267 | if (prtlev > 0)  cout << "(11) A=10, B=4, C = 3*A+2*B = " << c << endl; | 
|---|
|  | 268 | getMinMax(c, min, max); | 
|---|
|  | 269 | if ((min != 38) || (max != 38)) { | 
|---|
|  | 270 | cout << "(11) !!! ERROR Test C = 3*A+2*B  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 271 | rc += 512; | 
|---|
|  | 272 | } | 
|---|
|  | 273 | else cout << "(11) OK   Test C = 3*A+2*B  OK " << endl; | 
|---|
|  | 274 |  | 
|---|
|  | 275 | a.MulElt(b+2,c); | 
|---|
|  | 276 | if (prtlev > 0)  cout << "(12) A=10, B=4, a.MulElt(b+2,c) = " << c << endl; | 
|---|
|  | 277 | getMinMax(c, min, max); | 
|---|
|  | 278 | if ((min != 60) || (max != 60)) { | 
|---|
|  | 279 | cout << "(12) !!! ERROR Test a.MulElt(b+2,c) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 280 | rc += 1024; | 
|---|
|  | 281 | } | 
|---|
|  | 282 | else cout << "(12) OK   Test A.MulElt(B+2,C)  OK " << endl; | 
|---|
|  | 283 |  | 
|---|
|  | 284 | (3*a).DivElt(b+2,c); | 
|---|
|  | 285 | if (prtlev > 0)  cout << "(13) A=10, B=4, (3*a).DivElt(b+2,c) C = " << c << endl; | 
|---|
|  | 286 | getMinMax(c, min, max); | 
|---|
|  | 287 | if ((min != 5) || (max != 5)) { | 
|---|
|  | 288 | cout << "(13) !!! ERROR Test (3*a).DivElt(b+2,c) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 289 | rc += 1024; | 
|---|
|  | 290 | } | 
|---|
|  | 291 | else cout << "(13) OK  Test (3*A).DivElt(B+2,C)  OK " << endl; | 
|---|
| [1107] | 292 |  | 
|---|
| [2586] | 293 | a = 3; | 
|---|
|  | 294 | b = 2; | 
|---|
|  | 295 | int_4 sc = a.ScalarProduct(b); | 
|---|
|  | 296 | if (prtlev > 0)  cout << "(14) A=3, B=3, a.ScalarProduct(b)= " << sc << endl; | 
|---|
|  | 297 | if (sc != nr*nc*6)   { | 
|---|
|  | 298 | cout << "(14) !!! ERROR Test  a.ScalarProduct(b) sc " << sc << " !=" << nr*nc*6 << endl; | 
|---|
|  | 299 | rc += 2048; | 
|---|
|  | 300 | } | 
|---|
|  | 301 | else cout << "(14) OK  Test a.ScalarProduct(b)  OK " << endl; | 
|---|
|  | 302 |  | 
|---|
|  | 303 | TMatrix<int_4> mx(nr, nc), mxc(nr,nc); | 
|---|
|  | 304 | for(int ir=0; ir<nr; ir++) | 
|---|
|  | 305 | for(int ic=0; ic<nc; ic++) mxc(ir, ic) = ir*1000+ic*6; | 
|---|
|  | 306 | if (prtlev > 0)  cout << "(15) mx.Row()/Column() operations MXC=" << mxc << endl; | 
|---|
|  | 307 |  | 
|---|
|  | 308 | TVector<int_4> cv(nr), rv(nc, BaseArray::RowVector); | 
|---|
|  | 309 | cv = RegularSequence(0, 1); | 
|---|
|  | 310 | rv = RegularSequence(0, 1); | 
|---|
|  | 311 | for(int ir=0; ir<nr; ir++)  { | 
|---|
|  | 312 | mx.Row(ir) = rv*3; | 
|---|
|  | 313 | mx.Row(ir) *= 2; | 
|---|
|  | 314 | } | 
|---|
|  | 315 | for(int ic=0; ic<nc; ic++)  { | 
|---|
|  | 316 | mx.Column(ic) += cv*1000; | 
|---|
|  | 317 | } | 
|---|
|  | 318 | TMatrix<int_4> mxd = mx-mxc; | 
|---|
|  | 319 | if (prtlev > 0)  { | 
|---|
|  | 320 | cout << "(15)  MX=" << mx << endl; | 
|---|
|  | 321 | cout << "(15)  MXD=" << mxd << endl; | 
|---|
|  | 322 | } | 
|---|
|  | 323 | getMinMax(mxd, min, max); | 
|---|
|  | 324 | if ((min != 0) || (max != 0)) { | 
|---|
|  | 325 | cout << "(15) !!! ERROR Test mx.Row()/Column() operations Min=" << min << " Max=" << max << endl; | 
|---|
|  | 326 | rc += 8192; | 
|---|
|  | 327 | } | 
|---|
|  | 328 | else cout << "(15) OK  Test mx.Row()/Column() operations  OK " << endl; | 
|---|
|  | 329 |  | 
|---|
|  | 330 | a = RegularSequence(1, 1); | 
|---|
|  | 331 | b = -a; | 
|---|
|  | 332 | c = a+b; | 
|---|
|  | 333 | if (prtlev > 0) { | 
|---|
|  | 334 | cout << "(16) A =  " << a << endl; | 
|---|
|  | 335 | cout << "(16) B =  ((? == -A)" << b << endl; | 
|---|
|  | 336 | cout << "(16) C = A+B  " << c << endl; | 
|---|
|  | 337 | } | 
|---|
|  | 338 | getMinMax(c, min, max); | 
|---|
|  | 339 | if ((min != 0) || (max != 0)) { | 
|---|
|  | 340 | cout << "(16) !!! ERROR Test B=-A  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 341 | rc += 256; | 
|---|
|  | 342 | } | 
|---|
|  | 343 | else cout << "(16) OK   Test B=-A  OK " << endl; | 
|---|
|  | 344 |  | 
|---|
| [1100] | 345 | return(rc); | 
|---|
| [1083] | 346 | } | 
|---|
| [1100] | 347 |  | 
|---|
|  | 348 | int test_odo(int nr, int nc) | 
|---|
|  | 349 | { | 
|---|
|  | 350 | cout << "\n -----> Testing TMatrix operation TMatrix<r_4>(nr=" << nr << ",nc=" | 
|---|
| [2568] | 351 | << nc << " ) " << endl; | 
|---|
| [2586] | 352 | cout << " --> ODO (Diff. Mem. Mapping) A,CC: CMemoryMapping AR,B,C: FortranMemoryMapping" << endl; | 
|---|
| [1100] | 353 |  | 
|---|
| [1102] | 354 | int rc = 0; | 
|---|
| [1100] | 355 | r_4 min,max; | 
|---|
|  | 356 |  | 
|---|
|  | 357 | TMatrix<r_4> a(nr,nc,BaseArray::CMemoryMapping); | 
|---|
|  | 358 | a = 20; | 
|---|
|  | 359 | TMatrix<r_4> b(nr,nc,BaseArray::FortranMemoryMapping); | 
|---|
|  | 360 | b = 9; | 
|---|
|  | 361 |  | 
|---|
| [2568] | 362 | TMatrix<r_4> ar(nr,nc,BaseArray::FortranMemoryMapping); | 
|---|
|  | 363 |  | 
|---|
| [1100] | 364 | if (prtlev > 0) { | 
|---|
|  | 365 | cout << " A = \n " << a << endl; | 
|---|
|  | 366 | cout << " B = \n " << b << endl; | 
|---|
|  | 367 | } | 
|---|
| [2568] | 368 |  | 
|---|
|  | 369 | a.AddCst(2.,ar); | 
|---|
|  | 370 | if (prtlev > 0) | 
|---|
|  | 371 | cout << "(1) AR = A+2 : a.AddCst(2,ar) : " << ar << endl; | 
|---|
|  | 372 | getMinMax(ar, min, max); | 
|---|
|  | 373 | if ((fabs(min-22.) > 0.0001) || (fabs(max-22.) > 0.0001)) { | 
|---|
|  | 374 | cout << "(1) !!! ERROR Test AR=A+2  a.AddCst(2,ar)   Min=" << min << " Max=" << max << endl; | 
|---|
|  | 375 | rc += 1; | 
|---|
|  | 376 | } | 
|---|
|  | 377 | else cout << "(1) OK   Test AR=A+2 a.AddCst(2,ar)  OK " << endl; | 
|---|
|  | 378 |  | 
|---|
|  | 379 | a.SubCst(28.,ar,true); | 
|---|
|  | 380 | if (prtlev > 0) | 
|---|
|  | 381 | cout << "(2) AR = 28-A : a.SubCst(28,ar,true) :  " << ar << endl; | 
|---|
|  | 382 | getMinMax(ar, min, max); | 
|---|
|  | 383 | if ((fabs(min-8.) > 0.0001) || (fabs(max-8.) > 0.0001)) { | 
|---|
|  | 384 | cout << "(2) !!! ERROR Test AR=28-A  a.SubCst(28,ar,true) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 385 | rc += 2; | 
|---|
|  | 386 | } | 
|---|
|  | 387 | else cout << "(2) OK   Test AR=28-A  a.SubCst(28,ar,true) OK " << endl; | 
|---|
|  | 388 |  | 
|---|
|  | 389 | a.MulCst(3.,ar); | 
|---|
|  | 390 | if (prtlev > 0) | 
|---|
|  | 391 | cout << "(3) AR = A*3= a.MulCst(3,ar)  " << ar << endl; | 
|---|
|  | 392 | getMinMax(ar, min, max); | 
|---|
|  | 393 | if ((fabs(min-60.) > 0.0001) || (fabs(max-60.) > 0.0001)) { | 
|---|
|  | 394 | cout << "(3) !!! ERROR Test AR=A*3  a.MulCst(3,ar) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 395 | rc += 4; | 
|---|
|  | 396 | } | 
|---|
|  | 397 | else cout << "(3) OK   Test AR=A*3  a.MulCst(3,ar) OK " << endl; | 
|---|
|  | 398 |  | 
|---|
|  | 399 | a.DivCst(5.,ar); | 
|---|
|  | 400 | if (prtlev > 0) | 
|---|
|  | 401 | cout << "(4) AR = A/5= a.DivCst(5,ar) : " << ar << endl; | 
|---|
|  | 402 | getMinMax(ar, min, max); | 
|---|
|  | 403 | if ((fabs(min-4.) > 0.0001) || (fabs(max-4.) > 0.0001)) { | 
|---|
|  | 404 | cout << "(4) !!! ERROR Test AR=A/5  a.DivCst(5,ar) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 405 | rc += 8; | 
|---|
|  | 406 | } | 
|---|
|  | 407 | else cout << "(4) OK   Test AR=A/5  a.DivCst(5,ar) OK " << endl; | 
|---|
|  | 408 |  | 
|---|
|  | 409 | a.DivCst(140.,ar,true); | 
|---|
|  | 410 | if (prtlev > 0) | 
|---|
|  | 411 | cout << "(5) AR = 140/A= a.DivCst(140.,ar,true) : " << ar << endl; | 
|---|
|  | 412 | getMinMax(ar, min, max); | 
|---|
|  | 413 | if ((fabs(min-7.) > 0.0001) || (fabs(max-7.) > 0.0001)) { | 
|---|
|  | 414 | cout << "(5) !!! ERROR Test AR=140/A  a.DivCst(140.,ar,true) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 415 | rc += 16; | 
|---|
|  | 416 | } | 
|---|
|  | 417 | else cout << "(5) OK   Test AR=140/A  a.DivCst(140.,ar,true) OK " << endl; | 
|---|
|  | 418 |  | 
|---|
|  | 419 | ar -= 3.; | 
|---|
|  | 420 | if (prtlev > 0) | 
|---|
|  | 421 | cout << "(6) AR -= 3 " << ar << endl; | 
|---|
|  | 422 | getMinMax(ar, min, max); | 
|---|
|  | 423 | if ((min != 4) || (max != 4)) { | 
|---|
|  | 424 | cout << "(6) !!! ERROR Test AR-=3  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 425 | rc += 32; | 
|---|
|  | 426 | } | 
|---|
|  | 427 | else cout << "(6) OK   Test AR-=3  OK " << endl; | 
|---|
|  | 428 |  | 
|---|
|  | 429 | TMatrix<r_4> c(nr,nc,BaseArray::FortranMemoryMapping); | 
|---|
| [1100] | 430 | c = a-(b*2.0f); | 
|---|
| [2568] | 431 | if (prtlev > 0) cout << "(7) C = A-2*B=  " << c << endl; | 
|---|
| [1100] | 432 |  | 
|---|
|  | 433 | getMinMax(c, min, max); | 
|---|
|  | 434 | if ((fabs(min-2.) > 0.0001) || (fabs(max-2.) > 0.0001)) { | 
|---|
| [2568] | 435 | cout << "(7) !!! ERROR Test C=A+2*B  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 436 | rc += 64; | 
|---|
| [1100] | 437 | } | 
|---|
| [2568] | 438 | else cout << "(7) OK   Test C=A+2*B  OK " << endl; | 
|---|
| [1100] | 439 |  | 
|---|
| [2578] | 440 | (a*4.0f+5.5f).DivElt(b,c); | 
|---|
| [2568] | 441 | if (prtlev > 0) cout << "(8) C = (A*4+12)/B = " << c << endl; | 
|---|
| [1100] | 442 | getMinMax(c, min, max); | 
|---|
|  | 443 | if ((fabs(min-9.5) > 0.0001) || (fabs(max-9.5) > 0.0001)) { | 
|---|
| [2568] | 444 | cout << "(8) !!! ERROR Test C = (A*4+12)/B  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 445 | rc += 128; | 
|---|
| [1100] | 446 | } | 
|---|
| [2568] | 447 | else cout << "(8) OK   Test C = (A*4+12)/B  OK " << endl; | 
|---|
| [1107] | 448 |  | 
|---|
|  | 449 | a = RegularSequence(1, 1); | 
|---|
|  | 450 | b = RegularSequence(nr*nc, -1); | 
|---|
|  | 451 | c = (a*2.f)+(b*2.f); | 
|---|
|  | 452 | if (prtlev > 0) { | 
|---|
| [2568] | 453 | cout << "(9) A =  " << a << endl; | 
|---|
|  | 454 | cout << "(9) B =  " << b << endl; | 
|---|
|  | 455 | cout << "(9) C = 2A-2*B= " << c << endl; | 
|---|
| [1107] | 456 | } | 
|---|
|  | 457 | c /= (nr*nc+1); | 
|---|
|  | 458 | getMinMax(c, min, max); | 
|---|
|  | 459 | if ((fabs(min-2.) > 0.0001) || (fabs(max-2.) > 0.0001)) { | 
|---|
| [2582] | 460 | cout << "(9) !!! ERROR Test C=2A+2*B  Min=" << min << " Max=" << max << endl; | 
|---|
| [2568] | 461 | rc += 256; | 
|---|
| [1107] | 462 | } | 
|---|
| [2568] | 463 | else cout << "(9) OK   Test3 C=2A+2*B  OK " << endl; | 
|---|
| [1107] | 464 |  | 
|---|
| [2582] | 465 | // ---------------------- | 
|---|
|  | 466 | // Operation de type array +-*/ array | 
|---|
|  | 467 |  | 
|---|
| [2586] | 468 | a = 10.; | 
|---|
|  | 469 | b = 4.; | 
|---|
| [2582] | 470 |  | 
|---|
|  | 471 | (3.f*a).SubElt(2.f*b,c); | 
|---|
|  | 472 | if (prtlev > 0)  cout << "(10) A=10, B=4, (3*a).SubElt(2*b,c)  C=" << c << endl; | 
|---|
|  | 473 | getMinMax(c, min, max); | 
|---|
|  | 474 | if ((fabs(min-22.) > 0.0001) || (fabs(max-22.) > 0.0001)) { | 
|---|
|  | 475 | cout << "(10) !!! ERROR Test (3*a).SubElt(2*b,c)  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 476 | rc += 512; | 
|---|
|  | 477 | } | 
|---|
|  | 478 | else cout << "(10) OK   Test (3*a).SubElt(2.*b,c)  OK " << endl; | 
|---|
|  | 479 |  | 
|---|
|  | 480 | (3.f*a).AddElt(2.f*b,c); | 
|---|
|  | 481 | if (prtlev > 0)  cout << "(11) A=10, B=4, (3*a).AddElt(2*b,c) C= " << c << endl; | 
|---|
|  | 482 | getMinMax(c, min, max); | 
|---|
|  | 483 | if ((fabs(min-38.) > 0.0001) || (fabs(max-38.) > 0.0001)) { | 
|---|
|  | 484 | cout << "(11) !!! ERROR Test (3*A).AddElt(2.*B,C)  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 485 | rc += 512; | 
|---|
|  | 486 | } | 
|---|
|  | 487 | else cout << "(11) OK   Test (3*a).AddElt(2*b,c) OK " << endl; | 
|---|
|  | 488 |  | 
|---|
|  | 489 | a.MulElt(b+2.f,c); | 
|---|
|  | 490 | if (prtlev > 0)  cout << "(12) A=10, B=4, a.MulElt(b+2,c) = " << c << endl; | 
|---|
|  | 491 | getMinMax(c, min, max); | 
|---|
|  | 492 | if ((fabs(min-60.) > 0.0001) || (fabs(max-60.) > 0.0001)) { | 
|---|
|  | 493 | cout << "(12) !!! ERROR Test a.MulElt(b+2,c) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 494 | rc += 1024; | 
|---|
|  | 495 | } | 
|---|
|  | 496 | else cout << "(12) OK   Test A.MulElt(B+2,C)  OK " << endl; | 
|---|
|  | 497 |  | 
|---|
|  | 498 | (3.f*a).DivElt(b+2.f,c); | 
|---|
|  | 499 | if (prtlev > 0)  cout << "(13) A=10, B=4, (3*a).DivElt(b+2,c) C = " << c << endl; | 
|---|
|  | 500 | getMinMax(c, min, max); | 
|---|
|  | 501 | if ((fabs(min-5.) > 0.0001) || (fabs(max-5.) > 0.0001)) { | 
|---|
|  | 502 | cout << "(13) !!! ERROR Test (3*a).DivElt(b+2,c) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 503 | rc += 1024; | 
|---|
|  | 504 | } | 
|---|
|  | 505 | else cout << "(13) OK  Test (3*A).DivElt(B+2,C)  OK " << endl; | 
|---|
|  | 506 |  | 
|---|
|  | 507 | TMatrix<r_4> cc(nr,nc,BaseArray::CMemoryMapping); | 
|---|
|  | 508 |  | 
|---|
|  | 509 | (3.f*a).SubElt(2.f*b,cc); | 
|---|
|  | 510 | if (prtlev > 0)  cout << "(14) A=10, B=4, (3*a).SubElt(2*b,cc)  " << cc << endl; | 
|---|
|  | 511 | getMinMax(cc, min, max); | 
|---|
|  | 512 | if ((fabs(min-22.) > 0.0001) || (fabs(max-22.) > 0.0001)) { | 
|---|
|  | 513 | cout << "(14) !!! ERROR Test (3*a).SubElt(2*b,cc)  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 514 | rc += 2048; | 
|---|
|  | 515 | } | 
|---|
|  | 516 | else cout << "(14) OK   Test (3*A).SubElt(2*B,CC)  OK " << endl; | 
|---|
|  | 517 |  | 
|---|
|  | 518 |  | 
|---|
|  | 519 | (3.f*a).AddElt(2.f*b,cc); | 
|---|
|  | 520 | if (prtlev > 0)  cout << "(15) A=10, B=4, (3*a).AddElt(2*b,cc) CC= " << cc << endl; | 
|---|
|  | 521 | getMinMax(cc, min, max); | 
|---|
|  | 522 | if ((fabs(min-38.) > 0.0001) || (fabs(max-38.) > 0.0001)) { | 
|---|
|  | 523 | cout << "(15) !!! ERROR Test (3*a).AddElt(2*b,c)  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 524 | rc += 4096; | 
|---|
|  | 525 | } | 
|---|
|  | 526 | else cout << "(15) OK   Test (3*A).AddElt(2*B,CC) OK " << endl; | 
|---|
|  | 527 |  | 
|---|
|  | 528 | a.MulElt(b+2.f,cc); | 
|---|
|  | 529 | if (prtlev > 0)  cout << "(16) A=10, B=4, a.MulElt(b+2,c) = " << cc << endl; | 
|---|
|  | 530 | getMinMax(cc, min, max); | 
|---|
|  | 531 | if ((fabs(min-60.) > 0.0001) || (fabs(max-60.) > 0.0001)) { | 
|---|
|  | 532 | cout << "(16) !!! ERROR Test A.MulElt(B+2,CC) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 533 | rc += 8192; | 
|---|
|  | 534 | } | 
|---|
|  | 535 | else cout << "(16) OK   Test A.MulElt(B+2,C)  OK " << endl; | 
|---|
|  | 536 |  | 
|---|
|  | 537 | (3.f*a).DivElt(b+2.f,cc); | 
|---|
|  | 538 | if (prtlev > 0)  cout << "(17) A=10, B=4, (3*a).DivElt(b+2,cc) C = " << cc << endl; | 
|---|
|  | 539 | getMinMax(cc, min, max); | 
|---|
|  | 540 | if ((fabs(min-5.) > 0.0001) || (fabs(max-5.) > 0.0001)) { | 
|---|
|  | 541 | cout << "(17) !!! ERROR Test (3*a).DivElt(b+2,c) Min=" << min << " Max=" << max << endl; | 
|---|
|  | 542 | rc += 16384; | 
|---|
|  | 543 | } | 
|---|
|  | 544 | else cout << "(17) OK  Test (3*A).DivElt(B+2,CC)  OK " << endl; | 
|---|
| [2586] | 545 |  | 
|---|
|  | 546 | a = 3.1; | 
|---|
|  | 547 | b = -2.2; | 
|---|
|  | 548 | r_4 sc = a.ScalarProduct(b); | 
|---|
|  | 549 | r_4 sce = 0.; | 
|---|
|  | 550 | for(int kkk=0; kkk<nr*nc; kkk++) sce += -2.2*3.1; | 
|---|
|  | 551 | if (prtlev > 0)  cout << "(18) A=3, B=3, a.ScalarProduct(b)= " << sc << endl; | 
|---|
|  | 552 | sc -= sce; | 
|---|
|  | 553 | if ((fabs(sc) > 0.00001) || (fabs(sc) > 0.00001)) { | 
|---|
|  | 554 | cout << "(18) !!! ERROR Test  a.ScalarProduct(b) sc-" <<  sce | 
|---|
|  | 555 | << " = " << sc << endl; | 
|---|
|  | 556 | rc += 32768; | 
|---|
|  | 557 | } | 
|---|
|  | 558 | else cout << "(18) OK  Test a.ScalarProduct(b)  OK " << endl; | 
|---|
|  | 559 |  | 
|---|
|  | 560 | TMatrix<r_4> mx(nr, nc), mxc(nr,nc,BaseArray::FortranMemoryMapping); | 
|---|
|  | 561 | for(int ir=0; ir<nr; ir++) | 
|---|
|  | 562 | for(int ic=0; ic<nc; ic++) mxc(ir, ic) = ir*1000+ic*6; | 
|---|
|  | 563 | if (prtlev > 0)  cout << "(19) mx.Row()/Column() operations MXC=" << mxc << endl; | 
|---|
|  | 564 |  | 
|---|
|  | 565 | TVector<r_4> cv(nr), rv(nc, BaseArray::RowVector, BaseArray::FortranMemoryMapping); | 
|---|
|  | 566 | cv = RegularSequence(0, 1); | 
|---|
|  | 567 | rv = RegularSequence(0, 1); | 
|---|
|  | 568 | for(int ir=0; ir<nr; ir++)  { | 
|---|
|  | 569 | mx.Row(ir) = rv*3.f; | 
|---|
|  | 570 | mx.Row(ir) *= 2.f; | 
|---|
|  | 571 | } | 
|---|
|  | 572 | for(int ic=0; ic<nc; ic++)  { | 
|---|
|  | 573 | mx.Column(ic) += cv*1000.f; | 
|---|
|  | 574 | } | 
|---|
|  | 575 | TMatrix<r_4> mxd = mx-mxc; | 
|---|
|  | 576 | if (prtlev > 0)  { | 
|---|
|  | 577 | cout << "(19)  MX=" << mx << endl; | 
|---|
|  | 578 | cout << "(19)  MXD=" << mxd << endl; | 
|---|
|  | 579 | } | 
|---|
|  | 580 | getMinMax(mxd, min, max); | 
|---|
|  | 581 | if ((fabs(min) > 0.0001) || (fabs(max) > 0.0001)) { | 
|---|
|  | 582 | cout << "(19) !!! ERROR Test mx.Row()/Column() operations Min=" << min << " Max=" << max << endl; | 
|---|
|  | 583 | rc += 65536; | 
|---|
|  | 584 | } | 
|---|
|  | 585 | else cout << "(19) OK  Test mx.Row()/Column() operations  OK " << endl; | 
|---|
|  | 586 |  | 
|---|
|  | 587 | a = RegularSequence(3.14, 1.3); | 
|---|
|  | 588 | b = -a; | 
|---|
|  | 589 | c = a+b; | 
|---|
|  | 590 | if (prtlev > 0) { | 
|---|
|  | 591 | cout << "(20) A =  " << a << endl; | 
|---|
|  | 592 | cout << "(20) B =  ((? == -A)" << b << endl; | 
|---|
|  | 593 | cout << "(16) C = A+B  " << c << endl; | 
|---|
|  | 594 | } | 
|---|
|  | 595 | getMinMax(c, min, max); | 
|---|
|  | 596 | if ((fabs(min) > 0.0001) || (fabs(max) > 0.0001)) { | 
|---|
|  | 597 | cout << "(20) !!! ERROR Test B=-A  Min=" << min << " Max=" << max << endl; | 
|---|
|  | 598 | rc += 131072; | 
|---|
|  | 599 | } | 
|---|
|  | 600 | else cout << "(20) OK   Test B=-A  OK " << endl; | 
|---|
|  | 601 |  | 
|---|
| [1100] | 602 | return(rc); | 
|---|
|  | 603 |  | 
|---|
| [2586] | 604 | return(rc); | 
|---|
|  | 605 |  | 
|---|
| [1100] | 606 | } | 
|---|