MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::detail::expm_impl Namespace Reference

Namespaces

namespace  adl

Classes

struct  theta_row
 theta_m for m = 3, 5, 7, 9, 13 at unit roundoff u = 2^-t, generated by tools/expm_theta.py and rounded toward zero. More...

Functions

template<typename R>
std::size_t table_index ()
 Index into theta_table of the table expm uses for magnitude type R: the first (largest u) whose u = 2^-t does not exceed R's unit roundoff.
template<typename R>
void split_pow2 (R &x, long &e)
 x = mant * 2^e with mant in [1, 2), for x > 0. Leaves a non-finite x alone.
template<typename R>
R pow2 (long k)
 2^k in R, by repeated doubling or halving.
template<typename R, typename T>
std::array< long, 5 > ell_log2 (const mat::dense2D< T > &A, R normA, R u)
 For each degree m: the smallest integer L with 2^L >= |c_{2m+1}| ||(|A|)^(2m+1)||_1 / (||A||_1 u), or a large negative number when that quantity is zero.
int ell (long L, int m, int s)
template<typename T, typename R>
std::vector< T > pade_coefficients (int m)
 Coefficients of p_m(x) = sum_j b_j x^j, normalized to b_0 = 1: b_j = b_{j-1} (m - j + 1) / (j (2m - j + 1)).
template<typename T>
void combine (mat::dense2D< T > &Y, const T &c0, std::initializer_list< std::pair< T, const mat::dense2D< T > * > > terms)
 Y = c0 I + sum_i c[i] M[i].
template<typename T, typename R>
void scale_by (mat::dense2D< T > &Y, const R &f, int k)
 Y = Y * f, repeated k times (f a power of two, so each step is exact unless it underflows; applying it k times keeps f itself in range).
template<typename T>
void set_triangular_exact (mat::dense2D< T > &X, const std::vector< T > &d, const std::vector< T > &t)
 Al-Mohy & Higham (2009), Code Fragment 2.1: overwrite the diagonal and first superdiagonal of X with exp of those of the upper triangular 2^-j A, where d and t hold 2^-j times A's diagonal and superdiagonal.

Variables

