Changeset 1394 in Sophya for trunk/SophyaLib/NTools
- Timestamp:
- Feb 12, 2001, 6:09:27 PM (25 years ago)
- Location:
- trunk/SophyaLib/NTools
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/fftmserver.cc
r805 r1394 7 7 FFTMayerServer::FFTMayerServer() 8 8 : FFTServerInterface("FFTMayerServer using extended FFTMayer package") 9 , ckR4("FFTMayerServer: ", true, true) , ckR8("FFTMayerServer: ", true, true) 9 10 10 11 { … … 24 25 25 26 /* --Methode-- */ 26 void FFTMayerServer::FFTForward(TVector< complex<r_8> > const & in, TVector< complex<r_8> > & out) 27 { 27 void FFTMayerServer::FFTForward(TArray< complex<r_8> > const & ina, TArray< complex<r_8> > & outa) 28 { 29 ckR8.CheckResize(ina, outa); 30 TVector< complex<r_8> > in(ina); 31 TVector< complex<r_8> > out(outa); 32 28 33 r_8 a,b,c,d; 29 34 r_8 q,r,s,t; … … 55 60 fht_r8(inoutim.Data(),inoutim.NElts()); 56 61 57 out.ReSize(in.NElts());62 // out.ReSize(in.NElts()); 58 63 r_8 fn = 1./n; 59 64 if (getNormalize()) … … 66 71 67 72 /* --Methode-- */ 68 void FFTMayerServer::FFTBackward(TVector< complex<r_8> > const & in, TVector< complex<r_8> > & out) 69 { 73 void FFTMayerServer::FFTBackward(TArray< complex<r_8> > const & ina, TArray< complex<r_8> > & outa) 74 { 75 ckR8.CheckResize(ina, outa); 76 TVector< complex<r_8> > in(ina); 77 TVector< complex<r_8> > out(outa); 78 70 79 r_8 a,b,c,d; 71 80 r_8 q,r,s,t; … … 87 96 fht_r8(inoutim.Data(),inoutim.NElts()); 88 97 89 out.ReSize(in.NElts());98 // out.ReSize(in.NElts()); 90 99 out(0) = complex<r_8>(inoutre(0), inoutim(0)); 91 100 out(n/2) = complex<r_8>(inoutre(n/2), inoutim(n/2)); … … 102 111 103 112 /* --Methode-- */ 104 void FFTMayerServer::FFTForward(TVector< complex<r_4> > const & in, TVector< complex<r_4> > & out) 105 { 113 void FFTMayerServer::FFTForward(TArray< complex<r_4> > const & ina, TArray< complex<r_4> > & outa) 114 { 115 ckR4.CheckResize(ina, outa); 116 TVector< complex<r_4> > in(ina); 117 TVector< complex<r_4> > out(outa); 118 106 119 r_4 a,b,c,d; 107 120 r_4 q,r,s,t; … … 133 146 fht_r4(inoutim.Data(),inoutim.NElts()); 134 147 135 out.ReSize(in.NElts());148 // out.ReSize(in.NElts()); 136 149 r_4 fn = 1./n; 137 150 if (getNormalize()) … … 145 158 146 159 /* --Methode-- */ 147 void FFTMayerServer::FFTBackward(TVector< complex<r_4> > const & in, TVector< complex<r_4> > & out) 148 { 160 void FFTMayerServer::FFTBackward(TArray< complex<r_4> > const & ina, TArray< complex<r_4> > & outa) 161 { 162 ckR4.CheckResize(ina, outa); 163 TVector< complex<r_4> > in(ina); 164 TVector< complex<r_4> > out(outa); 165 149 166 r_4 a,b,c,d; 150 167 r_4 q,r,s,t; … … 167 184 fht_r4(inoutim.Data(),inoutim.NElts()); 168 185 169 out.ReSize(in.NElts());186 // out.ReSize(in.NElts()); 170 187 out(0) = complex<r_4>(inoutre(0), inoutim(0)); 171 188 out(n/2) = complex<r_4>(inoutre(n/2), inoutim(n/2)); … … 182 199 183 200 /* --Methode-- */ 184 void FFTMayerServer::FFTForward(TVector< r_4 > const & in, TVector< complex<r_4> > & out) 185 { 201 void FFTMayerServer::FFTForward(TArray< r_4 > const & ina, TArray< complex<r_4> > & outa) 202 { 203 ckR4.CheckResize(ina, outa); 204 TVector< r_4 > in(ina); 205 TVector< complex<r_4> > out(outa); 206 186 207 r_4 a,b; 187 208 int i,j,k; … … 205 226 206 227 207 out.ReSize(n/2+1);228 // out.ReSize(n/2+1); 208 229 out(0) = complex<r_4>(inout(0), 0.); 209 230 … … 225 246 226 247 /* --Methode-- */ 227 void FFTMayerServer::FFTBackward(TVector< complex<r_4> > const & in, TVector< r_4 > & out) 228 { 248 void FFTMayerServer::FFTBackward(TArray< complex<r_4> > const & ina, TArray< r_4 > & outa) 249 { 250 ckR4.CheckResize(ina, outa); 251 TVector< complex<r_4> > in(ina); 252 TVector< r_4 > out(outa); 253 229 254 r_4 a,b; 230 255 int i,j,k; … … 238 263 } 239 264 240 out.ReSize(nc);265 // out.ReSize(nc); 241 266 out(0) = in(0).real(); 242 267 if (nc%2 == 0) { // nc pair … … 267 292 268 293 /* --Methode-- */ 269 void FFTMayerServer::FFTForward(TVector< r_8 > const & in, TVector< complex<r_8> > & out) 270 { 294 void FFTMayerServer::FFTForward(TArray< r_8 > const & ina, TArray< complex<r_8> > & outa) 295 { 296 ckR8.CheckResize(ina, outa); 297 TVector< r_8 > in(ina); 298 TVector< complex<r_8> > out(outa); 299 271 300 r_8 a,b; 272 301 int i,j,k; … … 290 319 291 320 292 out.ReSize(n/2+1);321 // out.ReSize(n/2+1); 293 322 out(0) = complex<r_8>(inout(0), 0.); 294 323 … … 309 338 310 339 /* --Methode-- */ 311 void FFTMayerServer::FFTBackward(TVector< complex<r_8> > const & in, TVector< r_8 > & out) 312 { 340 void FFTMayerServer::FFTBackward(TArray< complex<r_8> > const & ina, TArray< r_8 > & outa) 341 { 342 ckR8.CheckResize(ina, outa); 343 TVector< r_8 > out(outa); 344 TVector< complex<r_8> > in(ina); 345 313 346 r_8 a,b; 314 347 int i,j,k; … … 322 355 } 323 356 324 out.ReSize(nc);357 // out.ReSize(nc); 325 358 out(0) = in(0).real(); 326 359 if (nc%2 == 0) { // nc pair -
trunk/SophyaLib/NTools/fftmserver.h
r717 r1394 18 18 19 19 // Transforme unidimensionnel sur des doubles 20 virtual void FFTForward(T Vector< complex<r_8> > const & in, TVector< complex<r_8> > & out);21 virtual void FFTBackward(T Vector< complex<r_8> > const & in, TVector< complex<r_8> > & out);22 virtual void FFTForward(T Vector< r_8 > const & in, TVector< complex<r_8> > & out);23 virtual void FFTBackward(T Vector< complex<r_8> > const & in, TVector< r_8 > & out);20 virtual void FFTForward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out); 21 virtual void FFTBackward(TArray< complex<r_8> > const & in, TArray< complex<r_8> > & out); 22 virtual void FFTForward(TArray< r_8 > const & in, TArray< complex<r_8> > & out); 23 virtual void FFTBackward(TArray< complex<r_8> > const & in, TArray< r_8 > & out); 24 24 25 25 26 26 // Transforme unidimensionnel sur des float 27 virtual void FFTForward(T Vector< complex<r_4> > const & in, TVector< complex<r_4> > & out);28 virtual void FFTBackward(T Vector< complex<r_4> > const & in, TVector< complex<r_4> > & out);29 virtual void FFTForward(T Vector< r_4 > const & in, TVector< complex<r_4> > & out);30 virtual void FFTBackward(T Vector< complex<r_4> > const & in, TVector< r_4 > & out);27 virtual void FFTForward(TArray< complex<r_4> > const & in, TArray< complex<r_4> > & out); 28 virtual void FFTBackward(TArray< complex<r_4> > const & in, TArray< complex<r_4> > & out); 29 virtual void FFTForward(TArray< r_4 > const & in, TArray< complex<r_4> > & out); 30 virtual void FFTBackward(TArray< complex<r_4> > const & in, TArray< r_4 > & out); 31 31 32 32 33 33 protected: 34 34 virtual bool checkLength(int n); 35 36 FFTArrayChecker<r_4> ckR4; 37 FFTArrayChecker<r_8> ckR8; 35 38 }; 36 39 -
trunk/SophyaLib/NTools/fftpserver.cc
r1390 r1394 28 28 FFTPackServer::FFTPackServer() 29 29 : FFTServerInterface("FFTPackServer using extended FFTPack (C-version) package") 30 , ckR4( true, true) , ckR8(true, true)30 , ckR4("FFTPackServer: ", true, true) , ckR8("FFTPackServer: ", true, true) 31 31 { 32 32 //the working array and its size for the different … … 72 72 73 73 74 75 74 void FFTPackServer::FFTForward(TArray< complex<r_4> > const & in, TArray< complex<r_4> > & out) 76 75 { 77 76 ckR4.CheckResize(in, out); 78 77 out = in; 78 cout << out << endl; 79 79 fftf(out.Size(), out.Data()); 80 80 if (getNormalize()) out *= (1./(r_4)(in.Size())); … … 93 93 TArray< r_4 > inout(in, false); 94 94 fftf(inout.Size(), inout.Data()); 95 ckR4.ReShapetoCompl(inout, out);95 ReShapetoCompl(inout, out); 96 96 if (getNormalize()) out *= complex<r_4>((1./(r_4)(in.Size())), 0.); 97 97 } … … 100 100 { 101 101 ckR4.CheckResize(in, out); 102 ckR4.ReShapetoReal(in, out);102 ReShapetoReal(in, out); 103 103 fftb(out.Size(), out.Data()); 104 104 } … … 110 110 TArray< r_8 > inout(in, false); 111 111 fftf(inout.Size(), inout.Data()); 112 ckR8.ReShapetoCompl(inout, out);112 ReShapetoCompl(inout, out); 113 113 if (getNormalize()) out *= complex<r_8>((1./(r_8)(in.Size())), 0.); 114 114 } … … 117 117 { 118 118 ckR8.CheckResize(in, out); 119 ckR8.ReShapetoReal(in, out); 120 fftb(out.Size(), out.Data()); 121 } 122 123 119 ReShapetoReal(in, out); 120 fftb(out.Size(), out.Data()); 121 } 122 123 124 template <class T> 125 void FFTPack_ReShapetoReal(TArray< complex<T> > const & ina, TArray< T > & outa) 126 { 127 TVector< complex<T> > in(ina); 128 TVector< T > out(outa); 129 sa_size_t n = in.NElts(); 130 T thr = FFTArrayChecker<T>::ZeroThreshold(); 131 sa_size_t ncs = ( (in(n-1).imag() < -thr) || (in(n-1).imag() > thr) ) ? 132 ncs = 2*n-1 : ncs = 2*n-2; 133 134 if (out.NElts() != ncs) 135 throw SzMismatchError("FFTPack_ReShapetoReal() - Wrong output array size !"); 136 // cerr << "DEBUG-FFTPack_ReShapetoReal() ncs = " << ncs 137 // << " out.NElts()= " << out.NElts() << endl; 138 139 sa_size_t k; 140 141 out(0) = in(0).real(); 142 for(k=1;k<n-1;k++) { 143 out(2*k-1) = in(k).real(); 144 out(2*k) = in(k).imag(); 145 } 146 if (ncs == n*2-2) out(ncs-1) = in(n-1).real(); 147 else { out(ncs-2) = in(n-1).real(); out(ncs-1) = in(n-1).imag(); } 148 149 return; 150 } 151 152 template <class T> 153 void FFTPack_ReShapetoCompl(TArray< T > const & ina, TArray< complex<T> > & outa) 154 { 155 TVector< T > in(ina); 156 TVector< complex<T> > out(outa); 157 sa_size_t n = in.NElts(); 158 sa_size_t ncs = n/2+1; 159 sa_size_t nc = (n%2 != 0) ? n/2+1 : n/2; 160 if (out.NElts() != ncs) 161 throw SzMismatchError("FFTPack_ReShapetoCompl() - Wrong output array size !"); 162 163 out(0) = complex<T> (in(0),0.); 164 for(int k=1;k<nc;k++) 165 out(k) = complex<r_4> (in(2*k-1), in(2*k)); 166 if (n%2 == 0) out(ncs-1) = complex<T>(in(n-1), 0.); 167 168 return; 169 } 170 171 void FFTPackServer::ReShapetoReal(TArray< complex<r_8> > const & in, TArray< r_8 > & out) 172 { 173 FFTPack_ReShapetoReal<r_8>(in, out); 174 } 175 176 void FFTPackServer::ReShapetoCompl(TArray< r_8 > const & in, TArray< complex<r_8> > & out) 177 { 178 FFTPack_ReShapetoCompl<r_8>(in, out); 179 } 180 181 void FFTPackServer::ReShapetoReal(TArray< complex<r_4> > const & in, TArray< r_4 > & out) 182 { 183 FFTPack_ReShapetoReal<r_4>(in, out); 184 } 185 186 void FFTPackServer::ReShapetoCompl(TArray< r_4 > const & in, TArray< complex<r_4> > & out) 187 { 188 FFTPack_ReShapetoCompl<r_4>(in, out); 189 } 124 190 125 191 void FFTPackServer::checkint_rfft(int_4 l) -
trunk/SophyaLib/NTools/fftpserver.h
r1390 r1394 33 33 virtual void FFTForward(TArray< r_4 > const & in, TArray< complex<r_4> > & out); 34 34 virtual void FFTBackward(TArray< complex<r_4> > const & in, TArray< r_4 > & out); 35 36 // Methodes statiques pour reordonner les donnees 37 static void ReShapetoReal(TArray< complex<r_8> > const & in, TArray< r_8 > & out); 38 static void ReShapetoCompl(TArray< r_8 > const & in, TArray< complex<r_8> > & out); 39 static void ReShapetoReal(TArray< complex<r_4> > const & in, TArray< r_4 > & out); 40 static void ReShapetoCompl(TArray< r_4 > const & in, TArray< complex<r_4> > & out); 35 41 36 42 // Methodes propres a cette classe -
trunk/SophyaLib/NTools/fftservintf.cc
r1390 r1394 77 77 /* --Methode-- */ 78 78 template <class T> 79 FFTArrayChecker<T>::FFTArrayChecker(bool checkpack, bool onedonly) 80 { 79 FFTArrayChecker<T>::FFTArrayChecker(string msg, bool checkpack, bool onedonly) 80 { 81 _msg = msg + " FFTArrayChecker::"; 81 82 _checkpack = checkpack; 82 83 _onedonly = onedonly; … … 89 90 } 90 91 92 template <class T> 93 T FFTArrayChecker<T>::ZeroThreshold() 94 { 95 return(0); 96 } 97 98 r_8 FFTArrayChecker< r_8 >::ZeroThreshold() 99 { 100 return(1.e-18); 101 } 102 103 r_4 FFTArrayChecker< r_4 >::ZeroThreshold() 104 { 105 return(1.e-9); 106 } 107 108 109 91 110 /* --Methode-- */ 92 111 template <class T> … … 94 113 { 95 114 int k; 96 if (in.Size() < 1) 97 throw(SzMismatchError("FFTArrayChecker::CheckResize(complex in, complex out) - Unallocated input array !")); 115 string msg; 116 if (in.Size() < 1) { 117 msg = _msg + "CheckResize(complex in, complex out) - Unallocated input array !"; 118 throw(SzMismatchError(msg)); 119 } 98 120 if (_checkpack) 99 if ( !in.IsPacked() ) 100 throw(SzMismatchError("FFTArrayChecker::CheckResize(complex in, complex out) - Not packed input array !")); 121 if ( !in.IsPacked() ) { 122 msg = _msg + "CheckResize(complex in, complex out) - Not packed input array !"; 123 throw(SzMismatchError(msg)); 124 } 101 125 int ndg1 = 0; 102 126 for(k=0; k<in.NbDimensions(); k++) 103 127 if (in.Size(k) > 1) ndg1++; 104 128 if (_onedonly) 105 if (ndg1++ > 1) 106 throw(SzMismatchError("FFTArrayChecker::CheckResize(complex in, complex out) - Only 1-D array accepted !")); 107 108 sa_size_t sz[BASEARRAY_MAXNDIMS]; 109 for(k=0; k<in.NbDimensions(); k++) 110 sz[k] = in.Size(k); 111 out.ReSize(in.NbDimensions(), sz); 129 if (ndg1 > 1) { 130 msg = _msg + "CheckResize(complex in, complex out) - Only 1-D array accepted !"; 131 throw(SzMismatchError(msg)); 132 } 133 out.ReSize(in); 134 // sa_size_t sz[BASEARRAY_MAXNDIMS]; 135 // for(k=0; k<in.NbDimensions(); k++) 136 // sz[k] = in.Size(k); 137 // out.ReSize(in.NbDimensions(), sz); 112 138 113 139 return(ndg1); … … 119 145 { 120 146 int k; 121 if (in.Size() < 1) 122 throw(SzMismatchError("FFTArrayChecker::CheckResize(real in, complex out) - Unallocated input array !")); 147 string msg; 148 if (in.Size() < 1) { 149 msg = _msg + "CheckResize(real in, complex out) - Unallocated input array !"; 150 throw(SzMismatchError(msg)); 151 } 123 152 if (_checkpack) 124 if ( !in.IsPacked() ) 125 throw(SzMismatchError("FFTArrayChecker::CheckResize(real in, complex out) - Not packed input array !")); 153 if ( !in.IsPacked() ) { 154 msg = _msg + "CheckResize(real in, complex out) - Not packed input array !"; 155 throw(SzMismatchError(msg)); 156 } 126 157 int ndg1 = 0; 127 158 for(k=0; k<in.NbDimensions(); k++) 128 159 if (in.Size(k) > 1) ndg1++; 129 160 if (_onedonly) 130 if (ndg1++ > 1) 131 throw(SzMismatchError("FFTArrayChecker::CheckResize(real in, complex out) - Only 1-D array accepted !")); 132 161 if (ndg1 > 1) { 162 msg = _msg + "CheckResize(real in, complex out) - Only 1-D array accepted !"; 163 throw(SzMismatchError(msg)); 164 } 133 165 sa_size_t sz[BASEARRAY_MAXNDIMS]; 134 166 for(k=0; k<in.NbDimensions(); k++) 135 sz[k] = in.Size(k)/2+1; 167 sz[k] = in.Size(k)/2+1; 168 // sz[k] = (in.Size(k)%2 != 0) ? in.Size(k)/2+1 : in.Size(k)/2; 169 136 170 out.ReSize(in.NbDimensions(), sz); 137 171 … … 144 178 { 145 179 int k; 146 if (in.Size() < 1) 147 throw(SzMismatchError("FFTArrayChecker::CheckResize(complex in, real out) - Unallocated input array !")); 180 string msg; 181 if (in.Size() < 1) { 182 msg = _msg + "CheckResize(complex in, real out) - Unallocated input array !"; 183 throw(SzMismatchError(msg)); 184 } 148 185 if (_checkpack) 149 if ( !in.IsPacked() ) 150 throw(SzMismatchError("FFTArrayChecker::CheckResize(complex in, real out) - Not packed input array !")); 186 if ( !in.IsPacked() ) { 187 msg = _msg + "CheckResize(complex in, real out) - Not packed input array !"; 188 throw(SzMismatchError(msg)); 189 } 151 190 int ndg1 = 0; 152 191 for(k=0; k<in.NbDimensions(); k++) 153 192 if (in.Size(k) > 1) ndg1++; 154 193 if (_onedonly) 155 if (ndg1++ > 1) 156 throw(SzMismatchError("FFTArrayChecker::CheckResize(complex in, real out) - Only 1-D array accepted !")); 157 194 if (ndg1 > 1) { 195 msg = _msg + "CheckResize(complex in, real out) - Only 1-D array accepted !"; 196 throw(SzMismatchError(msg)); 197 } 158 198 sa_size_t sz[BASEARRAY_MAXNDIMS]; 159 for(k=0; k<in.NbDimensions(); k++) 160 sz[k] = in.Size(k)*2-1; 199 if (ndg1 > 1) { 200 for(k=0; k<in.NbDimensions(); k++) 201 sz[k] = in.Size(k)*2-1; 202 } 203 else { 204 for(k=0; k<BASEARRAY_MAXNDIMS; k++) sz[k] = 1; 205 T thr = ZeroThreshold(); 206 sa_size_t n = in.Size(in.MaxSizeKA()); 207 sa_size_t ncs = ( (in[n-1].imag() < -thr) || (in[n-1].imag() > thr) ) ? 208 ncs = 2*n-1 : ncs = 2*n-2; 209 sz[in.MaxSizeKA()] = ncs; 210 } 211 161 212 out.ReSize(in.NbDimensions(), sz); 162 213 … … 165 216 } 166 217 167 /* --Methode-- */218 /* --Methode-- 168 219 template <class T> 169 220 void FFTArrayChecker<T>::ReShapetoReal( TArray< complex<T> > const & in, TArray< T > & out) … … 182 233 out[ncs-2] = in[n-1].real(); out[ncs-1] = in[n-1].imag(); 183 234 } 184 185 /* --Methode-- */ 235 */ 236 237 /* --Methode-- 186 238 template <class T> 187 239 void FFTArrayChecker<T>::ReShapetoCompl(TArray< T > const & in, TArray< complex<T> > & out) … … 195 247 if (n%2 == 0) out[ncs-1] = complex<r_8>(in[n-1], 0.); 196 248 } 197 249 */ 198 250 199 251 #ifdef __CXX_PRAGMA_TEMPLATES__ -
trunk/SophyaLib/NTools/fftservintf.h
r1390 r1394 31 31 inline string getInfo() const { return _info; } 32 32 33 // Transforme unidimensionnel sur des doubles34 virtual void FFTForward(TVector< complex<r_8> > const & in, TVector< complex<r_8> > & out);35 virtual void FFTBackward(TVector< complex<r_8> > const & in, TVector< complex<r_8> > & out);36 virtual void FFTForward(TVector< r_8 > const & in, TVector< complex<r_8> > & out);37 virtual void FFTBackward(TVector< complex<r_8> > const & in, TVector< r_8 > & out);38 39 // Transforme unidimensionnel sur des float40 virtual void FFTForward(TVector< complex<r_4> > const & in, TVector< complex<r_4> > & out);41 virtual void FFTBackward(TVector< complex<r_4> > const & in, TVector< complex<r_4> > & out);42 virtual void FFTForward(TVector< r_4 > const & in, TVector< complex<r_4> > & out);43 virtual void FFTBackward(TVector< complex<r_4> > const & in, TVector< r_4 > & out);44 45 46 33 //--------------------------------------------------- 47 34 // Transforme N-dim sur des doubles … … 67 54 class FFTArrayChecker { 68 55 public: 69 FFTArrayChecker( bool checkpack=true, bool onedonly=false);56 FFTArrayChecker(string msg, bool checkpack=true, bool onedonly=false); 70 57 virtual ~FFTArrayChecker(); 58 static T ZeroThreshold(); 71 59 virtual int CheckResize(TArray< complex<T> > const & in, TArray< complex<T> > & out); 72 60 virtual int CheckResize(TArray< T > const & in, TArray< complex<T> > & out); 73 61 virtual int CheckResize(TArray< complex<T> > const & in, TArray< T > & out); 74 virtual void ReShapetoReal(TArray< complex<T> > const & in, TArray< T > & out);75 virtual void ReShapetoCompl(TArray< T > const & in, TArray< complex<T> > & out);62 // virtual void ReShapetoReal(TArray< complex<T> > const & in, TArray< T > & out); 63 // virtual void ReShapetoCompl(TArray< T > const & in, TArray< complex<T> > & out); 76 64 77 65 protected: 66 string _msg; 78 67 bool _checkpack; 79 68 bool _onedonly;
Note:
See TracChangeset
for help on using the changeset viewer.