Universal Numbers Library C++ API
sw::universal -- header-only custom arithmetic types (posit, cfloat, lns, fixpnt, dd/qd, and more)
Loading...
Searching...
No Matches
sw::universal::TrackedStatistical< T, Model > Class Template Reference

TrackedStatistical provides fast, approximate error tracking using ULP statistics. More...

#include <tracked_statistical.hpp>

Public Types

using value_type = T

Public Member Functions

constexpr TrackedStatistical () noexcept
 Default constructor: zero value.
 TrackedStatistical (T v) noexcept
 Construct from value (exact, no error yet).
 TrackedStatistical (T v, double ulp_err, size_t ops) noexcept
 Construct with known error state.
constexpr TrackedStatistical (const TrackedStatistical &) noexcept=default
constexpr TrackedStatistical (TrackedStatistical &&) noexcept=default
constexpr TrackedStatistical & operator= (const TrackedStatistical &) noexcept=default
constexpr TrackedStatistical & operator= (TrackedStatistical &&) noexcept=default
template<typename U>
TrackedStatistical & operator= (U v) noexcept
T value () const noexcept
 Get the computed value.
double ulp_error () const noexcept
 Get accumulated ULP error estimate.
size_t operations () const noexcept
 Get total operation count.
 operator T () const noexcept
 Implicit conversion to underlying type.
double error () const noexcept
 Get absolute error estimate.
double relative_error () const noexcept
 Get relative error estimate.
