6#ifndef THEORETICA_ITER_RESULT_H
7#define THEORETICA_ITER_RESULT_H
44 template<
typename Type = real>
116 explicit operator bool()
const {
140 return "Converged successfully";
142 return "Maximum iterations exceeded without converging to desired accuracy";
144 return "Algorithm stalled";
146 return "Invalid input provided";
148 return "Algorithm diverged";
150 return "Unknown status";
155#ifndef THEORETICA_NO_PRINT
160 std::stringstream
res;
174 return out <<
obj.to_string();
A class for representing mathematical errors.
Definition error.h:109
Mathematical constants and default algorithm parameters.
Error handling for IO operations.
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
double real
A real number, defined as a floating point type.
Definition constants.h:207
Vector make_error()
Create a vector representing an error state, with all NaN values.
Definition algebra.h:103
@ NoConvergence
Algorithm did not converge.
TH_CONSTEXPR real inf()
Get positive infinity in floating point representation.
Definition error.h:96
ConvergenceStatus
Status codes for iterative algorithm termination.
Definition iter_result.h:19
@ Stalled
No progress in iterations.
@ Success
Algorithm converged successfully.
@ Diverged
Algorithm diverged.
@ MaxIterations
Maximum iterations exceeded.
@ InvalidInput
Invalid input provided.
A structure returned by iterative algorithms containing the computed value, convergence information,...
Definition iter_result.h:45
iter_result(const Type &value, unsigned int iterations)
Construct with final result for reporting success.
Definition iter_result.h:72
friend std::ostream & operator<<(std::ostream &out, const iter_result< Type > &obj)
Stream the complex number in string representation to an output stream (std::ostream)
Definition iter_result.h:173
real residual
Final error or residual norm (exact meaning depends on the algorithm)
Definition iter_result.h:57
iter_result()
Construct with default values.
Definition iter_result.h:61
std::string status_string() const
Get a human-readable string description of the status of convergence of an iterative algorithm.
Definition iter_result.h:136
unsigned int iterations
Number of iterations performed.
Definition iter_result.h:54
iter_result(const Type &value, unsigned int iterations, real residual)
Construct with final result for reporting success.
Definition iter_result.h:79
Type safe() const
Returns the computed value in a safe way, checking for convergence and throwing an exception if the a...
Definition iter_result.h:123
std::string to_string() const
Convert the iter_result number to string representation.
Definition iter_result.h:158
iter_result(ConvergenceStatus status, unsigned int iterations, real residual)
Construct with convergence status for reporting failure.
Definition iter_result.h:93
iter_result(const Type &value, ConvergenceStatus status, unsigned int iterations, real residual)
Construct with all fields specified.
Definition iter_result.h:99
iter_result(const Type &val)
Construct with final result for reporting success.
Definition iter_result.h:67
Type value
Best estimate of the result.
Definition iter_result.h:48
iter_result(ConvergenceStatus status, unsigned int iterations=0)
Construct with convergence status for reporting failure.
Definition iter_result.h:87
ConvergenceStatus status
Status code indicating reason for termination.
Definition iter_result.h:51
bool converged() const
Check if the algorithm converged successfully.
Definition iter_result.h:110