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