HOPS
HOPS class reference
MHO_ExtremaSearch.hh
Go to the documentation of this file.
1 #ifndef MHO_ExtremaSearch_HH__
2 #define MHO_ExtremaSearch_HH__
3 
4 #include <algorithm>
5 #include <cstdint>
6 #include <limits>
7 
9 #include "MHO_Message.hh"
10 #include "MHO_Meta.hh"
11 #include "MHO_NDArrayWrapper.hh"
12 #include "MHO_TableContainer.hh"
13 
14 namespace hops
15 {
16 
28 template< class XArgType > class MHO_ExtremaSearch: public MHO_InspectingOperator< XArgType >
29 {
30  public:
32  virtual ~MHO_ExtremaSearch(){};
33 
39  double GetMax() { return fMax; }
40 
46  double GetMin() { return fMin; }
47 
53  std::size_t GetMaxLocation() { return fMaxLocation; }
54 
60  std::size_t GetMinLocation() { return fMinLocation; }
61 
62  protected:
70  virtual bool InitializeImpl(const XArgType* ) override { return true; };
71 
79  virtual bool ExecuteImpl(const XArgType* in) override
80  {
81  Search(in);
82  return true;
83  }
84 
85  private:
86  // basic floating point types
94  template< typename XCheckType = typename XArgType::value_type >
95  typename std::enable_if< std::is_floating_point< XCheckType >::value, void >::type Search(const XArgType* in)
96  {
97  using fp_value_type = typename XArgType::value_type;
98  fMaxLocation = 0;
99  fMinLocation = 0;
102  fp_value_type value;
103  auto bit = in->cbegin();
104  auto eit = in->cend();
105  std::size_t i = 0;
106  for(auto it = bit; it != eit; it++)
107  {
108  value = *it;
109  if(value > fMax)
110  {
111  fMax = value;
112  fMaxLocation = i;
113  }
114  if(value < fMin)
115  {
116  fMin = value;
117  fMinLocation = i;
118  }
119  i++;
120  }
121  };
122 
123  //specialization for complex types
131  template< typename XCheckType = typename XArgType::value_type >
132  typename std::enable_if< is_complex< XCheckType >::value, void >::type Search(const XArgType* in)
133  {
134  using fp_value_type = typename XArgType::value_type::value_type;
135  fMaxLocation = 0;
136  fMinLocation = 0;
139  fp_value_type value;
140  auto bit = in->cbegin();
141  auto eit = in->cend();
142  std::size_t i = 0;
143  for(auto it = bit; it != eit; it++)
144  {
145  value = std::abs(*it);
146  if(value > fMax)
147  {
148  fMax = value;
149  fMaxLocation = i;
150  }
151  if(value < fMin)
152  {
153  fMin = value;
154  fMinLocation = i;
155  }
156  i++;
157  }
158  };
159 
160  double fMax;
161  double fMin;
162  std::size_t fMaxLocation;
163  std::size_t fMinLocation;
164 };
165 
166 }; // namespace hops
167 
168 #endif
template meta-programming helper functions, mostly tuple access/modification
Class MHO_ExtremaSearch.
Definition: MHO_ExtremaSearch.hh:29
std::size_t GetMinLocation()
Getter for min location (offset into the array)
Definition: MHO_ExtremaSearch.hh:60
MHO_ExtremaSearch()
Definition: MHO_ExtremaSearch.hh:31
std::size_t GetMaxLocation()
Getter for max location (offset into the array)
Definition: MHO_ExtremaSearch.hh:53
double GetMax()
Getter for maximum value across the array.
Definition: MHO_ExtremaSearch.hh:39
double GetMin()
Getter for minimum value across the.
Definition: MHO_ExtremaSearch.hh:46
virtual ~MHO_ExtremaSearch()
Definition: MHO_ExtremaSearch.hh:32
virtual bool InitializeImpl(const XArgType *) override
Initializes the operator.
Definition: MHO_ExtremaSearch.hh:70
virtual bool ExecuteImpl(const XArgType *in) override
Executes search operation using input argument and returns true.
Definition: MHO_ExtremaSearch.hh:79
Class MHO_InspectingOperator.
Definition: MHO_InspectingOperator.hh:22
#define min(a, b)
Definition: max555.c:9
#define max(a, b)
Definition: max555.c:10
Definition: MHO_ChannelLabeler.hh:17
Definition: vex.h:175