6#ifndef THEORETICA_ITER_RESULT_H
7#define THEORETICA_ITER_RESULT_H
44 template<
typename Type = real>
99 operator Type()
const {
110 explicit operator bool()
const {
120 return "Converged successfully";
122 return "Maximum iterations exceeded without converging to desired accuracy";
124 return "Algorithm stalled";
126 return "Invalid input provided";
128 return "Algorithm diverged";
130 return "Unknown status";
135#ifndef THEORETICA_NO_PRINT
140 std::stringstream res;
142 res <<
"Value = " <<
value <<
"\n";
153 inline friend std::ostream&
operator<<(std::ostream& out,
const iter_result<Type>& obj) {
154 return out << obj.to_string();
Mathematical constants and default algorithm parameters.
Error handling with errno and exceptions.
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
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:78
TH_CONSTEXPR real inf()
Get positive infinity in floating point representation.
Definition error.h:100
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:70
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:153
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:116
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:77
std::string to_string() const
Convert the iter_result number to string representation.
Definition iter_result.h:138
iter_result(ConvergenceStatus status, unsigned int iterations, real residual)
Construct with convergence status for reporting failure.
Definition iter_result.h:91
iter_result(const Type &val)
Construct with final result for reporting success.
Definition iter_result.h:65
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:85
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:104