Changeset 2568 in Sophya for trunk/SophyaProg


Ignore:
Timestamp:
Jul 27, 2004, 1:42:45 PM (21 years ago)
Author:
ansari
Message:

Ajout/ameliorations test des operations sur TArray ds carrt.cc - Reza 27 Juillet 2004

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/Tests/carrt.cc

    r2322 r2568  
    88#include "timing.h"
    99
    10 static int test_ac();
     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
     24static int test_ac(bool fgszm=false);
    1125static int test_oso(int r, int c);
    1226static int test_odo(int r, int c);
     
    1630
    1731template <class T>
    18 void getMinMax(TArray<T>& a, T& min, T& max)
    19 {
    20   min = a[0];
    21   max = a[0];
    22   for(uint_8 k=1; k<a.Size(); k++) {
    23     if (a[k]<min)  min = a[k];
    24     else if (a[k]>max)  max = a[k];
    25   }
    26 }
     32void getMinMax(TArray<T>& a, T& min, T& max) { return a.MinMax(min, max); }
    2733
    2834int main(int narg, char* arg[])
     
    3339
    3440  if (narg < 2) {
    35     cout << " carrt ac/oso/odo [NRow=5] [NCols=10] [prtlev=0] [nprtmax=100] \n"
     41    cout << " carrt ac/ace/oso/odo [NRow=5] [NCols=10] [prtlev=0] [nprtmax=100] \n"
    3642         << "   ac : array conversion test   \n"
     43         << "   ace : array conversion test + conversion with sizemismatch -> exception/rc=9  \n"
    3744         << "   oso : operation same memory organisation \n"
    3845         << "   odo : operation different memory organisation \n" << endl;
    39     exit(0);
     46    return 1;
    4047  }
    4148
     
    4956
    5057  BaseArray::SetMaxPrint(nprt, prtlev);
    51  
     58  int rc = 0;
    5259  PrtTim(" Start of Test ");
    5360  try {
    54     if (opt == "ac") test_ac();
    55     else if (opt == "oso") test_oso(nr, nc);
    56     else if (opt == "odo") test_odo(nr, nc);
     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);
    5765  }
    5866  catch (PThrowable & exc) {
    5967    cerr << " catched Exception " << exc.Msg() << endl;
     68    rc = 9;
    6069  } 
    6170  catch (...) {
     
    6473
    6574  PrtTim(" End of Test ");
    66 
     75  cout << " ----- End of carrt - Rc= " << rc << " ----- " << endl;
     76  if (rc > 255) rc = 255;
     77  return rc;
    6778}
    6879
    6980
    70 int test_ac()
     81int test_ac(bool fgszm)
    7182{
    72     cout << "\n -----> Testing TArray Conversion <---- " << endl;
    73      TArray<int_4> ia(7,5);   
    74      ia = RegularSequence(10., 2.);
    75      TArray<r_4> ra(7,5);   
    76      ra = ia;
    77      cout << " ra = ia(= RegularSequence(10., 2.)) = \n " << ra << endl;
    78      TArray<r_4> rb(5,3);
    79      rb =  RegularSequence(20., .5); 
    80      TMatrix<int_4> mx(3,5);
    81      cout << " TArray<r_4> rb(5,3); rb =  RegularSequence(20., .5); rb : " << endl;
    82      cout << rb << endl;
    83      mx = rb;
    84      cout << " TMatrix<int_4> mx(3,5);       mx = rb;  mx: " << endl;
    85      cout << mx << endl;
    86      TArray<r_4> rc(10);
    87      rc = 3.1415;
    88      TMatrix<r_8> mx2(rc);
    89      cout << "   TArray<r_4> rc(10) = 3.1415 , TMatrix<r_8> mx2(rc) rc : " << endl;
    90      cout << mx2 << endl;
    91      TMatrix<int_4> mx3(3,5);
    92      cout << " Trying      TMatrix<int_4> mx3(3,5);  mx3 = rc; ?? " << endl;
    93      mx3 = rc;
    94      return(0);
     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);
    95137}
    96138
     
    98140{
    99141  cout << "\n -----> Testing TArray operation TArray<int_4>(nx=" << nr << ",ny="
    100        << nc << " )" << endl;
     142       << nc << " ) " << endl;
     143  cout << " -----> OSO (Same Mem. Mapping) Same memory mapping (default) for all arrays" << endl;
    101144
    102145  int rc = 0;
     
    107150  TArray<int_4> b(nr,nc);
    108151  b = 9;
    109   TArray<int_4> c = a-2*b;
    110 
    111152  if (prtlev > 0) {
    112153    cout << " A = \n " << a << endl;
    113154    cout << " B = \n " << b << endl;
    114     cout << " C = A-2*B= \n " << c << endl;
    115   }
    116 
     155  }
     156
     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;
    117222  getMinMax(c, min, max);
    118223  if ((min != 2) || (max != 2)) {
    119     cout << "!!! ERROR Test C=A+2*B  Min=" << min << " Max=" << max << endl;
    120     rc += 1;
    121   }
    122   else cout << " OK   Test C=A+2*B  OK " << endl;
     224    cout << "(7) !!! ERROR Test C=A+2*B  Min=" << min << " Max=" << max << endl;
     225    rc += 64;
     226  }
     227  else cout << "(7) OK   Test C=A+2*B  OK " << endl;
    123228
    124229  c = (a*4+1).DivElt(b);
    125   if (prtlev > 0) cout << " C = (A*4+1)/B = \n" << c << endl;
     230  if (prtlev > 0) cout << "(8) C = (A*4+1)/B = " << c << endl;
    126231  getMinMax(c, min, max);
    127232  if ((min != 9) || (max != 9)) {
    128     cout << "!!! ERROR Test C = (A*4+1)/B  Min=" << min << " Max=" << max << endl;
    129     rc += 2;
    130   }
    131   else cout << " OK   Test C = (A*4+1)/B OK " << endl;
     233    cout << "(8) !!! ERROR Test C = (A*4+1)/B  Min=" << min << " Max=" << max << endl;
     234    rc += 128;
     235  }
     236  else cout << "(8) OK   Test C = (A*4+1)/B ((DivElt) OK " << endl;
    132237 
    133238  a = RegularSequence(1, 1);
     
    135240  c = (a*2)+(b*2);
    136241  if (prtlev > 0) {
    137     cout << " A = \n " << a << endl;
    138     cout << " B = \n " << b << endl;
    139     cout << " C = 2A-2*B= \n " << c << endl;
     242    cout << "(9) A = " << a << endl;
     243    cout << "(9) B = " << b << endl;
     244    cout << "(9) C = 2A-2*B= " << c << endl;
    140245  }
    141246  c /= (nr*nc+1);
    142247  getMinMax(c, min, max);
    143248  if ((min != 2) || (max != 2)) {
    144     cout << "!!! ERROR Test3 C=2A+2*B  Min=" << min << " Max=" << max << endl;
    145     rc += 1;
    146   }
    147   else cout << " OK   Test3 C=2A+2*B  OK " << endl;
     249    cout << "(9) !!! ERROR Test C=2A+2*B  Min=" << min << " Max=" << max << endl;
     250    rc += 256;
     251  }
     252  else cout << "(9) OK   Test C=2A+2*B  OK " << endl;
    148253 
    149254  return(rc);
     
    153258{
    154259  cout << "\n -----> Testing TMatrix operation TMatrix<r_4>(nr=" << nr << ",nc="
    155        << nc << " )" << endl;
    156   cout << "   A CMemoryMapping  - B FortranMemoryMapping " << endl;
     260       << nc << " ) " << endl;
     261  cout << " ----> ODO (Diff. Mem. Mapping) A: CMemoryMapping AR,B,C: FortranMemoryMapping" << endl;
    157262
    158263  int rc = 0;
     
    163268  TMatrix<r_4> b(nr,nc,BaseArray::FortranMemoryMapping);
    164269  b = 9;
    165   TMatrix<r_4> c(nr,nc,BaseArray::CMemoryMapping);
     270
     271  TMatrix<r_4> ar(nr,nc,BaseArray::FortranMemoryMapping);
    166272
    167273  if (prtlev > 0) {
     
    169275    cout << " B = \n " << b << endl;
    170276  }
     277
     278  a.AddCst(2.,ar);
     279  if (prtlev > 0)
     280    cout << "(1) AR = A+2 : a.AddCst(2,ar) : " << ar << endl;
     281  getMinMax(ar, min, max);
     282  if ((fabs(min-22.) > 0.0001) || (fabs(max-22.) > 0.0001)) {
     283    cout << "(1) !!! ERROR Test AR=A+2  a.AddCst(2,ar)   Min=" << min << " Max=" << max << endl;
     284    rc += 1;
     285  }
     286  else cout << "(1) OK   Test AR=A+2 a.AddCst(2,ar)  OK " << endl;
     287
     288  a.SubCst(28.,ar,true);
     289  if (prtlev > 0)
     290    cout << "(2) AR = 28-A : a.SubCst(28,ar,true) :  " << ar << endl;
     291  getMinMax(ar, min, max);
     292  if ((fabs(min-8.) > 0.0001) || (fabs(max-8.) > 0.0001)) {
     293    cout << "(2) !!! ERROR Test AR=28-A  a.SubCst(28,ar,true) Min=" << min << " Max=" << max << endl;
     294    rc += 2;
     295  }
     296  else cout << "(2) OK   Test AR=28-A  a.SubCst(28,ar,true) OK " << endl;
     297 
     298  a.MulCst(3.,ar);
     299  if (prtlev > 0)
     300    cout << "(3) AR = A*3= a.MulCst(3,ar)  " << ar << endl;
     301  getMinMax(ar, min, max);
     302  if ((fabs(min-60.) > 0.0001) || (fabs(max-60.) > 0.0001)) {
     303    cout << "(3) !!! ERROR Test AR=A*3  a.MulCst(3,ar) Min=" << min << " Max=" << max << endl;
     304    rc += 4;
     305  }
     306  else cout << "(3) OK   Test AR=A*3  a.MulCst(3,ar) OK " << endl;
     307
     308  a.DivCst(5.,ar);
     309  if (prtlev > 0)
     310    cout << "(4) AR = A/5= a.DivCst(5,ar) : " << ar << endl;
     311  getMinMax(ar, min, max);
     312  if ((fabs(min-4.) > 0.0001) || (fabs(max-4.) > 0.0001)) {
     313    cout << "(4) !!! ERROR Test AR=A/5  a.DivCst(5,ar) Min=" << min << " Max=" << max << endl;
     314    rc += 8;
     315  }
     316  else cout << "(4) OK   Test AR=A/5  a.DivCst(5,ar) OK " << endl;
     317
     318  a.DivCst(140.,ar,true);
     319  if (prtlev > 0)
     320    cout << "(5) AR = 140/A= a.DivCst(140.,ar,true) : " << ar << endl;
     321  getMinMax(ar, min, max);
     322  if ((fabs(min-7.) > 0.0001) || (fabs(max-7.) > 0.0001)) {
     323    cout << "(5) !!! ERROR Test AR=140/A  a.DivCst(140.,ar,true) Min=" << min << " Max=" << max << endl;
     324    rc += 16;
     325  }
     326  else cout << "(5) OK   Test AR=140/A  a.DivCst(140.,ar,true) OK " << endl;
     327
     328  ar -= 3.; 
     329  if (prtlev > 0)
     330    cout << "(6) AR -= 3 " << ar << endl;
     331  getMinMax(ar, min, max);
     332  if ((min != 4) || (max != 4)) {
     333    cout << "(6) !!! ERROR Test AR-=3  Min=" << min << " Max=" << max << endl;
     334    rc += 32;
     335  }
     336  else cout << "(6) OK   Test AR-=3  OK " << endl;
     337
     338  TMatrix<r_4> c(nr,nc,BaseArray::FortranMemoryMapping);
    171339  c = a-(b*2.0f);
    172   if (prtlev > 0) cout << " C = A-2*B= \n " << c << endl;
     340  if (prtlev > 0) cout << "(7) C = A-2*B= " << c << endl;
    173341
    174342  getMinMax(c, min, max);
    175343  if ((fabs(min-2.) > 0.0001) || (fabs(max-2.) > 0.0001)) {
    176     cout << "!!! ERROR Test C=A+2*B  Min=" << min << " Max=" << max << endl;
    177     rc += 1;
    178   }
    179   else cout << " OK   Test C=A+2*B  OK " << endl;
     344    cout << "(7) !!! ERROR Test C=A+2*B  Min=" << min << " Max=" << max << endl;
     345    rc += 64;
     346  }
     347  else cout << "(7) OK   Test C=A+2*B  OK " << endl;
    180348
    181349  c = (a*4.0f+5.5f).DivElt(b);
    182   if (prtlev > 0) cout << " C = (A*4+12)/B = \n" << c << endl;
     350  if (prtlev > 0) cout << "(8) C = (A*4+12)/B = " << c << endl;
    183351  getMinMax(c, min, max);
    184352  if ((fabs(min-9.5) > 0.0001) || (fabs(max-9.5) > 0.0001)) {
    185     cout << "!!! ERROR Test C = (A*4+12)/B  Min=" << min << " Max=" << max << endl;
    186     rc += 2;
    187   }
    188   else cout << " OK   Test C = (A*4+12)/B  OK " << endl;
     353    cout << "(8) !!! ERROR Test C = (A*4+12)/B  Min=" << min << " Max=" << max << endl;
     354    rc += 128;
     355  }
     356  else cout << "(8) OK   Test C = (A*4+12)/B  OK " << endl;
    189357
    190358  a = RegularSequence(1, 1);
     
    192360  c = (a*2.f)+(b*2.f);
    193361  if (prtlev > 0) {
    194     cout << " A = \n " << a << endl;
    195     cout << " B = \n " << b << endl;
    196     cout << " C = 2A-2*B= \n " << c << endl;
     362    cout << "(9) A = " << a << endl;
     363    cout << "(9) B = " << b << endl;
     364    cout << "(9) C = 2A-2*B= " << c << endl;
    197365  }
    198366  c /= (nr*nc+1);
    199367  getMinMax(c, min, max);
    200368  if ((fabs(min-2.) > 0.0001) || (fabs(max-2.) > 0.0001)) {
    201     cout << "!!! ERROR Test3 C=2A+2*B  Min=" << min << " Max=" << max << endl;
    202     rc += 1;
    203   }
    204   else cout << " OK   Test3 C=2A+2*B  OK " << endl;
     369    cout << "(9) !!! ERROR Test3 C=2A+2*B  Min=" << min << " Max=" << max << endl;
     370    rc += 256;
     371  }
     372  else cout << "(9) OK   Test3 C=2A+2*B  OK " << endl;
    205373
    206374  return(rc);
Note: See TracChangeset for help on using the changeset viewer.