28template<
typename ValueType>
115 m_affine_(interval), m_threshold_(t.value) {
130 m_affine_(
center, std::move(radii)), m_threshold_(t.value) {
146 m_affine_(std::move(a)), m_threshold_(
threshold) {
206 auto r = m_affine_.radius();
207 return interval_t(m_affine_.center() - r, m_affine_.center() + r);
245 m_affine_.add_error_term(error_term, r);
280 bool empty() const noexcept {
return m_affine_.empty(); }
289 return m_affine_.print_affine_form();
298 return range().print_interval_form();
326 result.m_affine_ = -m_affine_;
352 m_affine_ += other.m_affine_;
389 m_affine_ -= other.m_affine_;
426 m_affine_ *= other.m_affine_;
466 value_t b_min = std::fabs(other.m_affine_.
center()) - other_total;
468 throw std::domain_error(
469 "ThresholdedAffine division by interval containing zero");
472 m_affine_ /= other.m_affine_;
497 return m_affine_ == other.m_affine_ &&
498 m_threshold_ == other.m_threshold_;
508 return !(*
this == other);
519 void apply_threshold_() {
520 if(m_affine_.
empty())
return;
521 auto total_r = m_affine_.
radius();
524 if(terms.empty())
return;
527 for(
auto&& [sym, coeff] : terms) {
528 if(std::fabs(coeff) < std::numeric_limits<value_t>::epsilon()) {
530 }
else if(total_r !=
value_t(0) &&
531 std::fabs(coeff) / total_r < m_threshold_) {
534 new_terms[sym] = coeff;
537 m_affine_ =
affine_t(m_affine_.center(), std::move(new_terms));
555template<
typename ValueType>
567template<
typename ValueType>
634template<
typename T,
typename U>
Defines the Affine class.
Implements affine arithmetic.
Definition affine.hpp:48
std::unordered_map< error_term_t, value_t > error_terms_t
Type used to map error terms to their radii.
Definition affine.hpp:60
const error_terms_t & error_terms() const
Returns the error terms of the affine form.
Definition affine.hpp:213
value_t center() const
Returns the center of the affine form.
Definition affine.hpp:194
size_type error_term_t
Opaque type used to store error term information.
Definition affine.hpp:57
Interval< value_t > interval_t
Type of an interval.
Definition affine.hpp:63
bool empty() const noexcept
Checks if this affine form is representing an empty interval.
Definition affine.hpp:313
value_t radius() const
Returns the radius of the affine form.
Definition affine.hpp:830
Implements affine arithmetic that drops negligible error terms.
Definition thresholded_affine.hpp:29
std::size_t size_type
Definition thresholded_affine.hpp:32
std::string print_affine_form() const
Returns a string of the affine form (tracked terms only).
Definition thresholded_affine.hpp:288
ThresholdedAffine operator-() const
Returns the additive inverse of *this.
Definition thresholded_affine.hpp:324
static constexpr Threshold default_threshold()
Definition thresholded_affine.hpp:194
ThresholdedAffine< T > pow(const ThresholdedAffine< T > &a, const U &exp)
Power of a ThresholdedAffine.
Definition thresholded_affine.hpp:635
ThresholdedAffine & operator/=(value_t value)
Divides *this by a scalar.
Definition thresholded_affine.hpp:447
value_t threshold() const
Definition thresholded_affine.hpp:313
ThresholdedAffine(ThresholdedAffine &&other) noexcept=default
Move constructor.
ThresholdedAffine operator*(const ThresholdedAffine &other) const
Multiplies *this by another ThresholdedAffine.
Definition thresholded_affine.hpp:437
ThresholdedAffine(const interval_t &interval, Threshold t=default_threshold())
Constructs a ThresholdedAffine from an interval.
Definition thresholded_affine.hpp:113
bool operator==(const ThresholdedAffine &other) const
Checks equality of two ThresholdedAffine forms.
Definition thresholded_affine.hpp:496
ThresholdedAffine operator-(value_t value) const
Returns the difference of *this and a scalar.
Definition thresholded_affine.hpp:395
ThresholdedAffine operator+(const ThresholdedAffine &other) const
Returns the sum of *this and another ThresholdedAffine.
Definition thresholded_affine.hpp:363
Affine< float > affine_t
Definition thresholded_affine.hpp:47
bool contains(value_t v) const
Returns whether *this contains a scalar value v.
Definition thresholded_affine.hpp:255
ThresholdedAffine(const ThresholdedAffine &other)=default
Copy constructor.
ThresholdedAffine & operator=(ThresholdedAffine &&other) noexcept=default
Move assignment operator.
ThresholdedAffine operator+(value_t value) const
Returns the sum of *this and a scalar.
Definition thresholded_affine.hpp:358
ThresholdedAffine(affine_t a, value_t threshold)
Constructs a ThresholdedAffine by wrapping an Affine form.
Definition thresholded_affine.hpp:145
typename Affine< float >::interval_t interval_t
Definition thresholded_affine.hpp:44
ThresholdedAffine< T > exp(const ThresholdedAffine< T > &a)
Exponential of a ThresholdedAffine.
Definition thresholded_affine.hpp:612
ThresholdedAffine(value_t center, Threshold t=default_threshold())
Constructs a ThresholdedAffine from a center value.
Definition thresholded_affine.hpp:86
ThresholdedAffine(value_t lo, value_t hi, Threshold t=default_threshold())
Constructs a ThresholdedAffine from a lower and upper bound.
Definition thresholded_affine.hpp:99
void add_error_term(error_term_t error_term, value_t r)
Adds an error term to the affine form and applies thresholding.
Definition thresholded_affine.hpp:244
ThresholdedAffine operator/(value_t value) const
Divides *this by a scalar.
Definition thresholded_affine.hpp:479
ThresholdedAffine< T > log(const ThresholdedAffine< T > &a)
Natural logarithm of a ThresholdedAffine.
Definition thresholded_affine.hpp:623
ThresholdedAffine & operator-=(value_t value)
Subtracts a scalar from *this.
Definition thresholded_affine.hpp:373
bool contains(const interval_t &i) const
Returns whether *this contains an interval.
Definition thresholded_affine.hpp:263
ThresholdedAffine(value_t center, error_terms_t radii, Threshold t=default_threshold())
Constructs a ThresholdedAffine from a center and error terms.
Definition thresholded_affine.hpp:128
ThresholdedAffine operator/(const ThresholdedAffine &other) const
Divides *this by another ThresholdedAffine.
Definition thresholded_affine.hpp:484
value_t radius() const
Returns the total radius: the sum of the tracked terms.
Definition thresholded_affine.hpp:229
ThresholdedAffine & operator+=(const ThresholdedAffine &other)
Adds another ThresholdedAffine to *this.
Definition thresholded_affine.hpp:351
ThresholdedAffine< ValueType > operator*(ValueType value, const ThresholdedAffine< ValueType > &a)
Multiplies a scalar by a ThresholdedAffine.
Definition thresholded_affine.hpp:568
ThresholdedAffine< T > sqrt(const ThresholdedAffine< T > &a)
Square root of a ThresholdedAffine.
Definition thresholded_affine.hpp:602
float value_t
Definition thresholded_affine.hpp:35
ThresholdedAffine & operator/=(const ThresholdedAffine &other)
Divides *this by another ThresholdedAffine.
Definition thresholded_affine.hpp:463
typename Affine< float >::error_term_t error_term_t
Definition thresholded_affine.hpp:38
ThresholdedAffine & operator=(const ThresholdedAffine &other)=default
Copy assignment operator.
ThresholdedAffine & operator*=(const ThresholdedAffine &other)
Multiplies *this by another ThresholdedAffine.
Definition thresholded_affine.hpp:425
ThresholdedAffine & operator*=(value_t value)
Multiplies *this by a scalar.
Definition thresholded_affine.hpp:410
interval_t range() const
Returns the interval represented by *this.
Definition thresholded_affine.hpp:204
void set_center(value_t c)
Sets the center of the affine form.
Definition thresholded_affine.hpp:236
ThresholdedAffine & operator+=(value_t value)
Adds a scalar to *this.
Definition thresholded_affine.hpp:336
const error_terms_t & error_terms() const
Returns the error terms of the tracked affine form.
Definition thresholded_affine.hpp:222
ThresholdedAffine operator*(value_t value) const
Multiplies *this by a scalar.
Definition thresholded_affine.hpp:432
ThresholdedAffine & operator-=(const ThresholdedAffine &other)
Subtracts another ThresholdedAffine from *this.
Definition thresholded_affine.hpp:388
ThresholdedAffine< T > fabs(const ThresholdedAffine< T > &a)
Absolute value of a ThresholdedAffine (alias for abs).
Definition thresholded_affine.hpp:591
ThresholdedAffine< T > abs(const ThresholdedAffine< T > &a)
Absolute value of a ThresholdedAffine.
Definition thresholded_affine.hpp:581
bool empty() const noexcept
Returns whether *this is empty.
Definition thresholded_affine.hpp:280
std::string print_interval_form() const
Returns a string of the interval form.
Definition thresholded_affine.hpp:297
typename Affine< float >::error_terms_t error_terms_t
Definition thresholded_affine.hpp:41
const affine_t & affine() const
Returns the underlying Affine form (tracked terms only).
Definition thresholded_affine.hpp:306
bool contains(const ThresholdedAffine &other) const
Returns whether *this contains another ThresholdedAffine's range.
Definition thresholded_affine.hpp:271
bool operator!=(const ThresholdedAffine &other) const
Checks inequality of two ThresholdedAffine forms.
Definition thresholded_affine.hpp:507
ThresholdedAffine operator-(const ThresholdedAffine &other) const
Returns the difference of *this and another ThresholdedAffine.
Definition thresholded_affine.hpp:400
value_t center() const
Definition thresholded_affine.hpp:215
ThresholdedAffine()
Constructs an empty ThresholdedAffine.
Definition thresholded_affine.hpp:76
std::ostream & operator<<(std::ostream &os, const ThresholdedAffine< ValueType > &a)
Outputs the range of a ThresholdedAffine to a stream.
Definition thresholded_affine.hpp:556
The primary namespace for the sigma library.
Definition affine.hpp:12
ThresholdedAffine< double > TADouble
Typedef for a thresholded affine form of doubles.
Definition thresholded_affine.hpp:643
Affine< T > exp(const Affine< T > &a)
Calculate the exponential of an affine form.
Definition exponents.ipp:30
Affine< T > pow(const Affine< T > &a, const U &exp)
Calculate the power of an affine form.
Definition exponents.ipp:71
Affine< T > abs(const Affine< T > &a)
Absolute Value of an affine form.
Definition basic.ipp:8
Affine< T > log(const Affine< T > &a)
Calculate the natural logarithm of an affine form.
Definition exponents.ipp:50
Affine< T > fabs(const Affine< T > &a)
Absolute Value of an affine form.
Definition basic.ipp:25
Affine< T > sqrt(const Affine< T > &a)
Calculate the square root of an affine form.
Definition exponents.ipp:8
ThresholdedAffine< float > TAFloat
Typedef for a thresholded affine form of floats.
Definition thresholded_affine.hpp:640
Threshold(value_t v)
Constructs a Threshold with the given value.
Definition thresholded_affine.hpp:64
value_t value
The relative threshold value (e.g. 0.01 for 1%).
Definition thresholded_affine.hpp:62