double valid_bits () const noexcept
 Estimate valid bits of precision, clamped to [0, the type's mantissa].
bool is_exact () const noexcept
 Check if value is still considered exact (no operations performed).
TrackedStatistical operator+ (const TrackedStatistical &rhs) const
TrackedStatistical operator- (const TrackedStatistical &rhs) const
TrackedStatistical operator- () const
TrackedStatistical operator* (const TrackedStatistical &rhs) const
TrackedStatistical operator/ (const TrackedStatistical &rhs) const
TrackedStatistical & operator+= (const TrackedStatistical &rhs)
TrackedStatistical & operator-= (const TrackedStatistical &rhs)
TrackedStatistical & operator*= (const TrackedStatistical &rhs)
TrackedStatistical & operator/= (const TrackedStatistical &rhs)
bool operator< (const TrackedStatistical &rhs) const noexcept
bool operator> (const TrackedStatistical &rhs) const noexcept
bool operator<= (const TrackedStatistical &rhs) const noexcept
bool operator>= (const TrackedStatistical &rhs) const noexcept
bool operator== (const TrackedStatistical &rhs) const noexcept
bool operator!= (const TrackedStatistical &rhs) const noexcept
bool definitely_different (const TrackedStatistical &rhs) const noexcept
 Are values definitely different (non-overlapping error regions)?
bool possibly_equal (const TrackedStatistical &rhs) const noexcept
 Could values be equal (overlapping error regions)?
void report (std::ostream &os) const

Static Public Member Functions

static constexpr const char * model_name () noexcept
 Get the error model name.
static constexpr const char * strategy_name () noexcept
 Get strategy name.
static double combine_errors (double err1, double err2, double op_cost) noexcept
 Combine errors from two operands plus new operation error.
static double add_operation_error (double current_err, double op_cost) noexcept
 Add new operation error to existing error.

Static Public Attributes

static constexpr ErrorModel model = Model
static constexpr double ADD_COST = 0.5
static constexpr double MUL_COST = 0.5
static constexpr double DIV_COST = 0.5
static constexpr double SQRT_COST = 0.5
static constexpr double TRANS_COST = 1.0

Friends

std::ostream & operator<< (std::ostream &os, const TrackedStatistical &v)

Detailed Description

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
class sw::universal::TrackedStatistical< T, Model >

TrackedStatistical provides fast, approximate error tracking using ULP statistics.

Template Parameters
TThe underlying scalar type (float, double, long double)
ModelError accumulation model (RandomWalk or Linear)

Error is estimated based on operation count and the statistical model, without computing actual reference values. This makes it very fast but only provides estimates, not exact errors.

Member Typedef Documentation

◆ value_type

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
using sw::universal::TrackedStatistical< T, Model >::value_type = T

Constructor & Destructor Documentation

◆ TrackedStatistical() [1/5]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
sw::universal::TrackedStatistical< T, Model >::TrackedStatistical ( )
inlineconstexprnoexcept

Default constructor: zero value.

◆ TrackedStatistical() [2/5]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
sw::universal::TrackedStatistical< T, Model >::TrackedStatistical ( T v)
inlinenoexcept

Construct from value (exact, no error yet).

◆ TrackedStatistical() [3/5]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
sw::universal::TrackedStatistical< T, Model >::TrackedStatistical ( T v,
double ulp_err,
size_t ops )
inlinenoexcept

Construct with known error state.

◆ TrackedStatistical() [4/5]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
sw::universal::TrackedStatistical< T, Model >::TrackedStatistical ( const TrackedStatistical< T, Model > & )
constexprdefaultnoexcept

◆ TrackedStatistical() [5/5]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
sw::universal::TrackedStatistical< T, Model >::TrackedStatistical ( TrackedStatistical< T, Model > && )
constexprdefaultnoexcept

Member Function Documentation

◆ add_operation_error()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::add_operation_error ( double current_err,
double op_cost )
inlinestaticnoexcept

Add new operation error to existing error.

◆ combine_errors()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::combine_errors ( double err1,
double err2,
double op_cost )
inlinestaticnoexcept

Combine errors from two operands plus new operation error.

◆ definitely_different()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
bool sw::universal::TrackedStatistical< T, Model >::definitely_different ( const TrackedStatistical< T, Model > & rhs) const
inlinenoexcept

Are values definitely different (non-overlapping error regions)?

◆ error()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::error ( ) const
inlinenoexcept

Get absolute error estimate.

A non-finite value has no ULP to scale by, so the error is unbounded rather than the NaN that ulp(inf) used to produce (#1546).

◆ is_exact()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
bool sw::universal::TrackedStatistical< T, Model >::is_exact ( ) const
inlinenoexcept

Check if value is still considered exact (no operations performed).

◆ model_name()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
constexpr const char * sw::universal::TrackedStatistical< T, Model >::model_name ( )
inlinestaticconstexprnoexcept

Get the error model name.

◆ operations()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
size_t sw::universal::TrackedStatistical< T, Model >::operations ( ) const
inlinenoexcept

Get total operation count.

◆ operator T()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
sw::universal::TrackedStatistical< T, Model >::operator T ( ) const
inlinenoexcept

Implicit conversion to underlying type.

◆ operator!=()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
bool sw::universal::TrackedStatistical< T, Model >::operator!= ( const TrackedStatistical< T, Model > & rhs) const
inlinenoexcept

◆ operator*()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical sw::universal::TrackedStatistical< T, Model >::operator* ( const TrackedStatistical< T, Model > & rhs) const
inline

◆ operator*=()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical & sw::universal::TrackedStatistical< T, Model >::operator*= ( const TrackedStatistical< T, Model > & rhs)
inline

◆ operator+()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical sw::universal::TrackedStatistical< T, Model >::operator+ ( const TrackedStatistical< T, Model > & rhs) const
inline

◆ operator+=()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical & sw::universal::TrackedStatistical< T, Model >::operator+= ( const TrackedStatistical< T, Model > & rhs)
inline

◆ operator-() [1/2]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical sw::universal::TrackedStatistical< T, Model >::operator- ( ) const
inline

◆ operator-() [2/2]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical sw::universal::TrackedStatistical< T, Model >::operator- ( const TrackedStatistical< T, Model > & rhs) const
inline

◆ operator-=()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical & sw::universal::TrackedStatistical< T, Model >::operator-= ( const TrackedStatistical< T, Model > & rhs)
inline

◆ operator/()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical sw::universal::TrackedStatistical< T, Model >::operator/ ( const TrackedStatistical< T, Model > & rhs) const
inline

◆ operator/=()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical & sw::universal::TrackedStatistical< T, Model >::operator/= ( const TrackedStatistical< T, Model > & rhs)
inline

◆ operator<()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
bool sw::universal::TrackedStatistical< T, Model >::operator< ( const TrackedStatistical< T, Model > & rhs) const
inlinenoexcept

◆ operator<=()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
bool sw::universal::TrackedStatistical< T, Model >::operator<= ( const TrackedStatistical< T, Model > & rhs) const
inlinenoexcept

◆ operator=() [1/3]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical & sw::universal::TrackedStatistical< T, Model >::operator= ( const TrackedStatistical< T, Model > & )
constexprdefaultnoexcept

◆ operator=() [2/3]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
TrackedStatistical & sw::universal::TrackedStatistical< T, Model >::operator= ( TrackedStatistical< T, Model > && )
constexprdefaultnoexcept

◆ operator=() [3/3]

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
template<typename U>
TrackedStatistical & sw::universal::TrackedStatistical< T, Model >::operator= ( U v)
inlinenoexcept

◆ operator==()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
bool sw::universal::TrackedStatistical< T, Model >::operator== ( const TrackedStatistical< T, Model > & rhs) const
inlinenoexcept

◆ operator>()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
bool sw::universal::TrackedStatistical< T, Model >::operator> ( const TrackedStatistical< T, Model > & rhs) const
inlinenoexcept

◆ operator>=()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
bool sw::universal::TrackedStatistical< T, Model >::operator>= ( const TrackedStatistical< T, Model > & rhs) const
inlinenoexcept

◆ possibly_equal()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
bool sw::universal::TrackedStatistical< T, Model >::possibly_equal ( const TrackedStatistical< T, Model > & rhs) const
inlinenoexcept

Could values be equal (overlapping error regions)?

◆ relative_error()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::relative_error ( ) const
inlinenoexcept

Get relative error estimate.

◆ report()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
void sw::universal::TrackedStatistical< T, Model >::report ( std::ostream & os) const
inline

◆ strategy_name()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
constexpr const char * sw::universal::TrackedStatistical< T, Model >::strategy_name ( )
inlinestaticconstexprnoexcept

Get strategy name.

◆ ulp_error()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::ulp_error ( ) const
inlinenoexcept

Get accumulated ULP error estimate.

◆ valid_bits()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::valid_bits ( ) const
inlinenoexcept

Estimate valid bits of precision, clamped to [0, the type's mantissa].

◆ value()

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
T sw::universal::TrackedStatistical< T, Model >::value ( ) const
inlinenoexcept

Get the computed value.

◆ operator<<

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
std::ostream & operator<< ( std::ostream & os,
const TrackedStatistical< T, Model > & v )
friend

Member Data Documentation

◆ ADD_COST

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::ADD_COST = 0.5
staticconstexpr

◆ DIV_COST

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::DIV_COST = 0.5
staticconstexpr

◆ model

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
ErrorModel sw::universal::TrackedStatistical< T, Model >::model = Model
staticconstexpr

◆ MUL_COST

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::MUL_COST = 0.5
staticconstexpr

◆ SQRT_COST

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::SQRT_COST = 0.5
staticconstexpr

◆ TRANS_COST

template<typename T, ErrorModel Model = ErrorModel::RandomWalk>
double sw::universal::TrackedStatistical< T, Model >::TRANS_COST = 1.0
staticconstexpr

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