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::TrackedLNS< LNSType, ShadowType > Class Template Reference

TrackedLNS provides specialized error tracking for LNS types exploiting the fact that multiplication is exact in log representation. More...

#include <tracked_lns.hpp>

Public Types

using value_type = LNSType
using shadow_type = ShadowType

Public Member Functions

constexpr TrackedLNS () noexcept
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr TrackedLNS (U v) noexcept
constexpr TrackedLNS (LNSType v) noexcept
constexpr TrackedLNS (LNSType v, ShadowType s, double err, uint64_t a, uint64_t m, uint64_t d, uint64_t c, uint64_t ab=0) noexcept
constexpr TrackedLNS (const TrackedLNS &) noexcept=default
constexpr TrackedLNS (TrackedLNS &&) noexcept=default
constexpr TrackedLNS & operator= (const TrackedLNS &) noexcept=default
constexpr TrackedLNS & operator= (TrackedLNS &&) noexcept=default
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr TrackedLNS & operator= (U v) noexcept
constexpr LNSType value () const noexcept
constexpr ShadowType shadow () const noexcept
constexpr operator LNSType () const noexcept
constexpr uint64_t additions () const noexcept
 Number of additions (the only error source in LNS).
constexpr uint64_t multiplications () const noexcept
 Number of multiplications (exact in LNS!).
constexpr uint64_t divisions () const noexcept
 Number of divisions (exact in LNS!).
constexpr uint64_t cancellations () const noexcept
 Number of near-cancellation events (a ~= -b).
constexpr uint64_t absorptions () const noexcept
 Number of absorption events (small operand swallowed).
constexpr bool had_absorption () const noexcept
 Did any absorption occur?
constexpr uint64_t operations () const noexcept
 Total operations.
constexpr uint64_t exact_operations () const noexcept
 Exact operations (mult + div in LNS).
double error () const noexcept
 Total error (difference from shadow).
double addition_error () const noexcept
 Error accumulated only from additions.
double relative_error () const noexcept
 Relative error.
double valid_bits () const noexcept
 Valid bits remaining, capped at type precision.
bool is_exact () const noexcept
 Is the result exact? (Only possible if no additions were performed).
bool had_cancellation () const noexcept
 Was there catastrophic cancellation?
TrackedLNS operator+ (const TrackedLNS &rhs) const
 Addition: THE ONLY SOURCE OF ERROR in LNS Also detects near-cancellation when a ~= -b and absorption when |a| >> |b|.
TrackedLNS operator- (const TrackedLNS &rhs) const
 Subtraction: Also introduces error (like addition) Detects cancellation when a ~= b and absorption when |a| >> |b|.
TrackedLNS operator- () const
 Unary minus: No error (just sign flip, preserves absorptions).
TrackedLNS operator* (const TrackedLNS &rhs) const
 Multiplication: EXACT in LNS!
TrackedLNS operator/ (const TrackedLNS &rhs) const
 Division: EXACT in LNS! No error introduced.
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS operator+ (U rhs) const
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS operator- (U rhs) const
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS operator* (U rhs) const
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS operator/ (U rhs) const
TrackedLNS & operator+= (const TrackedLNS &rhs)
TrackedLNS & operator-= (const TrackedLNS &rhs)
TrackedLNS & operator*= (const TrackedLNS &rhs)
TrackedLNS & operator/= (const TrackedLNS &rhs)
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS & operator+= (U rhs)
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS & operator-= (U rhs)
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS & operator*= (U rhs)
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS & operator/= (U rhs)
bool operator== (const TrackedLNS &rhs) const noexcept
bool operator!= (const TrackedLNS &rhs) const noexcept
bool operator< (const TrackedLNS &rhs) const noexcept
bool operator<= (const TrackedLNS &rhs) const noexcept
bool operator> (const TrackedLNS &rhs) const noexcept
bool operator>= (const TrackedLNS &rhs) const noexcept
void report (std::ostream &os) const

Detailed Description

template<typename LNSType, typename ShadowType = double>
class sw::universal::TrackedLNS< LNSType, ShadowType >

TrackedLNS provides specialized error tracking for LNS types exploiting the fact that multiplication is exact in log representation.

Member Typedef Documentation

◆ shadow_type

template<typename LNSType, typename ShadowType = double>
using sw::universal::TrackedLNS< LNSType, ShadowType >::shadow_type = ShadowType

◆ value_type

template<typename LNSType, typename ShadowType = double>
using sw::universal::TrackedLNS< LNSType, ShadowType >::value_type = LNSType

Constructor & Destructor Documentation

◆ TrackedLNS() [1/6]

template<typename LNSType, typename ShadowType = double>
sw::universal::TrackedLNS< LNSType, ShadowType >::TrackedLNS ( )
inlineconstexprnoexcept

◆ TrackedLNS() [2/6]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
sw::universal::TrackedLNS< LNSType, ShadowType >::TrackedLNS ( U v)
inlineconstexprnoexcept

◆ TrackedLNS() [3/6]

