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  //profiler_scope();
82  Search(in);
83  return true;
84  }
85 
86  private:
87  // basic floating point types
95  template< typename XCheckType = typename XArgType::value_type >
96  typename std::enable_if< std::is_floating_point< XCheckType >::value, void >::type Search(const XArgType* in)
97  {
98  using fp_value_type = typename XArgType::value_type;
99  fMaxLocation = 0;
100  fMinLocation = 0;
101  fMax = std::numeric_limits< fp_value_type >::lowest();
103  fp_value_type value;
104  auto bit = in->cbegin();
105  auto eit = in->cend();
106  std::size_t i = 0;
107  for(auto it = bit; it != eit; it++)
108  {
109  value = *it;
110  if(value > fMax)
111  {
112  fMax = value;
113  fMaxLocation = i;
114  }
115  if(value < fMin)
116  {
117  fMin = value;
118  fMinLocation = i;
119  }
120  i++;
121  }
122  };
123 
124  //specialization for complex types
132  template< typename XCheckType = typename XArgType::value_type >
133  typename std::enable_if< is_complex< XCheckType >::value, void >::type Search(const XArgType* in)
134  {
135  using fp_value_type = typename XArgType::value_type::value_type;
136  fMaxLocation = 0;
137  fMinLocation = 0;
138  fMax = std::numeric_limits< fp_value_type >::lowest();
140  fp_value_type value;
141  auto bit = in->cbegin();
142  auto eit = in->cend();
143  std::size_t i = 0;
144  for(auto it = bit; it != eit; it++)
145  {
146  value = std::abs(*it);
147  if(value > fMax)
148  {
149  fMax = value;
150  fMaxLocation = i;
151  }
152  if(value < fMin)
153  {
154  fMin = value;
155  fMinLocation = i;
156  }
157  i++;
158  }
159  };
160 
161  double fMax;
162  double fMin;
163  std::size_t fMaxLocation;
164  std::size_t fMinLocation;
165 };
166 
167 }; // namespace hops
168 
169 #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:21
#define max(a, b)
Definition: max555.c:10
Definition: MHO_AdhocFlagging.hh:18
Definition: vex.h:175