constexpr std::array< int, 5 > degrees {3, 5, 7, 9, 13}
constexpr theta_row theta_table []
constexpr std::array< double, 5 > leading_coefficient
 |c_{2m+1}|, the leading coefficient of the backward-error series h_{2m+1}(x) = log(e^-x r_m(x)), rounded up: (m!)^2 / ((2m)!
constexpr int loop_cap = 1 << 14

Function Documentation

◆ combine()

template<typename T>
void mtl::detail::expm_impl::combine ( mat::dense2D< T > & Y,
const T & c0,
std::initializer_list< std::pair< T, const mat::dense2D< T > * > > terms )

Y = c0 I + sum_i c[i] M[i].

◆ ell()

int mtl::detail::expm_impl::ell ( long L,
int m,
int s )
inline

◆ ell_log2()

template<typename R, typename T>
std::array< long, 5 > mtl::detail::expm_impl::ell_log2 ( const mat::dense2D< T > & A,
R normA,
R u )

For each degree m: the smallest integer L with 2^L >= |c_{2m+1}| ||(|A|)^(2m+1)||_1 / (||A||_1 u), or a large negative number when that quantity is zero.

This is the logarithm behind Al-Mohy & Higham's ell(A, m): once A is scaled by 2^-s the quantity shrinks by 2^-(2m s), so ell(2^-s A, m) = max(0, ceil((L - 2m s) / (2m))).

One sweep of row vectors e^T |A|^k, k = 1 .. 27, serves all five degrees. The vector is renormalized to [1, 2) after every product and its scale kept as a power of two, so a large ||A|| cannot overflow it.

◆ pade_coefficients()

template<typename T, typename R>
std::vector< T > mtl::detail::expm_impl::pade_coefficients ( int m)

Coefficients of p_m(x) = sum_j b_j x^j, normalized to b_0 = 1: b_j = b_{j-1} (m - j + 1) / (j (2m - j + 1)).

◆ pow2()

template<typename R>
R mtl::detail::expm_impl::pow2 ( long k)

2^k in R, by repeated doubling or halving.

◆ scale_by()

template<typename T, typename R>
void mtl::detail::expm_impl::scale_by ( mat::dense2D< T > & Y,
const R & f,
int k )

Y = Y * f, repeated k times (f a power of two, so each step is exact unless it underflows; applying it k times keeps f itself in range).

◆ set_triangular_exact()

template<typename T>
void mtl::detail::expm_impl::set_triangular_exact ( mat::dense2D< T > & X,
const std::vector< T > & d,
const std::vector< T > & t )

Al-Mohy & Higham (2009), Code Fragment 2.1: overwrite the diagonal and first superdiagonal of X with exp of those of the upper triangular 2^-j A, where d and t hold 2^-j times A's diagonal and superdiagonal.

◆ split_pow2()

template<typename R>
void mtl::detail::expm_impl::split_pow2 ( R & x,
long & e )

x = mant * 2^e with mant in [1, 2), for x > 0. Leaves a non-finite x alone.

◆ table_index()

template<typename R>
std::size_t mtl::detail::expm_impl::table_index ( )

Index into theta_table of the table expm uses for magnitude type R: the first (largest u) whose u = 2^-t does not exceed R's unit roundoff.

Variable Documentation

◆ degrees

std::array<int, 5> mtl::detail::expm_impl::degrees {3, 5, 7, 9, 13}
inlineconstexpr

◆ leading_coefficient

std::array<double, 5> mtl::detail::expm_impl::leading_coefficient
inlineconstexpr
Initial value:
{
9.9206349206349207e-06, 9.9413128513657615e-11, 2.2281945605535596e-16,
1.6907929343118737e-22, 8.8299616020186780e-36}

|c_{2m+1}|, the leading coefficient of the backward-error series h_{2m+1}(x) = log(e^-x r_m(x)), rounded up: (m!)^2 / ((2m)!

(2m+1)!).

◆ loop_cap

int mtl::detail::expm_impl::loop_cap = 1 << 14
inlineconstexpr

◆ theta_table

theta_row mtl::detail::expm_impl::theta_table[]
inlineconstexpr
Initial value:
= {
{ 8, {2.5932449418675693e+00, 4.0657321953694477e+00, 4.1855480655496386e+00, 4.2277287712893754e+00, 4.2500000000000000e+00}},
{ 11, {1.8719815976505649e+00, 4.0657321953694477e+00, 4.1855480655496386e+00, 4.2277287712893754e+00, 4.2500000000000000e+00}},
{ 24, {4.2587300348979311e-01, 1.8801526985337688e+00, 3.9257248464332841e+00, 4.2277287712893754e+00, 4.2500000000000000e+00}},
{ 53, {1.4955852179582915e-02, 2.5393983300632320e-01, 9.5041789961629318e-01, 2.0978479612570674e+00, 4.2500000000000000e+00}},
{ 64, {4.1968497232266989e-03, 1.1848116734693823e-01, 5.5170388480686700e-01, 1.3759868875587845e+00, 4.0246098906697353e+00}},
{106, {3.2787892205607026e-05, 6.4467025060072760e-03, 6.8988028496595374e-02, 2.7339737518502231e-01, 1.3203382096514474e+00}},
{113, {1.4605345568331036e-05, 3.9684111281412623e-03, 4.8782043467113475e-02, 2.0880318491357325e-01, 1.0957790341272287e+00}},
{212, {1.5758573750235053e-10, 4.1535526298923909e-06, 3.6270131419308295e-04, 4.6140907478251408e-03, 7.8285103094845854e-02}},
{237, {8.7745582211277553e-12, 7.3425130765306081e-07, 1.0519511326393828e-04, 1.7619311000486504e-03, 4.0200171948642080e-02}},
}