Changeset 715 in Sophya for trunk/SophyaProg/Tests
- Timestamp:
- Feb 5, 2000, 6:21:53 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaProg/Tests/tfft.cc
r705 r715 3 3 4 4 #include "fftpserver.h" 5 #include "fftmserver.h" 5 6 #include "sambainit.h" 6 7 … … 14 15 } 15 16 17 // Max Matrix print elts 18 static int nprt = 2; 19 static int nprtfc = 8; 20 16 21 template <class T> 17 void TestFFTS(T seuil, FFTServerInterface & ffts) 18 { 19 20 int num=16; 22 void TestFFTPack(T seuil, int num) 23 { 21 24 int i; 22 23 25 T fact = 1./num; 24 26 … … 26 28 TVector< T > in(num), ino(num), bk(num),dif(num); 27 29 TVector< complex<T> > outc(num); 30 31 cout << " DBG/1 outc " << outc.NElts() << endl; 32 outc.ReSize(32); 33 cout << " DBG/2 outc " << outc.NElts() << endl; 34 outc.ReSize(10); 35 cout << " DBG/3 outc " << outc.NElts() << endl; 36 outc.ReSize(48); 37 cout << " DBG/4 outc " << outc.NElts() << endl; 38 39 for (int i=0; i<num ; i++){ 40 ino[i] = in[i] = 0.5 + cos(2*M_PI*(double)i/(double)num) 41 + 2*sin(4*M_PI*(double)i/(double)num); 42 inc[i] = complex<T> (in[i], 0.); 43 } 28 44 29 30 for (int i=0; i<num ; i++){31 ino[i] = in[i] = cos(2*M_PI*i/8.) + sin(2*M_PI*i/4.);32 inc[i] = complex<T> (in[i], 0.);33 }34 35 36 cout << " Testing FFTServer " << ffts.getInfo() << endl;37 45 38 46 cout << "Input / L = " << num << endl; 39 in.Print(0,0,n um,0,num);47 in.Print(0,0,nprt,0,nprt); 40 48 cout << endl; 41 49 … … 44 52 cout << " Testing FFTPackServer " << endl; 45 53 fftp.fftf(in.NElts(), in.Data()); 46 in /= (num/2.);54 // in /= (num/2.); 47 55 cout << " fftp.fftf(in.NElts(), in.Data()) FORWARD: " << endl; 48 in.Print(0,0,n um,0,num);56 in.Print(0,0,nprtfc,0,nprtfc); 49 57 cout << endl; 50 58 fftp.fftb(in.NElts(), in.Data()); 51 59 cout << " fftp.fftb(in.NElts(), in.Data()) BACKWARD: " << endl; 52 in.Print(0,0,num,0,num); 53 cout << endl; 54 55 in = ino; 60 in.Print(0,0,nprt,0,nprt); 61 cout << endl; 62 dif = ino-in; 63 cout << " dif , NElts= " << dif.NElts() << endl; 64 dif.Print(0,0,nprt,0,nprt); 65 66 int ndiff = 0; 67 T maxdif=0., vdif; 68 for(i=0; i<num; i++) { 69 vdif = fabs(dif(i)); 70 if (vdif > seuil) ndiff++; 71 if (vdif > maxdif) maxdif = vdif; 72 } 73 cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff 74 << " MaxDiff= " << maxdif << endl; 75 76 } 77 78 template <class T> 79 void TestFFTS(T seuil, FFTServerInterface & ffts, int num) 80 { 81 82 cout <<" ===> TestFFTS " << ffts.getInfo() << " ArrSz= " << num << endl; 83 int i; 84 85 T fact = 1.; 86 87 TVector< complex<T> > inc(num), bkc(num), difc(num); 88 TVector< T > in(num), ino(num), bk(num),dif(num); 89 TVector< complex<T> > outc(num); 90 91 for (int i=0; i<num ; i++){ 92 ino[i] = in[i] = 0.5 + cos(2*M_PI*(double)i/(double)num) 93 + 2*sin(4*M_PI*(double)i/(double)num); 94 inc[i] = complex<T> (in[i], 0.); 95 } 96 97 98 cout << " Testing FFTServer " << ffts.getInfo() << endl; 99 100 cout << "Input / L = " << num << endl; 101 in.Print(0,0,nprt,0,nprt); 102 cout << endl; 103 104 int ndiff = 0; 56 105 57 106 cout << "\n ---- Testing FFT(T, complex<T>) ---- " << endl; 58 59 107 ffts.FFTForward(in, outc); 60 cout << " outc, NElts= " << outc.NElts() << endl;61 outc.Print(0,0,n um,0,num);108 cout << " FourierCoefs , NElts= " << outc.NElts() << endl; 109 outc.Print(0,0,nprtfc,0,nprtfc); 62 110 63 111 ffts.FFTBackward(outc, bk); 64 cout << " bk, NElts= " << bk.NElts() << endl;65 bk.Print(0,0,n um,0,num);112 cout << " Backward , NElts= " << bk.NElts() << endl; 113 bk.Print(0,0,nprt,0,nprt); 66 114 67 115 dif = bk*fact - in; 68 cout << " dif , NElts= " << dif.NElts() << endl; 69 dif.Print(0,0,num,0,num); 70 71 int ndiff = 0; 72 for(i=0; i<num; i++) 73 if (fabs(dif(i)) > seuil) ndiff++; 74 75 cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff << endl; 116 cout << " Difference , NElts= " << dif.NElts() << endl; 117 dif.Print(0,0,nprt,0,nprt); 118 119 ndiff = 0; 120 T maxdif=0., vdif; 121 for(i=0; i<num; i++) { 122 vdif = fabs(dif(i)); 123 if (vdif > seuil) ndiff++; 124 if (vdif > maxdif) maxdif = vdif; 125 } 126 cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff 127 << " MaxDiff= " << maxdif << endl; 76 128 77 129 cout << "\n ---- Testing FFT(complex<T>, complex<T>) ---- " << endl; 78 130 ffts.FFTForward(inc, outc); 79 cout << " outc, NElts= " << outc.NElts() << endl;80 outc.Print(0,0,n um,0,num);131 cout << " FourierCoef , NElts= " << outc.NElts() << endl; 132 outc.Print(0,0,nprtfc,0,nprtfc); 81 133 82 134 ffts.FFTBackward(outc, bkc); 83 cout << " bkc, NElts= " << bkc.NElts() << endl;84 bkc.Print(0,0,n um,0,num);135 cout << " Backward , NElts= " << bkc.NElts() << endl; 136 bkc.Print(0,0,nprt,0,nprt); 85 137 86 138 difc = bkc*complex<T>(fact,0.) - inc; 87 cout << " difc , NElts= " << difc.NElts() << endl; 88 difc.Print(0,0,num,0,num); 89 90 int ndiffc = 0; 91 for(i=0; i<num; i++) 92 if (fabs(module(difc(i))) > seuil) ndiffc++; 93 cout << " Difference, Seuil= " << seuil << " NDiffC= " << ndiffc << endl; 94 } 95 96 97 int main(int narg, char* arg) 139 cout << " Difference , NElts= " << difc.NElts() << endl; 140 difc.Print(0,0,nprt,0,nprt); 141 142 ndiff = 0; 143 maxdif=0., vdif; 144 for(i=0; i<num; i++) { 145 vdif = fabs(module(difc(i))); 146 if (vdif > seuil) ndiff++; 147 if (vdif > maxdif) maxdif = vdif; 148 } 149 cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff 150 << " MaxDiff= " << maxdif << endl; 151 } 152 153 154 155 156 157 int main(int narg, char* arg[]) 98 158 { 99 159 100 160 PeidaInit(); 101 161 InitTim(); // Initializing the CPU timer 102 FFTPackServer ffts; 103 162 163 if (narg < 4) { 164 cout << "tfft/ args error - \n Usage tfft size p/P/M f/d [NPrtFC NPrt] \n" 165 << " p=FFTPackTest P=FFTPack, M=FFTMayer, f=float, d=double " << endl; 166 exit(0); 167 } 168 169 FFTPackServer fftp; 170 FFTMayerServer fftm; 171 172 int sz = atoi(arg[1]); 173 if (narg > 4) nprtfc = atoi(arg[4]); 174 if (narg > 5) nprt = atoi(arg[4]); 175 176 if (sz < 2) sz = 2; 177 FFTServerInterface * ffts; 178 if (*arg[2] == 'M') ffts = fftm.Clone(); 179 else ffts = fftp.Clone(); 180 181 float fs = 1.e-4; 182 double ds = 1.e-6; 104 183 105 184 try { 106 float fs = 1.e-6; 107 double ds = 1.e-12; 108 cout << "\n ======================================== \n" 109 << " ------ Testing FFTS for float ----- \n" 110 << " ======================================== " << endl; 111 TestFFTS(fs, ffts); 112 cout << "\n ======================================== \n" 113 << " ------ Testing FFTS for double ----- \n" 114 << " ======================================== " << endl; 115 TestFFTS(ds, ffts); 185 if (*arg[3] == 'd') { 186 cout << "\n ========================================== \n" 187 << " ------ Testing FFTServer for double ----- \n" 188 << " ============================================ " << endl; 189 if (*arg[2] == 'p') TestFFTPack(ds, sz); 190 else TestFFTS(ds, *ffts, sz); 191 } 192 else { 193 cout << "\n ========================================= \n" 194 << " ------ Testing FFTServer for float ----- \n" 195 << " =========================================== " << endl; 196 if (*arg[2] == 'p') TestFFTPack(fs, sz); 197 else TestFFTS(fs, *ffts, sz); 198 } 116 199 } 117 200 catch(PThrowable exc ) { 118 cerr << "TestFFT-main() , Catched exception: " << exc.Msg() << endl;201 cerr << "TestFFT-main() , Catched exception: \n" << exc.Msg() << endl; 119 202 } 120 203 catch(std::exception ex) { 121 204 cerr << "TestFFT-main() , Catched exception ! " << (string)(ex.what()) << endl; 122 205 } 206 123 207 /* 124 208 catch(...) { … … 127 211 */ 128 212 PrtTim("End of tfft "); 129 } 213 delete ffts; 214 }
Note:
See TracChangeset
for help on using the changeset viewer.