Changeset 2841 in Sophya for trunk/SophyaProg/Tests/tfft.cc


Ignore:
Timestamp:
Nov 18, 2005, 2:48:02 PM (20 years ago)
Author:
ansari
Message:

amelioration programme test FFT suite bug trouve ds FFTWServer - Reza 18/11/2005

File:
1 edited

Legend:

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

    r2615 r2841  
    33
    44#include <math.h>
     5#include <ctype.h>
    56#include <iostream>
     7#include <typeinfo>
    68
    79#include "nbrandom.h"
     
    1416#include "timing.h"
    1517
     18/*  --------------------------------------------------------- */
     19/*  ----       Programme de test de calcul de FFT        ---  */
     20/*  ----          par les FFTServer de SOPHYA            ---  */
     21/*  2000-2005      -   C. Magneville,  R. Ansari              */
     22/*      Test FFT-1D real<>complex complex<>complex            */
     23/*  Aide/Liste d'arguments :                                  */
     24/*  csh> tfft                                                 */
     25/*  Tests de base     ( ==> Rc=0 )                            */
     26/*  csh> tfft 15 P                                            */
     27/*  csh> tfft 16 P                                            */ 
     28/*  csh> tfft 15 W                                            */
     29/*  csh> tfft 16 W                                            */
     30/*  csh> tfft 1531 P D 0 50 0.0002                            */
     31/*  csh> tfft 1220 P D 0 50 0.0002                            */
     32/*  csh> tfft 1531 W D 0 50 0.0002                            */
     33/*  csh> tfft 1220 W D 0 50 0.0002                            */
     34/*  --------------------------------------------------------- */
    1635
    1736static bool inp_typ_random = false ;  // true -> random input
     
    2746static int nprtfc = 8;
    2847
     48static  int prtlev = 0;
     49
    2950template <class T>
    30 void TestFFTPack(T seuil, int num)
     51void TestFFTPack(T seuil, sa_size_t num)
    3152{
    3253  int i;
     
    86107
    87108template <class T>
    88 void TestFFTS(T seuil, FFTServerInterface & ffts, int num)
     109int TestFFTS(T seuil, FFTServerInterface & ffts, sa_size_t num)
    89110{
    90111
     
    98119  TVector< complex<T> > outc(num);
    99120
    100   for (i=0; i<num ; i++){
    101     ino[i] = in[i] = 0.5 + cos(2*M_PI*(double)i/(double)num)
    102                          + 2*sin(4*M_PI*(double)i/(double)num);
    103     inc[i] = complex<T> (in[i], 0.);
    104   }
    105  
     121  if (inp_typ_random) {
     122    cout << " TestFFTS/Random input vector ... " << endl;
     123    ino = in = RandomSequence() ; // Nombre aleatoire gaussienne - sigma=1, mean=0
     124    ComplexMathArray< T > cma;
     125    TVector< T > im(num);
     126    im = RandomSequence(RandomSequence::Flat);
     127    inc = cma.FillFrom(in, im);
     128  }
     129  else {
     130    cout << " TestFFTS/Random input vector = 0.5+cos(2x)+2sin(4x)... " << endl;
     131    for (i=0; i<num ; i++){
     132      ino[i] = in[i] = 0.5 + cos(2*M_PI*(double)i/(double)num)
     133        + 2*sin(4*M_PI*(double)i/(double)num);
     134      inc[i] = complex<T> (in[i], 0.);
     135    }
     136  }
    106137
    107138  cout << " Testing FFTServer " << ffts.getInfo() << endl;
    108139
    109   cout << "Input / L = " << num << in << endl;
    110   cout << endl;
     140  cout << "Input / Length= " << num << endl;
     141  if (prtlev > 0)
     142    cout << in << endl;
    111143
    112144  int ndiff = 0;
    113 
    114   cout << "\n ----  Testing FFT(T, complex<T>) ---- " << endl;
     145  int rc = 0;
     146
     147  cout << "\n ----  Testing FFT-1D(T, complex<T>) ---- " << endl;
    115148  ffts.FFTForward(in, outc);
    116   cout << " FourierCoefs , NElts= " << outc.NElts() << outc << endl;
     149  if (prtlev > 0)
     150    cout << " FourierCoefs: outc= \n" << outc << endl;
    117151
    118152  ffts.FFTBackward(outc, bk);
    119   cout << " Backward , NElts= " << bk.NElts() << bk << endl;
     153  if (prtlev > 0)
     154    cout << " Backward: bk= \n" << bk << endl;
    120155 
    121156  dif = bk*fact - in;
    122   cout << " Difference , NElts= " << dif.NElts() << dif << endl;
     157  if (prtlev > 0)
     158    cout << " Difference dif= \n" << dif << endl;
    123159
    124160  ndiff = 0;
     
    132168       << " MaxDiff= " << maxdif << endl;
    133169 
    134   cout << "\n ----  Testing FFT(complex<T>, complex<T>) ---- " << endl;
     170  if (ndiff != 0)  rc += 4;
     171
     172  cout << "\n ----  Testing FFT-1D(complex<T>, complex<T>) ---- " << endl;
    135173  ffts.FFTForward(inc, outc);
    136   cout << " FourierCoef , NElts= " << outc.NElts() << outc << endl;
     174  if (prtlev > 0)
     175    cout << " FourierCoef , outc= \n" << outc << endl;
    137176
    138177  ffts.FFTBackward(outc, bkc);
    139   cout << " Backward , NElts= " << bkc.NElts() << bkc << endl;
     178  if (prtlev > 0)
     179    cout << " Backward , bkc= \n " << bkc << endl;
    140180 
    141181  difc = bkc*complex<T>(fact,0.) - inc;
    142   cout << " Difference , NElts= " << difc.NElts() << difc << endl;
     182  if (prtlev > 0)
     183    cout << " Difference , difc= \n " << difc << endl;
    143184
    144185  ndiff = 0;
     
    151192  cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff
    152193       << " MaxDiff= " << maxdif << endl;
     194
     195  if (ndiff != 0)  rc += 8;
     196  return rc;
    153197}
    154198
     
    163207  InitTim();   // Initializing the CPU timer
    164208
    165   if (narg < 4) {
    166     cout << "tfft/ args error - \n  Usage tfft size px/Px/Mx/Wx f/d [NPrt=50 PrtLev=0] \n"
    167          << " p=FFTPackTest  P=FFTPack, M=FFTMayer, W= FFTWServer"
    168          << " x=0 -> Random input - f=float, d=double " << endl;
    169     exit(0);
     209  if (narg < 3) {
     210    cout << "tfft/ args error - \n  Usage tfft size p/P/M/W [f/d/F/D  PrtLev=0 MaxNPrt=50 diffthr] \n"
     211         << " 1D real/complex-FFT test (FFTServer) \n"
     212         << " size: input vector length \n "
     213         << " p=FFTPackTest  P=FFTPack, M=FFTMayer, W= FFTWServer \n "
     214         << " F/f:float, D/d:double F/D:random in_vector (default=D) \n"
     215         << " diffthr : Threshold for diff checks (=10^-6/10^-4 double/float)" << endl;
     216    return(1);
    170217  }
    171218
     
    175222  FFTWServer fftw;
    176223
    177   inp_typ_random = false;
    178   if (arg[2][1] == '0')  inp_typ_random = true;
    179 
    180   int sz = atoi(arg[1]);
     224  sa_size_t sz = atol(arg[1]);
    181225  int nprt = 50;
    182   int prtlev = 0;
    183   if (narg > 4) nprt = atoi(arg[4]);
    184   if (narg > 5) prtlev = atoi(arg[5]);
     226  if (narg > 4) prtlev = atoi(arg[4]);
     227  if (narg > 5) nprt = atoi(arg[5]);
    185228  BaseArray::SetMaxPrint(nprt, prtlev);
     229  float fs = 1.e-4;
     230  double ds = 1.e-6;
     231  if (narg > 6) fs = ds = atof(arg[6]);
    186232
    187233  if (sz < 2) sz = 2;
     234
     235  char dtyp = 'D';
     236  if (narg > 3) dtyp = *arg[3];
     237  inp_typ_random = true;
     238  if (islower(dtyp))  inp_typ_random = false;
     239  dtyp = toupper(dtyp);
     240
    188241  FFTServerInterface * ffts;
    189242  if (*arg[2] == 'M')  ffts = fftm.Clone();
     
    191244  else ffts = fftp.Clone();
    192245
    193   float fs = 1.e-4;
    194   double ds = 1.e-6;
    195 
     246  cout << "\n ============================================= \n"
     247       << " ------ Testing FFTServer " << typeid(*ffts).name() << "\n"
     248       << "   VecSize= " << sz << " InputType= "
     249       << ( (inp_typ_random ) ? " random " : " fixed(sin+cos) ") << "\n"
     250       << " =============================================== " << endl;
     251
     252  int rc = 0;
    196253  try {
    197     if (*arg[3] == 'd') {
    198       cout << "\n ========================================== \n"
    199            << "    ------ Testing FFTServer for double ----- \n"
    200            << " ============================================ " << endl;
     254    if (dtyp == 'D') {
     255      cout << "   ------ Testing FFTServer for double (r_8)----- " << endl;
    201256      if (*arg[2] == 'p') TestFFTPack(ds, sz);
    202       else TestFFTS(ds, *ffts, sz);
     257      else rc = TestFFTS(ds, *ffts, sz);
    203258    }
    204259    else {
    205       cout << "\n ========================================= \n"
    206            << "    ------ Testing FFTServer for float ----- \n"
    207            << " =========================================== " << endl;
     260      cout << "   ------ Testing FFTServer for float (r_4)----- " << endl;
    208261      if (*arg[2] == 'p') TestFFTPack(fs, sz);
    209       else TestFFTS(fs, *ffts, sz);
    210     }
    211   }
    212   catch(PThrowable exc ) {
     262      else rc = TestFFTS(fs, *ffts, sz);
     263    }
     264  }
     265  catch(PThrowable& exc ) {
    213266    cerr << "TestFFT-main() , Catched exception: \n" << exc.Msg() << endl;
     267    rc = 97;
    214268  }
    215269  catch(std::exception ex) {
    216270    cerr << "TestFFT-main() , Catched exception ! " << (string)(ex.what()) << endl;
    217   }
    218 
    219   /*
     271    rc = 98;
     272  }
    220273  catch(...) {
    221274    cerr << "TestFFT-main() , Catched ... exception ! " << endl;
    222   }
    223   */
     275    rc = 99;
     276  }
    224277  PrtTim("End of tfft ");
    225278  delete ffts;
    226 }
     279  cout << " =========== End of tfft Rc= " << rc << " =============" << endl;
     280}
Note: See TracChangeset for help on using the changeset viewer.