HOPS
HOPS class reference
MHO_MultidimensionalFastFourierTransformInterface.hh
Go to the documentation of this file.
1 #ifndef MHO_MultidimensionalFastFourierTransformInterface_HH__
2 #define MHO_MultidimensionalFastFourierTransformInterface_HH__
3 
4 #include <cstring>
5 
6 #include "MHO_Message.hh"
7 #include "MHO_Meta.hh"
8 #include "MHO_TableContainer.hh"
9 
10 namespace hops
11 {
12 
24 template< typename XArgType > class MHO_MultidimensionalFastFourierTransformInterface
25 {
26  public:
28  "Array element type must be a complex floating point type.");
29  using complex_value_type = typename XArgType::value_type;
30  using floating_point_value_type = typename XArgType::value_type::value_type;
31 
33  {
34  for(size_t i = 0; i < XArgType::rank::value; i++)
35  {
36  fDimensionSize[i] = 0;
37  fAxesToXForm[i] = true;
38  }
39 
40  fIsValid = false;
41  fInitialized = false;
42  fForward = true;
43  fTransformAxisLabels = true;
44  };
45 
47 
52  virtual void SetForward() { fForward = true; }
53 
58  virtual void SetBackward() { fForward = false; };
59 
60  //sometimes we may want to select/deselect particular dimensions of the x-form
61  //default is to transform along every dimension, but that may not always be needed
66  virtual void SelectAllAxes()
67  {
68  for(std::size_t i = 0; i < XArgType::rank::value; i++)
69  {
70  fAxesToXForm[i] = true;
71  fInitialized = false;
72  }
73  }
74 
79  virtual void DeselectAllAxes()
80  {
81  for(std::size_t i = 0; i < XArgType::rank::value; i++)
82  {
83  fAxesToXForm[i] = false;
84  fInitialized = false;
85  }
86  }
87 
94  virtual void SelectAxis(std::size_t axis_index)
95  {
96  fInitialized = false;
97  if(axis_index < XArgType::rank::value)
98  {
99  fAxesToXForm[axis_index] = true;
100  }
101  else
102  {
103  msg_error("operators", "Cannot transform axis with index: " << axis_index << "for array with rank: "
104  << XArgType::rank::value << eom);
105  }
106  }
107 
112 
117 
118  protected:
119  //default...does nothing
127  template< typename XCheckType = XArgType >
128  typename std::enable_if< !std::is_base_of< MHO_TableContainerBase, XCheckType >::value, void >::type
129  IfTableTransformAxis(XArgType* , std::size_t ){};
130 
131  //use SFINAE to generate specialization for MHO_TableContainer types
139  template< typename XCheckType = XArgType >
140  typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value, void >::type
141  IfTableTransformAxis(XArgType* in, std::size_t axis_index)
142  {
144  {
145  if(fAxesToXForm[axis_index]) //only xform axis if this dimension was transformed
146  {
147  TransformAxis axis_xformer;
148  apply_at< typename XArgType::axis_pack_tuple_type, TransformAxis >(*in, axis_index, axis_xformer);
149  }
150  }
151  }
152 
157  {
158  public:
161 
162  //generic axis, do nothing
163  template< typename XAxisType > void operator()(XAxisType& ){};
164 
165  //overload for doubles
167  {
168  //this is under the expectation that all axis labels are equi-spaced
169  //this should be a safe assumption since we are doing DFT anyway
170  //one issue here is that we are not taking into account units (e.g. nanosec or MHz)
171  std::size_t N = axis1.GetSize();
172  double length = N;
173  if(N > 1)
174  {
175  double delta = axis1(1) - axis1(0);
176  double spacing = (1.0 / delta) * (1.0 / length);
177  double start = 0; //-1*length/2;
178  for(std::size_t i = 0; i < N; i++)
179  {
180  double x = i;
181  if(i < N / 2)
182  {
183  start = 0;
184  double value = (x + start) * spacing;
185  axis1(i) = value;
186  }
187  else
188  {
189  start = -1 * length;
190  double value = (x + start) * spacing;
191  axis1(i) = value;
192  }
193  }
194  }
195  }
196 
197  //overload for floats
199  {
200  //this is under the expectation that all axis labels are equi-spaced
201  //this should be a safe assumption since we are doing DFT anyway
202  //one issue here is that we are not taking into account units (e.g. nanosec or MHz)
203  std::size_t N = axis1.GetSize();
204  float length = N;
205  if(N > 1)
206  {
207  float delta = axis1(1) - axis1(0);
208  float spacing = (1.0 / delta) * (1.0 / length);
209  float start = 0; //-1*length/2;
210  for(std::size_t i = 0; i < N; i++)
211  {
212  float x = i;
213  if(i < N / 2)
214  {
215  start = 0;
216  float value = (x + start) * spacing;
217  axis1(i) = value;
218  }
219  else
220  {
221  start = -1 * length;
222  float value = (x + start) * spacing;
223  axis1(i) = value;
224  }
225  }
226  }
227  }
228  };
229 
230  //data
231  bool fIsValid;
232  bool fForward;
235 
236  size_t fDimensionSize[XArgType::rank::value];
237  bool fAxesToXForm[XArgType::rank::value];
238 };
239 
240 } // namespace hops
241 
242 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
template meta-programming helper functions, mostly tuple access/modification
Class TransformAxis.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:157
TransformAxis()
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:159
~TransformAxis()
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:160
void operator()(MHO_Axis< double > &axis1)
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:166
void operator()(XAxisType &)
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:163
void operator()(MHO_Axis< float > &axis1)
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:198
Class MHO_MultidimensionalFastFourierTransformInterface.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:25
size_t fDimensionSize[XArgType::rank::value]
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:236
std::enable_if< !std::is_base_of< MHO_TableContainerBase, XCheckType >::value, void >::type IfTableTransformAxis(XArgType *, std::size_t)
Transforms axis of input data if transformation is enabled and axis was transformed.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:129
MHO_MultidimensionalFastFourierTransformInterface()
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:32
bool fTransformAxisLabels
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:234
typename XArgType::value_type::value_type floating_point_value_type
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:30
virtual ~MHO_MultidimensionalFastFourierTransformInterface()
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:46
virtual void SetBackward()
Setter for backward.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:58
virtual void SelectAxis(std::size_t axis_index)
Selects an axis for transformation if within array rank.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:94
typename XArgType::value_type complex_value_type
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:29
bool fForward
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:232
virtual void SetForward()
Setter for forward.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:52
void EnableAxisLabelTransformation()
Enables transformation for axis labels.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:111
bool fIsValid
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:231
virtual void DeselectAllAxes()
Deselects all axes by setting fAxesToXForm to false and resetting initialization.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:79
bool fAxesToXForm[XArgType::rank::value]
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:237
bool fInitialized
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:233
std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value, void >::type IfTableTransformAxis(XArgType *in, std::size_t axis_index)
Transforms axis of input table if specified dimension was transformed.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:141
void DisableAxisLabelTransformation()
Disables axis label transformation by setting fTransformAxisLabels to false.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:116
virtual void SelectAllAxes()
Selects all axes for transformation.
Definition: MHO_MultidimensionalFastFourierTransformInterface.hh:66
std::size_t GetSize() const
Getter for size.
Definition: MHO_NDArrayWrapper_1.hh:107
Definition: MHO_ChannelLabeler.hh:17
Definition: MHO_Meta.hh:341
Definition: vex.h:175