16 #error no need to expose this header to Swig
20 #ifndef BORNAGAIN_BASE_UTILS_ALGORITHMS_H
21 #define BORNAGAIN_BASE_UTILS_ALGORITHMS_H
36 constexpr
double eps = std::numeric_limits<double>::epsilon();
37 return std::abs(a - b) <= eps * std::max(eps, (std::abs(a) + std::abs(b)) / 2);
41 template <
typename Evaluator,
typename Iterator>
42 double min_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate);
45 template <
typename Evaluator,
typename Iterator>
46 double max_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate);
49 template <
class T> std::vector<T>
concat(
const std::vector<T>& v1,
const std::vector<T>& v2);
57 template <
typename Evaluator,
typename Iterator>
58 double algo::min_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate)
61 double ret = evaluate(*begin);
64 ret = std::min(ret, evaluate(*it));
68 template <
typename Evaluator,
typename Iterator>
69 double algo::max_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate)
72 double ret = evaluate(*begin);
75 ret = std::max(ret, evaluate(*it));
79 template <
class T> std::vector<T>
algo::concat(
const std::vector<T>& v1,
const std::vector<T>& v2)
81 std::vector<T> v = v1;
82 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.