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