|
MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
|
Namespaces | |
| namespace | error_free_detail |
| namespace | exact_detail |
| namespace | detail |
Classes | |
| struct | accumulator_traits |
| Accumulator policy for accumulating products of Values into an Acc. More... | |
| struct | accumulator_traits< Acc, Value > |
| Accumulator policy for an accumulator that provides the ADL hook (configuration 3, see adl_accumulator). More... | |
| struct | fma_accumulator |
| Configuration 2 – fused multiply-add accumulator. More... | |
| struct | accumulator_traits< fma_accumulator< T >, Value > |
| Accumulator policy for the FMA reduction (configuration 2). More... | |
| struct | compensated_accumulator |
| Configuration 2c – compensated accumulator: Ogita, Rump and Oishi's Sum2 and Dot2 ("Accurate sum and dot product", SIAM J. More... | |
| struct | accumulator_traits< compensated_accumulator< T >, Value > |
| Accumulator policy for the compensated reduction (configuration 2c). More... | |
| struct | accumulator_round_type |
| The arithmetic type an accumulator should be rounded out to before a scalar post-processing step such as sqrt. More... | |
| struct | accumulator_round_type< fma_accumulator< T >, Mag > |
| struct | accumulator_round_type< compensated_accumulator< T >, Mag > |
| struct | exact_pair |
| The exact result of one operation as hi + lo: hi the rounded result, lo its rounding error. More... | |
| struct | exact_accumulator |
| Exact sum of products of Ts (top of file). More... | |
| struct | identity_t |
| identity_t<Op, T> – returns the identity element of operation Op for type T More... | |
| struct | identity_t< add< T >, T > |
| struct | identity_t< mult< T >, T > |
| struct | identity_t< max_op< T >, T > |
| struct | identity_t< min_op< T >, T > |
| struct | add |
| Additive operation tag. More... | |
| struct | mult |
| Multiplicative operation tag. More... | |
| struct | max_op |
| Maximum operation tag. More... | |
| struct | min_op |
| Minimum operation tag. More... | |
| struct | pow2_scaling |
| exponent(m): the e with 2^e <= m < 2^(e+1), for a positive finite m. More... | |
| struct | pow2_scaling< T > |
| struct | givens_parameters |
| A plane rotation G = [c s; -conj(s) c] with c a + s b = r and -conj(s) a + c b = 0. More... | |
Concepts | |
| concept | adl_accumulator |
| Configuration 3 via the ADL hook: does Acc's own namespace provide the super-accumulator functions for products of Values? | |
| concept | mergeable_accumulator |
| Can two partial accumulators of a reduction be combined? | |
| concept | binary_floating_point |
| Binary IEEE floating point: the types the error-free transformations hold for. | |
| concept | exact_accumulable |
| Is T a type the exact accumulator is defined for: binary32 or binary64. | |
Typedefs | |
| template<typename Acc, typename Mag> | |
| using | accumulator_round_type_t = typename accumulator_round_type<Acc, Mag>::type |
| template<typename T> | |
| using | split_product = exact_pair<T> |
| The name two_product returned before the other transformations (#602). | |
Functions | |
| template<typename T> requires binary_floating_point<T> | |
| exact_pair< T > | two_sum (T a, T b) |
| Knuth's TwoSum: a + b == hi + lo for any a, b, with hi = fl(a + b). | |
| template<typename T> requires binary_floating_point<T> | |
| exact_pair< T > | fast_two_sum (T a, T b) |
| Dekker's FastTwoSum: a + b == hi + lo, provided |a| >= |b| (more precisely, exponent(a) >= exponent(b), or a == 0). | |
| template<typename T> requires std::is_floating_point_v<T> | |
| exact_pair< T > | two_product (T a, T b) |
| The error-free product with an FMA: a * b == hi + lo, hi = fl(a * b). | |
| template<typename T> requires binary_floating_point<T> | |
| exact_pair< T > | split (T a) |
| Veltkamp's Split: a == hi + lo exactly, with hi at most digits - s significant bits and lo at most s - 1 (s = ceil(digits / 2)): 26 and 26 for double, 12 and 11 for float. | |
| template<typename T> requires binary_floating_point<T> | |
| exact_pair< T > | two_product_dekker (T a, T b) |
| Dekker's TwoProduct, without an FMA: a * b == hi + lo, hi = fl(a * b). | |
| template<typename T> | |
| void | accumulator_clear (exact_accumulator< T > &a) |
| template<typename T, typename V> requires exact_detail::feeds<V, T> | |
| void | accumulator_add_product (exact_accumulator< T > &a, const V &m, const V &v) |
| template<typename T, typename V> requires exact_detail::feeds<V, T> | |
| void | accumulator_assign (exact_accumulator< T > &a, const V &v) |
| template<typename T> | |
| void | accumulator_merge (exact_accumulator< T > &a, const exact_accumulator< T > &b) |
| a += b, exactly: the finite parts add without rounding, the special states combine. | |
| template<typename T, typename R> requires exact_accumulable<R> | |
| R | accumulator_value (const exact_accumulator< T > &a, std::type_identity< R >) |
| The single round-out, to nearest-even, of the exact sum to R (float or double). | |
| template<typename T> | |
| constexpr T | zero () |
| Returns the additive identity (zero) for type T. | |
| template<typename T> | |
| constexpr T | one () |
| Returns the multiplicative identity (one) for type T. | |
| template<typename T> | |
| givens_parameters< T > | givens_rotation (const T &a, const T &b) |
| The rotation that maps (a, b) to (r, 0), with |r| = sqrt(|a|^2 + |b|^2) formed without avoidable overflow or underflow (see the top of this file). | |
| template<typename T> | |
| T | scaled_hypot (const T &a, const T &b) |
| sqrt(a^2 + b^2), scaled as givens_rotation() scales it. | |
Variables | |
| template<typename Acc, typename Value> | |
| constexpr bool | is_compensated_accumulator_v = false |
| Three-factor terms (#602). | |
| template<typename T, typename Value> | |
| constexpr bool | is_compensated_accumulator_v< compensated_accumulator< T >, Value > |
| template<typename Acc, typename Value> | |
| constexpr bool | splits_product_terms_v |
| using mtl::math::accumulator_round_type_t = typename accumulator_round_type<Acc, Mag>::type |
| using mtl::math::split_product = exact_pair<T> |
The name two_product returned before the other transformations (#602).
| void mtl::math::accumulator_add_product | ( | exact_accumulator< T > & | a, |
| const V & | m, | ||
| const V & | v ) |
| void mtl::math::accumulator_assign | ( | exact_accumulator< T > & | a, |
| const V & | v ) |
| void mtl::math::accumulator_clear | ( | exact_accumulator< T > & | a | ) |
| void mtl::math::accumulator_merge | ( | exact_accumulator< T > & | a, |
| const exact_accumulator< T > & | b ) |
a += b, exactly: the finite parts add without rounding, the special states combine.
So a sum split across threads or processes and merged has the bits of the sequential sum, for every partition.
| R mtl::math::accumulator_value | ( | const exact_accumulator< T > & | a, |
| std::type_identity< R > | ) |
The single round-out, to nearest-even, of the exact sum to R (float or double).
An exactly zero sum is +0.
| exact_pair< T > mtl::math::fast_two_sum | ( | T | a, |
| T | b ) |
Dekker's FastTwoSum: a + b == hi + lo, provided |a| >= |b| (more precisely, exponent(a) >= exponent(b), or a == 0).
Not checked: the caller orders the operands, which is what makes it half the cost of two_sum.
| givens_parameters< T > mtl::math::givens_rotation | ( | const T & | a, |
| const T & | b ) |
The rotation that maps (a, b) to (r, 0), with |r| = sqrt(|a|^2 + |b|^2) formed without avoidable overflow or underflow (see the top of this file).
a = b = 0 gives the identity, c = 1, s = 0, r = 0.
A complex T (one whose magnitude type is not T itself) follows LAPACK's zlartg: c = |a| / d and s = (a / |a|) conj(b) / d with d = sqrt(|a|^2 + |b|^2), scaled as the real case is, and r = (a / |a|) d, so r keeps a's phase. b = 0 gives c = 1, s = 0, r = a; a = 0 gives c = 0, s = conj(b) / |b|, r = |b|. G is unitary. It used to take the real formula over complex numbers, r = sqrt(a*a + b*b), a complex square: (1, i) gave r = 0 and the identity, (1+i, 1-i) gave r = 0 for |r| = 2, and the rotations applied s unconjugated, so complex GMRES solved the wrong least-squares problem (#853).
A real a or b that is not finite keeps the unscaled formula r = sqrt(a*a + b*b), c = a/r, s = b/r.
A binary IEEE T (detail::binary_ieee_limits) whose larger magnitude lies in detail::plain_givens_interval also takes the unscaled formula, which there gives the scaled form's result without its exponent extraction and three scalings (#697). For double the interval is about (2^-483, 2^510).
|
constexpr |
Returns the multiplicative identity (one) for type T.
| T mtl::math::scaled_hypot | ( | const T & | a, |
| const T & | b ) |
sqrt(a^2 + b^2), scaled as givens_rotation() scales it.
| exact_pair< T > mtl::math::split | ( | T | a | ) |
Veltkamp's Split: a == hi + lo exactly, with hi at most digits - s significant bits and lo at most s - 1 (s = ceil(digits / 2)): 26 and 26 for double, 12 and 11 for float.
So a product of two halves is exact in T. Domain: |a| <= 2^(max_exponent - s - 1) (split_limit: 2^996 for double, 2^115 for float), where factor * a cannot overflow; far enough above it hi is NaN, as in the paper. (Splitting a scaled-down copy does not rescue the top of the range: there hi can round up to 2^max_exponent.) two_product_dekker rescales its operands into the domain.
| exact_pair< T > mtl::math::two_product | ( | T | a, |
| T | b ) |
The error-free product with an FMA: a * b == hi + lo, hi = fl(a * b).
| exact_pair< T > mtl::math::two_product_dekker | ( | T | a, |
| T | b ) |
Dekker's TwoProduct, without an FMA: a * b == hi + lo, hi = fl(a * b).
The same pair as two_product wherever both are exact; this is the form of the Ogita-Rump-Oishi paper, and the one for a target without an FMA. An operand beyond split's domain is scaled down by 2^(s+1) and the other up by 2^(s+1): both exact, the product unchanged. (Both beyond it, the product overflows.) A product above 2^(max_exponent - 1) is formed at half scale, so no intermediate overflows either: exact for every finite product that does not underflow, max * 1 included.
| exact_pair< T > mtl::math::two_sum | ( | T | a, |
| T | b ) |
Knuth's TwoSum: a + b == hi + lo for any a, b, with hi = fl(a + b).
|
constexpr |
Returns the additive identity (zero) for type T.
|
inlineconstexpr |
Three-factor terms (#602).
The LDL^T-type factorizations sum terms a * b * c – L(i,k) d_k L(j,k) – but add_product takes two factors, so they form a * b in Value first. That rounding happens before the accumulator sees the term, and no accumulator, exact or not, can undo it.
For an IEEE Value the rounding can be recovered without a protocol change: with p = a * b rounded and e = fma(a, b, -p), a * b == p + e exactly (absent underflow of e), so add_product(acc, p, c) and add_product(acc, e, c) together carry the whole term. This is worth its second add_product only when the accumulator keeps e * c: an exact one (the ADL hook), a compensated one at least as wide as Value (it keeps twice the precision), or a strictly wider built-in floating type. A plain Value accumulator would round the small term away again, and an FMA accumulator rounds each term to T anyway, so for configurations 1 (at Value) and 2 the kernels keep the single pre-rounded add_product and their bits.
Not for non-IEEE Values: a posit or an LNS has no such splitting identity. An accumulator that specializes accumulator_traits directly rather than through the ADL hook is not detected and keeps the pre-rounded form.
|
inlineconstexpr |
|
inlineconstexpr |