MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::itl::cyclic_iteration< Real > Class Template Reference

Prints residual every cycle iterations (cycle >= 1); prints a summary when the solver returns it as its int result, once. More...

#include <cyclic_iteration.hpp>

Inheritance diagram for mtl::itl::cyclic_iteration< Real >:
mtl::itl::basic_iteration< Real > mtl::itl::noisy_iteration< Real >

Public Member Functions

template<Vector V>
 cyclic_iteration (const V &r0, int max_iter, Real rtol, int cycle=100, Real atol=Real(0), std::ostream &out=std::cout)
 cyclic_iteration (Real norm_r0, int max_iter, Real rtol, int cycle=100, Real atol=Real(0), std::ostream &out=std::cout)
template<Vector V>
bool finished (const V &r)
 Test convergence; print residual every cycle iterations.
bool finished (Real r)
int error_code () const
 The error code, printing the summary the first time it is asked for.
 operator int () const
template<Vector V>
void reset (const V &r0)
 basic_iteration::reset, and the summary is printed again for the next solve (it printed only for the first, issue 888).
void reset (Real norm_r0)
Public Member Functions inherited from mtl::itl::basic_iteration< Real >
template<Vector V>
 basic_iteration (const V &r0, int max_iter, Real rtol, Real atol=Real(0))
 Construct from initial residual vector r0.
 basic_iteration (Real norm_r0, int max_iter, Real rtol, Real atol=Real(0))
 Construct from precomputed norm of r0.
template<Vector V>
void reset (const V &r0)
 Prepare the object for another solve (issue 888): the iteration count back to 0, the tolerance's reference norm to ||r0||, the residual, error and finished state cleared.
void reset (Real norm_r0)
 reset from a precomputed norm of r0, as the second constructor takes.
template<Vector V>
bool finished (const V &r)
 Test convergence given residual vector r.
bool finished (Real r)
 Test convergence given scalar residual norm.
template<Vector V>
bool converged_now (const V &r)
 Convergence test only, without the iteration-limit test: for a check in the middle of an iteration (bicgstab's half step, bicgstab_ell's BiCG part), where reaching max_iter must not cut the iteration short (issue 866).
bool converged_now (Real r)
basic_iteration & operator++ ()
 Pre-increment iteration counter.
basic_iteration operator++ (int)
 Post-increment iteration counter.
bool first () const
 Returns true if this is the first iteration (i <= 1).
 operator int () const
 Error code: 0 = converged, 1 = max_iter exceeded, 2-5 breakdown, 6 = non-finite residual.
int error_code () const
int iterations () const
Real resid () const
Real relresid () const
Real tol () const
Real atol () const
Real norm_r0 () const
void fail (int code, const std::string &)
 Signal solver breakdown or other failure.
bool is_finished () const

Static Protected Member Functions

static int checked_cycle (int cycle)

Protected Attributes

int cycle_
std::ostream & out_
bool reported_ = false
Protected Attributes inherited from mtl::itl::basic_iteration< Real >
int i_
int max_iter_
Real rtol_
Real atol_
Real my_norm_r0_
Real resid_
int error_
bool is_finished_

Additional Inherited Members

Static Public Attributes inherited from mtl::itl::basic_iteration< Real >
static constexpr int non_finite = 6
 Error code of a residual that is NaN or infinite.
static constexpr int not_positive_definite = 7
 Error code of a preconditioner found not to be positive definite: a v^H M^{-1} v negative beyond rounding, in a solver that requires an SPD (HPD) M.
Protected Member Functions inherited from mtl::itl::basic_iteration< Real >
bool converged (Real r) const

Detailed Description

template<typename Real>
class mtl::itl::cyclic_iteration< Real >

Prints residual every cycle iterations (cycle >= 1); prints a summary when the solver returns it as its int result, once.

Constructor & Destructor Documentation

◆ cyclic_iteration() [1/2]

template<typename Real>
template<Vector V>
mtl::itl::cyclic_iteration< Real >::cyclic_iteration ( const V & r0,
int max_iter,
Real rtol,
int cycle = 100,
Real atol = Real(0),
std::ostream & out = std::cout )
inline

◆ cyclic_iteration() [2/2]

template<typename Real>
mtl::itl::cyclic_iteration< Real >::cyclic_iteration ( Real norm_r0,
int max_iter,
Real rtol,
int cycle = 100,
Real atol = Real(0),
std::ostream & out = std::cout )
inline

Member Function Documentation

◆ checked_cycle()

template<typename Real>
int mtl::itl::cyclic_iteration< Real >::checked_cycle ( int cycle)
inlinestaticprotected

◆ error_code()

template<typename Real>
int mtl::itl::cyclic_iteration< Real >::error_code ( ) const
inline

The error code, printing the summary the first time it is asked for.

basic_iteration's error_code() and operator int() are not virtual, so this class declares its own operator int: return iter; from a solver templated on cyclic_iteration reaches it and prints (it went through the base and printed nothing, issue 866). gmres asks inside its restarts, which no longer repeats the summary.

◆ finished() [1/2]

template<typename Real>
template<Vector V>
bool mtl::itl::cyclic_iteration< Real >::finished ( const V & r)
inline

Test convergence; print residual every cycle iterations.

◆ finished() [2/2]

template<typename Real>
bool mtl::itl::cyclic_iteration< Real >::finished ( Real r)
inline

◆ operator int()

template<typename Real>
mtl::itl::cyclic_iteration< Real >::operator int ( ) const
inline

◆ reset() [1/2]

template<typename Real>
template<Vector V>
void mtl::itl::cyclic_iteration< Real >::reset ( const V & r0)
inline

basic_iteration::reset, and the summary is printed again for the next solve (it printed only for the first, issue 888).

noisy_iteration inherits it.

◆ reset() [2/2]

template<typename Real>
void mtl::itl::cyclic_iteration< Real >::reset ( Real norm_r0)
inline

Member Data Documentation

◆ cycle_

template<typename Real>
int mtl::itl::cyclic_iteration< Real >::cycle_
protected

◆ out_

template<typename Real>
std::ostream& mtl::itl::cyclic_iteration< Real >::out_
protected

◆ reported_

template<typename Real>
bool mtl::itl::cyclic_iteration< Real >::reported_ = false
mutableprotected

The documentation for this class was generated from the following file: