Sirius  0.0.0
fftw.h
Go to the documentation of this file.
1 
22 #ifndef SIRIUS_FFTW_FFTW_H_
23 #define SIRIUS_FFTW_FFTW_H_
24 
25 #include <map>
26 #include <memory>
27 #include <type_traits>
28 
29 #include "sirius/fftw/types.h"
30 #include "sirius/image.h"
31 #include "sirius/types.h"
32 
33 #include "sirius/utils/lru_cache.h"
34 
35 namespace sirius {
36 namespace fftw {
37 
38 namespace detail {
39 
43 struct PlanDeleter {
44  void operator()(::fftw_plan plan);
45 };
46 } // namespace detail
47 
48 using PlanUPtr =
49  std::unique_ptr<std::remove_pointer_t<::fftw_plan>, detail::PlanDeleter>;
50 using PlanSPtr = std::shared_ptr<std::remove_pointer_t<::fftw_plan>>;
51 
55 class Fftw {
56  private:
57  static constexpr int kCacheSize = 10;
59 
60  public:
65  static Fftw& Instance();
66 
74  PlanSPtr GetRealToComplexPlan(const Size& size, double* in,
75  fftw_complex* out);
83  PlanSPtr GetComplexToRealPlan(const Size& size, fftw_complex* in,
84  double* out);
85 
86  private:
87  Fftw() = default;
88 
89  // not copyable
90  Fftw(const Fftw&) = delete;
91  Fftw operator=(const Fftw&) = delete;
92  // not moveable
93  Fftw(Fftw&&) = delete;
94  Fftw operator=(Fftw&&) = delete;
95 
96  PlanSPtr CreateC2RPlan(const Size& size, fftw_complex* in, double* out);
97  PlanSPtr CreateR2CPlan(const Size& size, double* out, fftw_complex* in);
98 
99  // allow PlanDeleter operator() to access private DestroyPlan method
100  friend void detail::PlanDeleter::operator()(::fftw_plan);
101  void DestroyPlan(::fftw_plan plan);
102 
103  private:
104  std::mutex plan_mutex_;
105 
106  PlanCache r2c_plans_;
107  PlanCache c2r_plans_;
108 };
109 
110 } // namespace fftw
111 } // namespace sirius
112 
113 #endif // SIRIUS_FFTW_FFTW_H_
Definition: exception.h:27
PlanSPtr GetRealToComplexPlan(const Size &size, double *in, fftw_complex *out)
Get a r2c fftw plan of the given size.
fftw3 management class
Definition: fftw.h:55
std::unique_ptr< std::remove_pointer_t<::fftw_plan >, detail::PlanDeleter > PlanUPtr
Definition: fftw.h:49
Deleter of fftw_plan for smart pointer.
Definition: fftw.h:43
static Fftw & Instance()
Get Fftw singleton instance.
std::shared_ptr< std::remove_pointer_t<::fftw_plan > > PlanSPtr
Definition: fftw.h:50
void operator()(::fftw_plan plan)
Data class that represents the size of an image.
Definition: types.h:38
PlanSPtr GetComplexToRealPlan(const Size &size, fftw_complex *in, double *out)
Get a c2r fftw plan of the given size.