BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
algo Namespace Reference

Functions

bool almostEqual (double a, double b)
 
template<typename Evaluator , typename Iterator >
double min_value (const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
 
template<typename Evaluator , typename Iterator >
double max_value (const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
 
template<class T >
std::vector< T > concat (const std::vector< T > &v1, const std::vector< T > &v2)
 

Detailed Description

Some additions to standard library algorithms.

Function Documentation

◆ almostEqual()

bool algo::almostEqual ( double  a,
double  b 
)
inline

Returns true if two doubles agree within machine epsilon.

Definition at line 30 of file Algorithms.h.

31 {
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);
34 }

References anonymous_namespace{PolyhedralComponents.cpp}::eps.

Referenced by VerticalLine::contains(), HorizontalLine::contains(), CustomBinAxis::equals(), FixedBinAxis::equals(), VariableBinAxis::equals(), ConstKBinAxis::equals(), anonymous_namespace{SimulationToPython.cpp}::isDefaultDirection(), pyfmt::isHexagonal(), and pyfmt::isSquare().

◆ min_value()

template<typename Evaluator , typename Iterator >
double algo::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.

Definition at line 54 of file Algorithms.h.

55 {
56  ASSERT(begin != end);
57  double ret = evaluate(*begin);
58  Iterator it = begin;
59  while (++it != end)
60  ret = std::min(ret, evaluate(*it));
61  return ret;
62 }
#define ASSERT(condition)
Definition: Assert.h:26

References ASSERT.

Referenced by FormFactorWeighted::bottomZ(), IFormFactorBorn::BottomZ(), and TestMinimizer::minimize_scalar().

◆ max_value()

template<typename Evaluator , typename Iterator >
double algo::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.

Definition at line 65 of file Algorithms.h.

66 {
67  ASSERT(begin != end);
68  double ret = evaluate(*begin);
69  Iterator it = begin;
70  while (++it != end)
71  ret = std::max(ret, evaluate(*it));
72  return ret;
73 }

References ASSERT.

Referenced by FormFactorWeighted::topZ(), and IFormFactorBorn::TopZ().

◆ concat()

template<class T >
std::vector< T > algo::concat ( const std::vector< T > &  v1,
const std::vector< T > &  v2 
)

Returns the concatenation of two std::vectors.

Definition at line 75 of file Algorithms.h.

76 {
77  std::vector<T> v = v1;
78  v.insert(v.end(), v2.begin(), v2.end());
79  return v;
80 }

Referenced by nodeMetaUnion().