NumCpp  2.1.0
A C++ implementation of the Python Numpy library
Iteration.hpp
Go to the documentation of this file.
1 #pragma once
34 
36 #include "NumCpp/Core/Types.hpp"
37 
38 #include <functional>
39 
40 namespace nc
41 {
42  namespace roots
43  {
44  //================================================================================
45  // Class Description:
47  class Iteration
48  {
49  public:
50  //============================================================================
51  // Method Description:
56  explicit Iteration(double epsilon) noexcept :
57  epsilon_(epsilon)
58  {}
59 
60  //============================================================================
61  // Method Description:
67  Iteration(double epsilon, uint32 maxNumIterations) noexcept :
68  epsilon_(epsilon),
69  maxNumIterations_(maxNumIterations)
70  {}
71 
72  //============================================================================
73  // Method Description:
76  virtual ~Iteration() noexcept = default;
77 
78  //============================================================================
79  // Method Description:
84  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  {
110  THROW_RUNTIME_ERROR("Maximum number of iterations has been reached; no root has been found within epsilon.");
111  }
112  }
113 
114  //====================================Attributes==============================
115  const double epsilon_;
118  };
119  } // namespace roots
120 } // namespace nc
nc::roots::Iteration::Iteration
Iteration(double epsilon, uint32 maxNumIterations) noexcept
Definition: Iteration.hpp:67
nc::roots::Iteration::Iteration
Iteration(double epsilon) noexcept
Definition: Iteration.hpp:56
Error.hpp
nc::roots::Iteration
ABC for iteration classes to derive from.
Definition: Iteration.hpp:47
nc::roots::Iteration::incrementNumberOfIterations
void incrementNumberOfIterations()
Definition: Iteration.hpp:105
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
nc::roots::Iteration::maxNumIterations_
uint32 maxNumIterations_
Definition: Iteration.hpp:116
nc::roots::Iteration::epsilon_
const double epsilon_
Definition: Iteration.hpp:115
nc::roots::Iteration::numIterations_
uint32 numIterations_
Definition: Iteration.hpp:117
nc::roots::Iteration::resetNumberOfIterations
void resetNumberOfIterations() noexcept
Definition: Iteration.hpp:94
THROW_RUNTIME_ERROR
#define THROW_RUNTIME_ERROR(msg)
Definition: Error.hpp:38
nc
Definition: Coordinate.hpp:45
nc::roots::Iteration::numIterations
uint32 numIterations() const noexcept
Definition: Iteration.hpp:84
Types.hpp
nc::roots::Iteration::~Iteration
virtual ~Iteration() noexcept=default