Changeset 2841 in Sophya for trunk/SophyaProg
- Timestamp:
- Nov 18, 2005, 2:48:02 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaProg/Tests/tfft.cc
r2615 r2841 3 3 4 4 #include <math.h> 5 #include <ctype.h> 5 6 #include <iostream> 7 #include <typeinfo> 6 8 7 9 #include "nbrandom.h" … … 14 16 #include "timing.h" 15 17 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 /* --------------------------------------------------------- */ 16 35 17 36 static bool inp_typ_random = false ; // true -> random input … … 27 46 static int nprtfc = 8; 28 47 48 static int prtlev = 0; 49 29 50 template <class T> 30 void TestFFTPack(T seuil, int num)51 void TestFFTPack(T seuil, sa_size_t num) 31 52 { 32 53 int i; … … 86 107 87 108 template <class T> 88 void TestFFTS(T seuil, FFTServerInterface & ffts, int num)109 int TestFFTS(T seuil, FFTServerInterface & ffts, sa_size_t num) 89 110 { 90 111 … … 98 119 TVector< complex<T> > outc(num); 99 120 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 } 106 137 107 138 cout << " Testing FFTServer " << ffts.getInfo() << endl; 108 139 109 cout << "Input / L = " << num << in << endl; 110 cout << endl; 140 cout << "Input / Length= " << num << endl; 141 if (prtlev > 0) 142 cout << in << endl; 111 143 112 144 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; 115 148 ffts.FFTForward(in, outc); 116 cout << " FourierCoefs , NElts= " << outc.NElts() << outc << endl; 149 if (prtlev > 0) 150 cout << " FourierCoefs: outc= \n" << outc << endl; 117 151 118 152 ffts.FFTBackward(outc, bk); 119 cout << " Backward , NElts= " << bk.NElts() << bk << endl; 153 if (prtlev > 0) 154 cout << " Backward: bk= \n" << bk << endl; 120 155 121 156 dif = bk*fact - in; 122 cout << " Difference , NElts= " << dif.NElts() << dif << endl; 157 if (prtlev > 0) 158 cout << " Difference dif= \n" << dif << endl; 123 159 124 160 ndiff = 0; … … 132 168 << " MaxDiff= " << maxdif << endl; 133 169 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; 135 173 ffts.FFTForward(inc, outc); 136 cout << " FourierCoef , NElts= " << outc.NElts() << outc << endl; 174 if (prtlev > 0) 175 cout << " FourierCoef , outc= \n" << outc << endl; 137 176 138 177 ffts.FFTBackward(outc, bkc); 139 cout << " Backward , NElts= " << bkc.NElts() << bkc << endl; 178 if (prtlev > 0) 179 cout << " Backward , bkc= \n " << bkc << endl; 140 180 141 181 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; 143 184 144 185 ndiff = 0; … … 151 192 cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff 152 193 << " MaxDiff= " << maxdif << endl; 194 195 if (ndiff != 0) rc += 8; 196 return rc; 153 197 } 154 198 … … 163 207 InitTim(); // Initializing the CPU timer 164 208 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); 170 217 } 171 218 … … 175 222 FFTWServer fftw; 176 223 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]); 181 225 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]); 185 228 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]); 186 232 187 233 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 188 241 FFTServerInterface * ffts; 189 242 if (*arg[2] == 'M') ffts = fftm.Clone(); … … 191 244 else ffts = fftp.Clone(); 192 245 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; 196 253 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; 201 256 if (*arg[2] == 'p') TestFFTPack(ds, sz); 202 else TestFFTS(ds, *ffts, sz);257 else rc = TestFFTS(ds, *ffts, sz); 203 258 } 204 259 else { 205 cout << "\n ========================================= \n" 206 << " ------ Testing FFTServer for float ----- \n" 207 << " =========================================== " << endl; 260 cout << " ------ Testing FFTServer for float (r_4)----- " << endl; 208 261 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 ) { 213 266 cerr << "TestFFT-main() , Catched exception: \n" << exc.Msg() << endl; 267 rc = 97; 214 268 } 215 269 catch(std::exception ex) { 216 270 cerr << "TestFFT-main() , Catched exception ! " << (string)(ex.what()) << endl; 217 } 218 219 /* 271 rc = 98; 272 } 220 273 catch(...) { 221 274 cerr << "TestFFT-main() , Catched ... exception ! " << endl; 222 }223 */275 rc = 99; 276 } 224 277 PrtTim("End of tfft "); 225 278 delete ffts; 226 } 279 cout << " =========== End of tfft Rc= " << rc << " =============" << endl; 280 }
Note:
See TracChangeset
for help on using the changeset viewer.