Line data Source code
1 : /** \file fftwTemplates.cpp
2 : * \brief Definitions of templatized wrappers for the fftw library
3 : * \ingroup fft_files
4 : * \author Jared R. Males (jaredmales@gmail.com)
5 : *
6 : */
7 :
8 : //***********************************************************************//
9 : // Copyright 2020 Jared R. Males (jaredmales@gmail.com)
10 : //
11 : // This file is part of mxlib.
12 : //
13 : // mxlib is free software: you can redistribute it and/or modify
14 : // it under the terms of the GNU General Public License as published by
15 : // the Free Software Foundation, either version 3 of the License, or
16 : // (at your option) any later version.
17 : //
18 : // mxlib is distributed in the hope that it will be useful,
19 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 : // GNU General Public License for more details.
22 : //
23 : // You should have received a copy of the GNU General Public License
24 : // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25 : //***********************************************************************//
26 :
27 : #include "math/ft/fftwTemplates.hpp"
28 :
29 : namespace mx
30 : {
31 : namespace math
32 : {
33 : namespace ft
34 : {
35 :
36 : template <>
37 0 : int fftw_import_system_wisdom<float>()
38 : {
39 0 : return ::fftwf_import_system_wisdom();
40 : }
41 :
42 : template <>
43 0 : int fftw_import_system_wisdom<double>()
44 : {
45 0 : return ::fftw_import_system_wisdom();
46 : }
47 :
48 : template <>
49 0 : int fftw_import_system_wisdom<long double>()
50 : {
51 0 : return ::fftwl_import_system_wisdom();
52 : }
53 :
54 : #ifdef HASQUAD
55 : template <>
56 : int fftw_import_system_wisdom<__float128>()
57 : {
58 : return ::fftwq_import_system_wisdom();
59 : }
60 : #endif
61 :
62 : template <>
63 4 : int fftw_import_wisdom_from_filename<float>( const char *filename )
64 : {
65 4 : return ::fftwf_import_wisdom_from_filename( filename );
66 : }
67 :
68 : template <>
69 4 : int fftw_import_wisdom_from_filename<double>( const char *filename )
70 : {
71 4 : return ::fftw_import_wisdom_from_filename( filename );
72 : }
73 :
74 : template <>
75 4 : int fftw_import_wisdom_from_filename<long double>( const char *filename )
76 : {
77 4 : return ::fftwl_import_wisdom_from_filename( filename );
78 : }
79 :
80 : #ifdef HASQUAD
81 : template <>
82 : int fftw_import_wisdom_from_filename<__float128>( const char *filename )
83 : {
84 : return ::fftwq_import_wisdom_from_filename( filename );
85 : }
86 : #endif
87 :
88 : template <>
89 4 : int fftw_export_wisdom_to_filename<float>( const char *filename )
90 : {
91 4 : return ::fftwf_export_wisdom_to_filename( filename );
92 : }
93 :
94 : template <>
95 4 : int fftw_export_wisdom_to_filename<double>( const char *filename )
96 : {
97 4 : return ::fftw_export_wisdom_to_filename( filename );
98 : }
99 :
100 : template <>
101 4 : int fftw_export_wisdom_to_filename<long double>( const char *filename )
102 : {
103 4 : return ::fftwl_export_wisdom_to_filename( filename );
104 : }
105 :
106 : #ifdef HASQUAD
107 : template <>
108 : int fftw_export_wisdom_to_filename<__float128>( const char *filename )
109 : {
110 : return ::fftwq_export_wisdom_to_filename( filename );
111 : }
112 : #endif
113 :
114 : template <>
115 0 : float *fftw_malloc<float>( size_t n )
116 : {
117 0 : return (float *)::fftwf_malloc( n * sizeof( float ) );
118 : }
119 :
120 : template <>
121 24 : complexFT *fftw_malloc<complexFT>( size_t n )
122 : {
123 24 : return (complexFT *)::fftwf_malloc( n * sizeof( complexFT ) );
124 : }
125 :
126 : template <>
127 24 : double *fftw_malloc<double>( size_t n )
128 : {
129 24 : return (double *)::fftw_malloc( n * sizeof( double ) );
130 : }
131 :
132 : template <>
133 62 : complexDT *fftw_malloc<complexDT>( size_t n )
134 : {
135 62 : return (complexDT *)::fftw_malloc( n * sizeof( complexDT ) );
136 : }
137 :
138 : template <>
139 0 : long double *fftw_malloc<long double>( size_t n )
140 : {
141 0 : return (long double *)::fftwl_malloc( n * sizeof( long double ) );
142 : }
143 :
144 : template <>
145 0 : complexLT *fftw_malloc<complexLT>( size_t n )
146 : {
147 0 : return (complexLT *)::fftwl_malloc( n * sizeof( complexLT ) );
148 : }
149 :
150 : #ifdef HASQUAD
151 : template <>
152 : __float128 *fftw_malloc<__float128>( size_t n )
153 : {
154 : return (__float128 *)::fftwq_malloc( n * sizeof( __float128 ) );
155 : }
156 :
157 : template <>
158 : complexQT *fftw_malloc<complexQT>( size_t n )
159 : {
160 : return (complexQT *)::fftwq_malloc( n * sizeof( complexQT ) );
161 : }
162 : #endif
163 :
164 : template <>
165 0 : void fftw_free<float>( float *p )
166 : {
167 0 : ::fftwf_free( p );
168 0 : }
169 :
170 : template <>
171 24 : void fftw_free<complexFT>( complexFT *p )
172 : {
173 24 : ::fftwf_free( p );
174 24 : }
175 :
176 : template <>
177 24 : void fftw_free<double>( double *p )
178 : {
179 24 : ::fftw_free( p );
180 24 : }
181 :
182 : template <>
183 62 : void fftw_free<complexDT>( complexDT *p )
184 : {
185 62 : ::fftw_free( p );
186 62 : }
187 :
188 : template <>
189 0 : void fftw_free<long double>( long double *p )
190 : {
191 0 : ::fftwl_free( p );
192 0 : }
193 :
194 : template <>
195 0 : void fftw_free<complexLT>( complexLT *p )
196 : {
197 0 : ::fftwl_free( p );
198 0 : }
199 :
200 : #ifdef HASQUAD
201 : template <>
202 : void fftw_free<__float128>( __float128 *p )
203 : {
204 : ::fftwq_free( p );
205 : }
206 :
207 : template <>
208 : void fftw_free<complexQT>( complexQT *p )
209 : {
210 : ::fftwq_free( p );
211 : }
212 : #endif
213 :
214 : template <>
215 2 : void fftw_make_planner_thread_safe<float>()
216 : {
217 : //::fftwf_make_planner_thread_safe();
218 2 : }
219 :
220 : template <>
221 2 : void fftw_make_planner_thread_safe<double>()
222 : {
223 : //::fftw_make_planner_thread_safe();
224 2 : }
225 :
226 : template <>
227 2 : void fftw_make_planner_thread_safe<long double>()
228 : {
229 : //::fftwl_make_planner_thread_safe();
230 2 : }
231 :
232 : #ifdef HASQUAD
233 : template <>
234 : void fftw_make_planner_thread_safe<__float128>()
235 : {
236 : //::fftwl_make_planner_thread_safe();
237 : }
238 : #endif
239 :
240 : template <>
241 2 : void fftw_plan_with_nthreads<float>( int nthreads )
242 : {
243 : //::fftwf_plan_with_nthreads(nthreads);
244 2 : }
245 :
246 : template <>
247 2 : void fftw_plan_with_nthreads<double>( int nthreads )
248 : {
249 : //::fftw_plan_with_nthreads(nthreads);
250 2 : }
251 :
252 : template <>
253 2 : void fftw_plan_with_nthreads<long double>( int nthreads )
254 : {
255 : //::fftwl_plan_with_nthreads(nthreads);
256 2 : }
257 :
258 : #ifdef HASQUAD
259 : template <>
260 : void fftw_plan_with_nthreads<__float128>( int nthreads )
261 : {
262 : //::fftwq_plan_with_nthreads(nthreads);
263 : }
264 : #endif
265 :
266 : template <>
267 : fftwTypeSpec<complexFT, complexFT>::planT
268 14 : fftw_plan_dft<complexFT, complexFT>( std::vector<int> n, complexFT *in, complexFT *out, int sign, unsigned flags )
269 : {
270 14 : return ::fftwf_plan_dft( n.size(),
271 14 : n.data(),
272 : reinterpret_cast<fftwf_complex *>( in ),
273 : reinterpret_cast<fftwf_complex *>( out ),
274 : sign,
275 14 : flags );
276 : }
277 :
278 : template <>
279 : fftwTypeSpec<float, complexFT>::planT
280 0 : fftw_plan_dft<float, complexFT>( std::vector<int> n, float *in, complexFT *out, int sign, unsigned flags )
281 : {
282 : static_cast<void>( sign );
283 0 : return ::fftwf_plan_dft_r2c( n.size(), n.data(), in, reinterpret_cast<fftwf_complex *>( out ), flags );
284 : }
285 :
286 : template <>
287 : fftwTypeSpec<complexFT, float>::planT
288 0 : fftw_plan_dft<complexFT, float>( std::vector<int> n, complexFT *in, float *out, int sign, unsigned flags )
289 : {
290 : static_cast<void>( sign );
291 0 : return ::fftwf_plan_dft_c2r( n.size(), n.data(), reinterpret_cast<fftwf_complex *>( in ), out, flags );
292 : }
293 :
294 : template <>
295 : fftwTypeSpec<complexDT, complexDT>::planT
296 35 : fftw_plan_dft<complexDT, complexDT>( std::vector<int> n, complexDT *in, complexDT *out, int sign, unsigned flags )
297 : {
298 35 : return ::fftw_plan_dft( n.size(),
299 35 : n.data(),
300 : reinterpret_cast<fftw_complex *>( in ),
301 : reinterpret_cast<fftw_complex *>( out ),
302 : sign,
303 35 : flags );
304 : }
305 :
306 : template <>
307 : fftwTypeSpec<double, complexDT>::planT
308 12 : fftw_plan_dft<double, complexDT>( std::vector<int> n, double *in, complexDT *out, int sign, unsigned flags )
309 : {
310 : static_cast<void>( sign );
311 12 : return ::fftw_plan_dft_r2c( n.size(), n.data(), in, reinterpret_cast<fftw_complex *>( out ), flags );
312 : }
313 :
314 : template <>
315 : fftwTypeSpec<complexDT, double>::planT
316 12 : fftw_plan_dft<complexDT, double>( std::vector<int> n, complexDT *in, double *out, int sign, unsigned flags )
317 : {
318 : static_cast<void>( sign );
319 12 : return ::fftw_plan_dft_c2r( n.size(), n.data(), reinterpret_cast<fftw_complex *>( in ), out, flags );
320 : }
321 :
322 : template <>
323 : fftwTypeSpec<complexLT, complexLT>::planT
324 0 : fftw_plan_dft<complexLT, complexLT>( std::vector<int> n, complexLT *in, complexLT *out, int sign, unsigned flags )
325 : {
326 0 : return ::fftwl_plan_dft( n.size(),
327 0 : n.data(),
328 : reinterpret_cast<fftwl_complex *>( in ),
329 : reinterpret_cast<fftwl_complex *>( out ),
330 : sign,
331 0 : flags );
332 : }
333 :
334 : template <>
335 : fftwTypeSpec<long double, complexLT>::planT
336 0 : fftw_plan_dft<long double, complexLT>( std::vector<int> n, long double *in, complexLT *out, int sign, unsigned flags )
337 : {
338 : static_cast<void>( sign );
339 0 : return ::fftwl_plan_dft_r2c( n.size(), n.data(), in, reinterpret_cast<fftwl_complex *>( out ), flags );
340 : }
341 :
342 : template <>
343 : fftwTypeSpec<complexLT, long double>::planT
344 0 : fftw_plan_dft<complexLT, long double>( std::vector<int> n, complexLT *in, long double *out, int sign, unsigned flags )
345 : {
346 : static_cast<void>( sign );
347 0 : return ::fftwl_plan_dft_c2r( n.size(), n.data(), reinterpret_cast<fftwl_complex *>( in ), out, flags );
348 : }
349 :
350 : #ifdef HASQUAD
351 : template <>
352 : fftwTypeSpec<complexQT, complexQT>::planT
353 : fftw_plan_dft<complexQT, complexQT>( std::vector<int> n, complexQT *in, complexQT *out, int sign, unsigned flags )
354 : {
355 : return ::fftwq_plan_dft( n.size(),
356 : n.data(),
357 : reinterpret_cast<fftwq_complex *>( in ),
358 : reinterpret_cast<fftwq_complex *>( out ),
359 : sign,
360 : flags );
361 : }
362 :
363 : template <>
364 : fftwTypeSpec<__float128, complexQT>::planT
365 : fftw_plan_dft<__float128, complexQT>( std::vector<int> n, __float128 *in, complexQT *out, int sign, unsigned flags )
366 : {
367 : return ::fftwq_plan_dft_r2c( n.size(), n.data(), in, reinterpret_cast<fftwq_complex *>( out ), flags );
368 : }
369 :
370 : template <>
371 : fftwTypeSpec<complexQT, __float128>::planT
372 : fftw_plan_dft<complexQT, __float128>( std::vector<int> n, complexQT *in, __float128 *out, int sign, unsigned flags )
373 : {
374 : return ::fftwq_plan_dft_c2r( n.size(), n.data(), reinterpret_cast<fftwq_complex *>( in ), out, flags );
375 : }
376 :
377 : #endif
378 :
379 : template <>
380 2 : void fftw_cleanup<float>()
381 : {
382 2 : ::fftwf_cleanup();
383 2 : }
384 :
385 : template <>
386 2 : void fftw_cleanup<double>()
387 : {
388 2 : ::fftw_cleanup();
389 2 : }
390 :
391 : template <>
392 2 : void fftw_cleanup<long double>()
393 : {
394 2 : ::fftwl_cleanup();
395 2 : }
396 :
397 : #ifdef HASQUAD
398 : template <>
399 : void fftw_cleanup<__float128>()
400 : {
401 : ::fftwq_cleanup();
402 : }
403 : #endif
404 :
405 : template <>
406 2 : void fftw_cleanup_threads<float>()
407 : {
408 : //::fftwf_cleanup_threads();
409 2 : }
410 :
411 : template <>
412 2 : void fftw_cleanup_threads<double>()
413 : {
414 : //::fftw_cleanup_threads();
415 2 : }
416 :
417 : template <>
418 2 : void fftw_cleanup_threads<long double>()
419 : {
420 : //::fftwl_cleanup_threads();
421 2 : }
422 :
423 : #ifdef HASQUAD
424 : template <>
425 : void fftw_cleanup_threads<__float128>()
426 : {
427 : //::fftwq_cleanup_threads();
428 : }
429 : #endif
430 :
431 : template <>
432 14 : void fftw_execute_dft<complexFT, complexFT>( fftwTypeSpec<complexFT, complexFT>::planT plan,
433 : complexFT *in,
434 : complexFT *out )
435 : {
436 14 : ::fftwf_execute_dft( plan, reinterpret_cast<fftwf_complex *>( in ), reinterpret_cast<fftwf_complex *>( out ) );
437 14 : }
438 :
439 : template <>
440 0 : void fftw_execute_dft<float, complexFT>( fftwTypeSpec<float, complexFT>::planT plan, float *in, complexFT *out )
441 : {
442 0 : ::fftwf_execute_dft_r2c( plan, in, reinterpret_cast<fftwf_complex *>( out ) );
443 0 : }
444 :
445 : template <>
446 0 : void fftw_execute_dft<complexFT, float>( fftwTypeSpec<complexFT, float>::planT plan, complexFT *in, float *out )
447 : {
448 0 : ::fftwf_execute_dft_c2r( plan, reinterpret_cast<fftwf_complex *>( in ), out );
449 0 : }
450 :
451 : template <>
452 1323 : void fftw_execute_dft<complexDT, complexDT>( fftwTypeSpec<complexDT, complexDT>::planT plan,
453 : complexDT *in,
454 : complexDT *out )
455 : {
456 1323 : ::fftw_execute_dft( plan, reinterpret_cast<fftw_complex *>( in ), reinterpret_cast<fftw_complex *>( out ) );
457 1323 : }
458 :
459 : template <>
460 36 : void fftw_execute_dft<double, complexDT>( fftwTypeSpec<double, complexDT>::planT plan, double *in, complexDT *out )
461 : {
462 36 : ::fftw_execute_dft_r2c( plan, in, reinterpret_cast<fftw_complex *>( out ) );
463 36 : }
464 :
465 : template <>
466 24 : void fftw_execute_dft<complexDT, double>( fftwTypeSpec<complexDT, double>::planT plan, complexDT *in, double *out )
467 : {
468 24 : ::fftw_execute_dft_c2r( plan, reinterpret_cast<fftw_complex *>( in ), out );
469 24 : }
470 :
471 : template <>
472 14 : void fftw_destroy_plan<float>( fftwPlanSpec<float>::planT plan )
473 : {
474 14 : ::fftwf_destroy_plan( plan );
475 14 : }
476 :
477 : template <>
478 59 : void fftw_destroy_plan<double>( fftwPlanSpec<double>::planT plan )
479 : {
480 59 : ::fftw_destroy_plan( plan );
481 59 : }
482 :
483 : template <>
484 0 : void fftw_destroy_plan<long double>( fftwPlanSpec<long double>::planT plan )
485 : {
486 0 : ::fftwl_destroy_plan( plan );
487 0 : }
488 :
489 : #ifdef HASQUAD
490 : template <>
491 : void fftw_destroy_plan<__float128>( fftwPlanSpec<__float128>::planT plan )
492 : {
493 : ::fftwq_destroy_plan( plan );
494 : }
495 :
496 : #endif
497 :
498 : } // namespace fft
499 : } // namespace math
500 : } // namespace mx
|