36 #include "../../meta/trueFalseT.hpp"
45 #define MXFFT_FORWARD (FFTW_FORWARD)
46 #define MXFFT_BACKWARD (FFTW_BACKWARD)
50 template<
typename _inputT,
typename _outputT,
size_t _rank,
int _cudaGPU=0>
54 std::vector<int> fftwDimVec(
int szX,
int szY,
int szZ);
71 template<
typename _inputT,
typename _outputT,
size_t _rank>
72 class fftT< _inputT, _outputT, _rank, 0>
74 typedef _inputT inputT;
75 typedef _outputT outputT;
79 static const size_t rank = _rank;
87 int m_dir {MXFFT_FORWARD};
93 planT m_plan {
nullptr};
101 template<
int crank = _rank>
103 int ndir = MXFFT_FORWARD,
104 bool inPlace =
false,
105 typename std::enable_if<crank==1>::type* = 0
109 template<
int crank = _rank>
112 int ndir = MXFFT_FORWARD,
113 bool inPlace =
false,
114 typename std::enable_if<crank==2>::type* = 0 );
117 template<
int crank = _rank>
121 int ndir = MXFFT_FORWARD,
122 bool inPlace =
false,
123 typename std::enable_if<crank==3>::type* = 0 );
145 template<
int crank = _rank>
147 int ndir=MXFFT_FORWARD,
149 typename std::enable_if<crank==1>::type* = 0
153 template<
int crank = _rank>
156 int ndir=MXFFT_FORWARD,
158 typename std::enable_if<crank==2>::type* = 0
162 template<
int crank = _rank>
166 int ndir=MXFFT_FORWARD,
168 typename std::enable_if<crank==3>::type* = 0
178 template<
typename inputT,
typename outputT,
size_t rank>
179 fftT<inputT,outputT,rank,0>::fftT()
183 template<
typename inputT,
typename outputT,
size_t rank>
185 fftT<inputT,outputT,rank,0>::fftT(
int nx,
188 typename std::enable_if<crank==1>::type*
193 plan(nx, ndir, inPlace);
196 template<
typename inputT,
typename outputT,
size_t rank>
198 fftT<inputT,outputT,rank,0>::fftT(
int nx,
202 typename std::enable_if<crank==2>::type*
207 plan(nx, ny, ndir, inPlace);
210 template<
typename inputT,
typename outputT,
size_t rank>
212 fftT<inputT,outputT,rank,0>::fftT(
int nx,
217 typename std::enable_if<crank==3>::type*
222 plan(nx, ny, nz, ndir, inPlace);
225 template<
typename inputT,
typename outputT,
size_t rank>
226 fftT<inputT,outputT,rank,0>::~fftT()
231 template<
typename inputT,
typename outputT,
size_t rank>
232 void fftT<inputT,outputT,rank,0>::destroyPlan()
234 if(m_plan) fftw_destroy_plan<realT>(m_plan);
243 template<
typename inputT,
typename outputT,
size_t rank>
244 int fftT<inputT,outputT,rank,0>::dir()
249 template<
typename inputT,
typename outputT,
size_t rank>
250 void fftT<inputT,outputT,rank,0>::doPlan(
const meta::trueFalseT<false> & inPlace)
259 if(rank == 1) sz = m_szX;
260 if(rank == 2) sz = m_szX*m_szY;
261 if(rank == 3) sz = m_szX*m_szY*m_szZ;
263 forplan1 = fftw_malloc<inputT>(sz);
264 forplan2 = fftw_malloc<outputT>(sz);
266 int pdir = FFTW_FORWARD;
267 if(m_dir == MXFFT_BACKWARD) pdir = FFTW_BACKWARD;
269 #ifndef MX_FFTW_NOOMP
273 m_plan = fftw_plan_dft<inputT, outputT>( fftwDimVec<rank>(m_szX, m_szY, m_szZ), forplan1, forplan2, pdir, FFTW_MEASURE);
276 fftw_free<inputT>(forplan1);
277 fftw_free<outputT>(forplan2);
281 template<
typename inputT,
typename outputT,
size_t rank>
282 void fftT<inputT,outputT,rank,0>::doPlan(
const meta::trueFalseT<true> & inPlace)
290 if(rank == 1) sz = m_szX;
291 if(rank == 2) sz = m_szX*m_szY;
292 if(rank == 3) sz = m_szX*m_szY*m_szZ;
294 forplan = fftw_malloc<complexT>(sz);
296 int pdir = FFTW_FORWARD;
297 if(m_dir == MXFFT_BACKWARD) pdir = FFTW_BACKWARD;
299 #ifndef MX_FFTW_NOOMP
303 m_plan = fftw_plan_dft<inputT, outputT>( fftwDimVec<rank>(m_szX, m_szY, m_szZ),
reinterpret_cast<inputT*
>(forplan),
reinterpret_cast<outputT*
>(forplan), pdir, FFTW_MEASURE);
306 fftw_free<inputT>(
reinterpret_cast<inputT*
>(forplan));
309 template<
typename inputT,
typename outputT,
size_t rank>
311 void fftT<inputT,outputT,rank,0>::plan(
int nx,
314 typename std::enable_if<crank==1>::type*
317 if(m_szX == nx && m_dir == ndir && m_plan)
332 doPlan(meta::trueFalseT<false>());
336 doPlan(meta::trueFalseT<true>());
341 template<
typename inputT,
typename outputT,
size_t rank>
343 void fftT<inputT,outputT,rank,0>::plan(
int nx,
347 typename std::enable_if<crank==2>::type*
350 if(m_szX == nx && m_szY == ny && m_dir == ndir && m_plan)
365 doPlan(meta::trueFalseT<false>());
369 doPlan(meta::trueFalseT<true>());
373 template<
typename inputT,
typename outputT,
size_t rank>
375 void fftT<inputT,outputT,rank,0>::plan(
int nx,
380 typename std::enable_if<crank==3>::type*
383 if(m_szX == nx && m_szY == ny && m_szZ == nz && m_dir == ndir && m_plan)
398 doPlan(meta::trueFalseT<false>());
402 doPlan(meta::trueFalseT<true>());
406 template<
typename inputT,
typename outputT,
size_t rank>
407 void fftT<inputT,outputT,rank,0>::operator()( outputT *out,
411 fftw_execute_dft<inputT,outputT>(m_plan, in, out);
419 std::vector<int> fftwDimVec<1>(
int szX,
425 std::vector<int> fftwDimVec<2>(
int szX,
431 std::vector<int> fftwDimVec<3>(
int szX,
442 class fft<std::complex<float>, std::complex<float>, 2, 1>
466 void plan(
int nx,
int ny)
468 if(m_szX == nx && m_szY == ny)
476 cufftPlan2d(&m_plan, m_szX, m_szY, CUFFT_C2C);
479 void fwdFFT(std::complex<float> * in, std::complex<float> * out)
481 cufftExecC2C(m_plan, (cufftComplex *) in, (cufftComplex *) out, CUFFT_FORWARD);
Declares and defines templatized wrappers for the fftw library.
fftwX_plan planT
Specializations typedef planT as fftwf_plan, fftw_plan, fftwl_plan, or fftwq_plan.
std::complex< realT > complexT
The complex data type.
_realT realT
The real data type (_realT is actually defined in specializations).