15 #ifndef BORNAGAIN_BASE_UTILS_ALGORITHMS_H
16 #define BORNAGAIN_BASE_UTILS_ALGORITHMS_H
32 constexpr
double eps = std::numeric_limits<double>::epsilon();
33 return std::abs(a - b) <=
eps * std::max(
eps, (std::abs(a) + std::abs(b)) / 2);
37 template <
typename Evaluator,
typename Iterator>
38 double min_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate);
41 template <
typename Evaluator,
typename Iterator>
42 double max_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate);
45 template <
class T> std::vector<T>
concat(
const std::vector<T>& v1,
const std::vector<T>& v2);
53 template <
typename Evaluator,
typename Iterator>
54 double algo::min_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate)
57 double ret = evaluate(*begin);
60 ret = std::min(ret, evaluate(*it));
64 template <
typename Evaluator,
typename Iterator>
65 double algo::max_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate)
68 double ret = evaluate(*begin);
71 ret = std::max(ret, evaluate(*it));
75 template <
class T> std::vector<T>
algo::concat(
const std::vector<T>& v1,
const std::vector<T>& v2)
77 std::vector<T> v = v1;
78 v.insert(v.end(), v2.begin(), v2.end());
Defines the macro ASSERT.
#define ASSERT(condition)
Some additions to standard library algorithms.
std::vector< T > concat(const std::vector< T > &v1, const std::vector< T > &v2)
Returns the concatenation of two std::vectors.
bool almostEqual(double a, double b)
Returns true if two doubles agree within machine epsilon.
double max_value(const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
Returns the maximum value of function evaluate as applied to the elements of an iterator range.
double min_value(const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
Returns the minimum value of function evaluate as applied to the elements of an iterator range.