NumCpp  2.5.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
Iteration.hpp
Go to the documentation of this file.
1 #pragma once
33 
35 #include "NumCpp/Core/Types.hpp"
36 
37 #include <functional>
38 
39 namespace nc
40 {
41  namespace roots
42  {
43  //================================================================================
44  // Class Description:
46  class Iteration
47  {
48  public:
49  //============================================================================
50  // Method Description:
55  explicit Iteration(double epsilon) noexcept :
56  epsilon_(epsilon)
57  {}
58 
59  //============================================================================
60  // Method Description:
66  Iteration(double epsilon, uint32 maxNumIterations) noexcept :
67  epsilon_(epsilon),
68  maxNumIterations_(maxNumIterations)
69  {}
70 
71  //============================================================================
72  // Method Description:
75  virtual ~Iteration() noexcept = default;
76 
77  //============================================================================
78  // Method Description:
83  uint32 numIterations() const noexcept
84  {
85  return numIterations_;
86  }
87 
88  protected:
89  //============================================================================
90  // Method Description:
93  void resetNumberOfIterations() noexcept
94  {
95  numIterations_ = 0;
96  }
97 
98  //============================================================================
99  // Method Description:
105  {
106  ++numIterations_;
108  {
109  THROW_RUNTIME_ERROR("Maximum number of iterations has been reached; no root has been found within epsilon.");
110  }
111  }
112 
113  //====================================Attributes==============================
114  const double epsilon_;
117  };
118  } // namespace roots
119 } // namespace nc
#define THROW_RUNTIME_ERROR(msg)
Definition: Error.hpp:37
ABC for iteration classes to derive from.
Definition: Iteration.hpp:47
Iteration(double epsilon) noexcept
Definition: Iteration.hpp:55
virtual ~Iteration() noexcept=default
const double epsilon_
Definition: Iteration.hpp:114
Iteration(double epsilon, uint32 maxNumIterations) noexcept
Definition: Iteration.hpp:66
uint32 numIterations_
Definition: Iteration.hpp:116
void resetNumberOfIterations() noexcept
Definition: Iteration.hpp:93
uint32 maxNumIterations_
Definition: Iteration.hpp:115
uint32 numIterations() const noexcept
Definition: Iteration.hpp:83
void incrementNumberOfIterations()
Definition: Iteration.hpp:104
Definition: Coordinate.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40