template<typename LNSType, typename ShadowType = double>
sw::universal::TrackedLNS< LNSType, ShadowType >::TrackedLNS ( LNSType v)
inlineconstexprnoexcept

◆ TrackedLNS() [4/6]

template<typename LNSType, typename ShadowType = double>
sw::universal::TrackedLNS< LNSType, ShadowType >::TrackedLNS ( LNSType v,
ShadowType s,
double err,
uint64_t a,
uint64_t m,
uint64_t d,
uint64_t c,
uint64_t ab = 0 )
inlineconstexprnoexcept

◆ TrackedLNS() [5/6]

template<typename LNSType, typename ShadowType = double>
sw::universal::TrackedLNS< LNSType, ShadowType >::TrackedLNS ( const TrackedLNS< LNSType, ShadowType > & )
constexprdefaultnoexcept

◆ TrackedLNS() [6/6]

template<typename LNSType, typename ShadowType = double>
sw::universal::TrackedLNS< LNSType, ShadowType >::TrackedLNS ( TrackedLNS< LNSType, ShadowType > && )
constexprdefaultnoexcept

Member Function Documentation

◆ absorptions()

template<typename LNSType, typename ShadowType = double>
uint64_t sw::universal::TrackedLNS< LNSType, ShadowType >::absorptions ( ) const
inlineconstexprnoexcept

Number of absorption events (small operand swallowed).

◆ addition_error()

template<typename LNSType, typename ShadowType = double>
double sw::universal::TrackedLNS< LNSType, ShadowType >::addition_error ( ) const
inlinenoexcept

Error accumulated only from additions.

◆ additions()

template<typename LNSType, typename ShadowType = double>
uint64_t sw::universal::TrackedLNS< LNSType, ShadowType >::additions ( ) const
inlineconstexprnoexcept

Number of additions (the only error source in LNS).

◆ cancellations()

template<typename LNSType, typename ShadowType = double>
uint64_t sw::universal::TrackedLNS< LNSType, ShadowType >::cancellations ( ) const
inlineconstexprnoexcept

Number of near-cancellation events (a ~= -b).

◆ divisions()

template<typename LNSType, typename ShadowType = double>
uint64_t sw::universal::TrackedLNS< LNSType, ShadowType >::divisions ( ) const
inlineconstexprnoexcept

Number of divisions (exact in LNS!).

◆ error()

template<typename LNSType, typename ShadowType = double>
double sw::universal::TrackedLNS< LNSType, ShadowType >::error ( ) const
inlinenoexcept

Total error (difference from shadow).

◆ exact_operations()

template<typename LNSType, typename ShadowType = double>
uint64_t sw::universal::TrackedLNS< LNSType, ShadowType >::exact_operations ( ) const
inlineconstexprnoexcept

Exact operations (mult + div in LNS).

◆ had_absorption()

template<typename LNSType, typename ShadowType = double>
bool sw::universal::TrackedLNS< LNSType, ShadowType >::had_absorption ( ) const
inlineconstexprnoexcept

Did any absorption occur?

◆ had_cancellation()

template<typename LNSType, typename ShadowType = double>
bool sw::universal::TrackedLNS< LNSType, ShadowType >::had_cancellation ( ) const
inlinenoexcept

Was there catastrophic cancellation?

◆ is_exact()

template<typename LNSType, typename ShadowType = double>
bool sw::universal::TrackedLNS< LNSType, ShadowType >::is_exact ( ) const
inlinenoexcept

Is the result exact? (Only possible if no additions were performed).

◆ multiplications()

template<typename LNSType, typename ShadowType = double>
uint64_t sw::universal::TrackedLNS< LNSType, ShadowType >::multiplications ( ) const
inlineconstexprnoexcept

Number of multiplications (exact in LNS!).

◆ operations()

template<typename LNSType, typename ShadowType = double>
uint64_t sw::universal::TrackedLNS< LNSType, ShadowType >::operations ( ) const
inlineconstexprnoexcept

Total operations.

◆ operator LNSType()

template<typename LNSType, typename ShadowType = double>
sw::universal::TrackedLNS< LNSType, ShadowType >::operator LNSType ( ) const
inlineconstexprnoexcept

◆ operator!=()

template<typename LNSType, typename ShadowType = double>
bool sw::universal::TrackedLNS< LNSType, ShadowType >::operator!= ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inlinenoexcept

◆ operator*() [1/2]

template<typename LNSType, typename ShadowType = double>
TrackedLNS sw::universal::TrackedLNS< LNSType, ShadowType >::operator* ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inline

Multiplication: EXACT in LNS!

No error introduced. This is the key advantage of LNS for multiply-heavy algorithms.

◆ operator*() [2/2]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS sw::universal::TrackedLNS< LNSType, ShadowType >::operator* ( U rhs) const
inline

◆ operator*=() [1/2]

template<typename LNSType, typename ShadowType = double>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator*= ( const TrackedLNS< LNSType, ShadowType > & rhs)
inline

◆ operator*=() [2/2]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator*= ( U rhs)
inline

◆ operator+() [1/2]

template<typename LNSType, typename ShadowType = double>
TrackedLNS sw::universal::TrackedLNS< LNSType, ShadowType >::operator+ ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inline

