20template <
typename IteratorType>
21using IteratedValueType =
22 typename std::iterator_traits<IteratorType>::value_type;
28 m_toleranceLinear (toleranceLinear)
31 template <
typename IteratorType>
32 bool operator() (IteratorType begin, IteratorType end)
const
37 const auto toleranceLinear =
static_cast<IteratedValueType<IteratorType>> (m_toleranceLinear);
38 const IteratedValueType<IteratorType> referenceValue = *begin;
41 for (IteratorType it = begin; it != end; ++it)
42 if (floatsNotEqual (*it, referenceValue, toleranceLinear))
48 const double m_toleranceLinear;
55 m_targetValue (targetValue),
56 m_toleranceLinear (toleranceLinear)
59 template <
typename IteratorType>
60 bool operator() (IteratorType begin, IteratorType end)
const
65 const auto targetValue =
static_cast<IteratedValueType<IteratorType>> (m_targetValue);
66 const auto toleranceLinear =
static_cast<IteratedValueType<IteratorType>> (m_toleranceLinear);
68 for (IteratorType it = begin; it != end; ++it)
69 if (floatsNotEqual (*it, targetValue, toleranceLinear))
75 const double m_targetValue;
76 const double m_toleranceLinear;
83 template <
typename IteratorType>
84 bool operator() (IteratorType begin, IteratorType end)
const
86 for (IteratorType it = begin; it != end; ++it)
98 template <
typename IteratorType>
99 bool operator() (IteratorType begin, IteratorType end)
const
104 for (IteratorType it = begin; it != end; ++it)
105 if (! std::isnan (*it))
116 template <
typename IteratorType>
117 size_t
operator() (IteratorType begin, IteratorType end)
const
122 return static_cast<size_t> (std::distance (begin, std::max_element (begin, end)));
130 template <
typename IteratorType>
131 size_t
operator() (IteratorType begin, IteratorType end)
const
136 return static_cast<size_t> (std::distance (begin, std::min_element (begin, end)));
143 template <
typename IteratorType>
144 std::vector<IteratedValueType<IteratorType>>
145 operator() (IteratorType begin, IteratorType end)
const
147 return std::vector<IteratedValueType<IteratorType>> (begin, end);
154 template <
typename IteratorType>
155 IteratedValueType<IteratorType>
156 operator() (IteratorType begin, IteratorType end)
const
169 template <
typename IteratorType>
170 IteratedValueType<IteratorType>
171 operator() (IteratorType begin, IteratorType end)
const
183 template <
typename IteratorType>
184 IteratedValueType<IteratorType>
185 operator() (IteratorType begin, IteratorType end)
const
190 return *std::max_element (begin, end);
197 template <
typename IteratorType>
198 IteratedValueType<IteratorType>
199 operator() (IteratorType begin, IteratorType end)
const
204 AccurateSum<IteratedValueType<IteratorType>> accurateSum;
207 for (IteratorType it = begin; it != end; ++it)
213 return accurateSum.
template get<IteratedValueType<IteratorType>>() / count;
220 template <
typename IteratorType>
221 IteratedValueType<IteratorType>
222 operator() (IteratorType begin, IteratorType end)
const
227 return *std::min_element (begin, end);
236 nth (size_t targetIndex) : n_targetIndex (targetIndex) {}
238 template <
typename IteratorType>
239 IteratedValueType<IteratorType>
240 operator() (IteratorType begin, IteratorType end)
const
245 IteratorType iterator = begin;
247 for (size_t i = 0; i < n_targetIndex; ++i)
258 const size_t n_targetIndex;
267 m_quantile (quantile),
268 m_interpolation (interpolation)
272 template <
typename IteratorType>
273 auto operator() (IteratorType begin, IteratorType end)
const
274 -> IteratedValueType<IteratorType>
278 using ValueType = IteratedValueType<IteratorType>;
280 if (m_quantile < 0 || m_quantile > 1)
286 const size_t n =
static_cast<size_t> (std::distance (begin, end));
287 std::vector<ValueType> data (begin, end);
292 const size_t index =
static_cast<size_t> (std::ceil (m_quantile * (n - 1)));
294 std::nth_element (data.begin(), data.begin() + index, data.end());
301 const double pos = m_quantile * (n - 1);
302 const size_t i0 =
static_cast<size_t> (std::floor (pos));
303 const size_t i1 =
static_cast<size_t> (std::ceil (pos));
304 const double t = pos - i0;
306 std::nth_element (data.begin(), data.begin() + i0, data.end());
307 const ValueType v0 = data[i0];
312 std::nth_element (data.begin(), data.begin() + i1, data.end());
313 const ValueType v1 = data[i1];
315 return (v0 + (v1 - v0) *
static_cast<ValueType> (t));
320 const double m_quantile;
327 template <
typename IteratorType>
328 IteratedValueType<IteratorType>
329 operator() (IteratorType begin, IteratorType end)
const
334 const auto largestValue = *std::max_element (begin, end);
335 const auto smallestValue = *std::min_element (begin, end);
336 return largestValue - smallestValue;
343 template <
typename IteratorType>
344 size_t
operator() (IteratorType begin, IteratorType end)
const
346 return static_cast<size_t> (std::distance (begin, end));
353 template <
typename IteratorType>
354 IteratedValueType<IteratorType>
355 operator() (IteratorType begin, IteratorType end)
const
360 AccurateSum<IteratedValueType<IteratorType>> accurateSum;
362 for (IteratorType it = begin; it != end; ++it)
Implements Kahan algorithm for floating point accumulations.
Thrown when a container index is out of range.
Thrown when an unexpected container size is encountered.
Thrown when an inappropriate value is encountered.
#define hassert(condition)
Triggers a HartAssertException if the condition is false
#define HART_THROW_OR_RETURN(ExceptionType, message, returnValue)
Throws an exception if HART_DO_NOT_THROW_EXCEPTIONS is set, prints a message and returns a specified ...
Interpolation
Interpolation method.
Returns true if all the values in the range are equal to each other within provided tolerance,...
allFloatsEqualToEachOther(double toleranceLinear=1e-8)
bool operator()(IteratorType begin, IteratorType end) const
Returns true if all the values in the range are equal to a specific value within provided tolerance,...
allFloatsEqualTo(double targetValue, double toleranceLinear=1e-8)
bool operator()(IteratorType begin, IteratorType end) const
Returns true if all elements in the range are NaN
bool operator()(IteratorType begin, IteratorType end) const
Returns true if at least one element in the range is NaN
bool operator()(IteratorType begin, IteratorType end) const
Returns the zero-based index of the largest element in the range.
size_t operator()(IteratorType begin, IteratorType end) const
Returns the zero-based index of the smallest element in the range.
size_t operator()(IteratorType begin, IteratorType end) const
Forwards the entire range as an std::vector, preserving the original order.
std::vector< IteratedValueType< IteratorType > > operator()(IteratorType begin, IteratorType end) const
Returns the first element in the range.
IteratedValueType< IteratorType > operator()(IteratorType begin, IteratorType end) const
Returns the last element in the range.
IteratedValueType< IteratorType > operator()(IteratorType begin, IteratorType end) const
Returns the largest element in the range.
IteratedValueType< IteratorType > operator()(IteratorType begin, IteratorType end) const
Returns the arithmetic mean of all elements in the range.
IteratedValueType< IteratorType > operator()(IteratorType begin, IteratorType end) const
Returns the smallest element in the range.
IteratedValueType< IteratorType > operator()(IteratorType begin, IteratorType end) const
Returns the nth element in the range (zero-based)
IteratedValueType< IteratorType > operator()(IteratorType begin, IteratorType end) const
Returns the percentile value.
auto operator()(IteratorType begin, IteratorType end) const -> IteratedValueType< IteratorType >
percentile(double quantile, Interpolation interpolation=Interpolation::nearest)
Returns the difference between largest and smallest values in the range.
IteratedValueType< IteratorType > operator()(IteratorType begin, IteratorType end) const
Returns the number of elements (values) in the range.
size_t operator()(IteratorType begin, IteratorType end) const
Returns the sum of all elements in the range.
IteratedValueType< IteratorType > operator()(IteratorType begin, IteratorType end) const