Addition: THE ONLY SOURCE OF ERROR in LNS Also detects near-cancellation when a ~= -b and absorption when |a| >> |b|.

◆ operator+() [2/2]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS sw::universal::TrackedLNS< LNSType, ShadowType >::operator+ ( U rhs) const
inline

◆ operator+=() [1/2]

template<typename LNSType, typename ShadowType = double>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator+= ( const TrackedLNS< LNSType, ShadowType > & rhs)
inline

◆ operator+=() [2/2]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator+= ( U rhs)
inline

◆ operator-() [1/3]

template<typename LNSType, typename ShadowType = double>
TrackedLNS sw::universal::TrackedLNS< LNSType, ShadowType >::operator- ( ) const
inline

Unary minus: No error (just sign flip, preserves absorptions).

◆ operator-() [2/3]

template<typename LNSType, typename ShadowType = double>
TrackedLNS sw::universal::TrackedLNS< LNSType, ShadowType >::operator- ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inline

Subtraction: Also introduces error (like addition) Detects cancellation when a ~= b and absorption when |a| >> |b|.

◆ operator-() [3/3]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS sw::universal::TrackedLNS< LNSType, ShadowType >::operator- ( U rhs) const
inline

◆ operator-=() [1/2]

template<typename LNSType, typename ShadowType = double>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator-= ( const TrackedLNS< LNSType, ShadowType > & rhs)
inline

◆ operator-=() [2/2]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator-= ( U rhs)
inline

◆ operator/() [1/2]

template<typename LNSType, typename ShadowType = double>
TrackedLNS sw::universal::TrackedLNS< LNSType, ShadowType >::operator/ ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inline

Division: EXACT in LNS! No error introduced.

◆ operator/() [2/2]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS sw::universal::TrackedLNS< LNSType, ShadowType >::operator/ ( U rhs) const
inline

◆ operator/=() [1/2]

template<typename LNSType, typename ShadowType = double>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator/= ( const TrackedLNS< LNSType, ShadowType > & rhs)
inline

◆ operator/=() [2/2]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator/= ( U rhs)
inline

◆ operator<()

template<typename LNSType, typename ShadowType = double>
bool sw::universal::TrackedLNS< LNSType, ShadowType >::operator< ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inlinenoexcept

◆ operator<=()

template<typename LNSType, typename ShadowType = double>
bool sw::universal::TrackedLNS< LNSType, ShadowType >::operator<= ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inlinenoexcept

◆ operator=() [1/3]

template<typename LNSType, typename ShadowType = double>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator= ( const TrackedLNS< LNSType, ShadowType > & )
constexprdefaultnoexcept

◆ operator=() [2/3]

template<typename LNSType, typename ShadowType = double>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator= ( TrackedLNS< LNSType, ShadowType > && )
constexprdefaultnoexcept

◆ operator=() [3/3]

template<typename LNSType, typename ShadowType = double>
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
TrackedLNS & sw::universal::TrackedLNS< LNSType, ShadowType >::operator= ( U v)
inlineconstexprnoexcept

◆ operator==()

template<typename LNSType, typename ShadowType = double>
bool sw::universal::TrackedLNS< LNSType, ShadowType >::operator== ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inlinenoexcept

◆ operator>()

template<typename LNSType, typename ShadowType = double>
bool sw::universal::TrackedLNS< LNSType, ShadowType >::operator> ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inlinenoexcept

◆ operator>=()

template<typename LNSType, typename ShadowType = double>
bool sw::universal::TrackedLNS< LNSType, ShadowType >::operator>= ( const TrackedLNS< LNSType, ShadowType > & rhs) const
inlinenoexcept

◆ relative_error()

template<typename LNSType, typename ShadowType = double>
double sw::universal::TrackedLNS< LNSType, ShadowType >::relative_error ( ) const
inlinenoexcept

Relative error.

A shadow of zero used to report 0.0 unconditionally – "perfectly accurate" – even when the value was not zero at all, which is exactly the case a caller needs told about: a difference that cancels in the shadow but not in the LNS encoding has lost every significant bit (#1546).

◆ report()

template<typename LNSType, typename ShadowType = double>
void sw::universal::TrackedLNS< LNSType, ShadowType >::report ( std::ostream & os) const
inline

◆ shadow()

template<typename LNSType, typename ShadowType = double>
ShadowType sw::universal::TrackedLNS< LNSType, ShadowType >::shadow ( ) const
inlineconstexprnoexcept

◆ valid_bits()

template<typename LNSType, typename ShadowType = double>
double sw::universal::TrackedLNS< LNSType, ShadowType >::valid_bits ( ) const
inlinenoexcept

Valid bits remaining, capped at type precision.

◆ value()

template<typename LNSType, typename ShadowType = double>
LNSType sw::universal::TrackedLNS< LNSType, ShadowType >::value ( ) const
inlineconstexprnoexcept

The documentation for this class was generated from the following file:
  • /home/runner/work/universal/universal/include/sw/universal/utility/tracked_lns.hpp