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

Namespaces

namespace  adl

Classes

struct  theta_row
 theta_m for m = 1..16 at unit roundoff u = 2^-t, generated by tools/logm_theta.py and rounded toward zero. More...
struct  real_of
struct  real_of< std::complex< R > >

Functions

template<typename R>
std::size_t table_index ()
template<typename R>
R log_lapy2 (const R &x, const R &y)
 log sqrt(x^2 + y^2).
template<typename R>
std::complex< R > clog (const std::complex< R > &z)
 The principal logarithm of a complex number: log|z| + i arg z.
template<typename T>
real_of< T >::type one_norm (const mat::dense2D< T > &M)
 ||M||_1 of a dense square matrix: the largest column sum of |m_ij|, with a complex entry measured as |re| + |im| as LAPACK's cabs1 does.
template<typename R>
bool alpha_within (const std::array< R, 6 > &nrm, int p, const R &theta)
 alpha_p(X) <= theta, as ||X^p|| <= theta^p and ||X^(p+1)|| <= theta^(p+1), from the norms nrm[p] = ||X^p||_1.
template<typename Accumulator, typename T>
std::array< typename real_of< T >::type, 6 > power_norms (const mat::dense2D< T > &Tm)
 The norms ||(T - I)^p||_1 for p = 1..5.
template<typename T>
std::vector< std::complex< typename real_of< T >::type > > eigenvalues_of (const mat::dense2D< T > &Tm)
 The eigenvalues of quasi-triangular T, as complex numbers: a 1x1 block t, and a 2x2 block [a b; c a] as a +- i sqrt|b| sqrt|c|.
template<typename T>
T briggs (T a, int k)
 a^(1/2^k) - 1 without the cancellation of forming the root first: (a - 1) / prod_{j=1}^{k} (1 + a^(1/2^j)) (Al-Mohy 2012; SciPy's _briggs_helper_function).
template<typename T>
mat::dense2D< T > solve_quasi_triangular (const mat::dense2D< T > &M, const mat::dense2D< T > &B, const std::vector< std::size_t > &blocks)
 Solve M Y = B for M upper quasi-triangular with the diagonal blocks blocks (start indices, then n), by block back substitution; a 2x2 block is solved by Gaussian elimination with partial pivoting.
template<typename R>
void gauss_legendre (int m, std::vector< R > &x, std::vector< R > &w)
 The m-point Gauss-Legendre rule on [0, 1], in R: Newton on the Legendre recurrence from double-precision starting values, so the nodes and weights carry R's own precision.
template<typename R>
void log_block2 (const R &a, const R &b, const R &c, R(&l)[2][2])
 log of a real 2x2 block [a b; c a] with b c < 0: log(rho) I + (theta / mu) N, N = [0 b; c 0], since N^2 = -mu^2 I; rho = |a + i mu|, theta = arg(a + i mu).
template<typename T>
T superdiagonal_log (const T &l1, const T &l2, const T &t)
 The (1,2) entry of log([l1 t; 0 l2]) (Higham 2008, (11.28), with SciPy's test for well-separated eigenvalues).
void no_principal_log (const char *who)
template<typename Accumulator, typename T>
mat::dense2D< T > log_quasi_triangular (const mat::dense2D< T > &T0, const char *who)
 log of quasi-triangular (real) or triangular (complex) T, the principal branch.

Variables

constexpr theta_row theta_table []
constexpr int loop_cap = 1 << 10
template<typename T>
constexpr bool exact_entries
 Whether the recomputation of step 5 is available for T.

Function Documentation

◆ alpha_within()

template<typename R>
bool mtl::detail::logm_impl::alpha_within ( const std::array< R, 6 > & nrm,
int p,
const R & theta )

alpha_p(X) <= theta, as ||X^p|| <= theta^p and ||X^(p+1)|| <= theta^(p+1), from the norms nrm[p] = ||X^p||_1.

No p-th root is taken.

◆ briggs()

template<typename T>
T mtl::detail::logm_impl::briggs ( T a,
int k )

a^(1/2^k) - 1 without the cancellation of forming the root first: (a - 1) / prod_{j=1}^{k} (1 + a^(1/2^j)) (Al-Mohy 2012; SciPy's _briggs_helper_function).

A complex a in the left half-plane takes one root first, so that the product's factors stay away from zero.

◆ clog()

template<typename R>
std::complex< R > mtl::detail::logm_impl::clog ( const std::complex< R > & z)

The principal logarithm of a complex number: log|z| + i arg z.

◆ eigenvalues_of()

template<typename T>
std::vector< std::complex< typename real_of< T >::type > > mtl::detail::logm_impl::eigenvalues_of ( const mat::dense2D< T > & Tm)

The eigenvalues of quasi-triangular T, as complex numbers: a 1x1 block t, and a 2x2 block [a b; c a] as a +- i sqrt|b| sqrt|c|.

◆ gauss_legendre()

template<typename R>
void mtl::detail::logm_impl::gauss_legendre ( int m,
std::vector< R > & x,
std::vector< R > & w )

The m-point Gauss-Legendre rule on [0, 1], in R: Newton on the Legendre recurrence from double-precision starting values, so the nodes and weights carry R's own precision.

◆ log_block2()

template<typename R>
void mtl::detail::logm_impl::log_block2 ( const R & a,
const R & b,
const R & c,
R(&) l[2][2] )

log of a real 2x2 block [a b; c a] with b c < 0: log(rho) I + (theta / mu) N, N = [0 b; c 0], since N^2 = -mu^2 I; rho = |a + i mu|, theta = arg(a + i mu).

b / mu and c / mu are formed as +-sqrt|b| / sqrt|c| and its reciprocal, which stay finite where theta / mu would overflow for a tiny mu.

◆ log_lapy2()

template<typename R>
R mtl::detail::logm_impl::log_lapy2 ( const R & x,
const R & y )

log sqrt(x^2 + y^2).

A part above a quarter of the largest finite value would overflow the modulus, although its log is finite, so both are then scaled by 1/4, exactly, and log 4 is added back. A subnormal modulus would round (|d (1 + i)| to d), so parts below the smallest normal value are scaled up by powers of 4, exactly, to [1, 4), and log 4 is subtracted that many times.

◆ log_quasi_triangular()

template<typename Accumulator, typename T>
mat::dense2D< T > mtl::detail::logm_impl::log_quasi_triangular ( const mat::dense2D< T > & T0,
const char * who )

log of quasi-triangular (real) or triangular (complex) T, the principal branch.

The steps are those at the top of this file.

◆ no_principal_log()

void mtl::detail::logm_impl::no_principal_log ( const char * who)
inline

◆ one_norm()

template<typename T>
real_of< T >::type mtl::detail::logm_impl::one_norm ( const mat::dense2D< T > & M)

||M||_1 of a dense square matrix: the largest column sum of |m_ij|, with a complex entry measured as |re| + |im| as LAPACK's cabs1 does.

That is an upper bound on the modulus, so every theta test stays conservative. A column sum that is not finite (a power that overflowed, and NaN where infinity met zero in the next product) counts as the largest finite value, so that it fails every theta test instead of passing them all.

◆ power_norms()

template<typename Accumulator, typename T>
std::array< typename real_of< T >::type, 6 > mtl::detail::logm_impl::power_norms ( const mat::dense2D< T > & Tm)

The norms ||(T - I)^p||_1 for p = 1..5.

◆ solve_quasi_triangular()

template<typename T>
mat::dense2D< T > mtl::detail::logm_impl::solve_quasi_triangular ( const mat::dense2D< T > & M,
const mat::dense2D< T > & B,
const std::vector< std::size_t > & blocks )

Solve M Y = B for M upper quasi-triangular with the diagonal blocks blocks (start indices, then n), by block back substitution; a 2x2 block is solved by Gaussian elimination with partial pivoting.

◆ superdiagonal_log()

template<typename T>
T mtl::detail::logm_impl::superdiagonal_log ( const T & l1,
const T & l2,
const T & t )

The (1,2) entry of log([l1 t; 0 l2]) (Higham 2008, (11.28), with SciPy's test for well-separated eigenvalues).

Real or complex.

◆ table_index()

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

Variable Documentation

◆ exact_entries

template<typename T>
bool mtl::detail::logm_impl::exact_entries
inlineconstexpr
Initial value:
= [] {
using R = typename real_of<T>::type;
else return adl::has_log<R>;
}()
constexpr bool is_complex_v
Whether T is a std::complex, cv-qualifiers ignored (#838).
Definition scalar.hpp:65
T type
Definition logm.hpp:131

Whether the recomputation of step 5 is available for T.

◆ loop_cap

int mtl::detail::logm_impl::loop_cap = 1 << 10
inlineconstexpr

◆ theta_table

theta_row mtl::detail::logm_impl::theta_table[]
inlineconstexpr
Initial value:
= {
{ 8, {2.0556378113565385e-01, 6.6787324907318391e-01, 8.6321237071950396e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01}},
{ 11, {7.5117418789611839e-02, 4.4837093538742018e-01, 7.0614669543529140e-01, 8.3495220542349435e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01}},
{ 24, {8.4554916858733324e-04, 5.6023059002159405e-02, 2.1323982449115605e-01, 3.9001579176794809e-01, 5.3632358197441876e-01, 6.4568664286693300e-01, 7.2524828289477494e-01, 7.8323135329348248e-01, 8.2603280216228403e-01, 8.5815396704041957e-01, 8.8267695218190567e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01, 8.9999999999999991e-01}},
{ 53, {3.6500241166821667e-08, 3.7593213639263378e-04, 8.2023793049542000e-03, 3.7925485813213540e-02, 9.3346522964603135e-02, 1.6680834400298361e-01, 2.4796015202926916e-01, 3.2875993178081814e-01, 4.0443220710631639e-01, 4.7276766041649781e-01, 5.3316981326948798e-01, 5.8591754955734332e-01, 6.3169593749397313e-01, 6.7132910485514108e-01, 7.0564130496404942e-01, 7.3539225760317928e-01}},
{ 64, {8.0654900857230240e-10, 5.5889354452327250e-05, 2.3073945975618597e-03, 1.4773849843546462e-02, 4.4563652096338661e-02, 9.1775475165195658e-02, 1.5156379216555396e-01, 2.1787178735944562e-01, 2.8559204975067637e-01, 3.5120613353605401e-01, 4.1264786885038723e-01, 4.6892448598286285e-01, 5.1974522008903090e-01, 5.6523641177058614e-01, 6.0574743217904337e-01, 6.4172811356228154e-01}},
{106, {3.8459253727671271e-16, 3.8594305912052708e-08, 1.8043736793233080e-05, 3.9069075866104681e-04, 2.4718262149449645e-03, 8.4396425071008360e-03, 2.0218605031865226e-02, 3.8750410814695706e-02, 6.3921258553562468e-02, 9.4850089680560329e-02, 1.3025214828683826e-01, 1.6873661665627471e-01, 2.0900036958358659e-01, 2.4992913567091538e-01, 2.9063269102706912e-01, 3.3043993748915051e-01}},
{113, {3.3993498887762956e-17, 1.1474155913993978e-08, 8.0376045005431223e-06, 2.1304220733306831e-04, 1.5222387529037428e-03, 5.6400539111747779e-03, 1.4336298641625554e-02, 2.8751582374573582e-02, 4.9173558792335786e-02, 7.5163434349813110e-02, 1.0581520995963382e-01, 1.4000913145889102e-01, 1.7660238594475969e-01, 2.1454833307678264e-01, 2.5295666593775379e-01, 2.9111235004677877e-01}},
{212, {4.2698348998361531e-32, 4.0665709705008996e-16, 8.6722773446227496e-11, 4.0110671345012426e-08, 1.5943481310289909e-06, 1.8574066122523088e-05, 1.0730225385226058e-04, 3.9982645547527299e-04, 1.1120045017315231e-03, 2.5196059340318769e-03, 4.9172117405206946e-03, 8.5775108784407143e-03, 1.3721276441635606e-02, 2.0500796338515807e-02, 2.8995156706767427e-02, 3.9214142266363064e-02}},
{237, {7.3711650688992350e-36, 5.3430702366703530e-18, 4.8288254812159674e-12, 4.5977060463129696e-09, 2.8184376022025850e-07, 4.3829244816509238e-06, 3.1122225279742368e-05, 1.3538358278270023e-04, 4.2476658840507936e-04, 1.0600994265624985e-03, 2.2397306587981823e-03, 4.1755019937513302e-03, 7.0687438062081278e-03, 1.1091422745517152e-02, 1.6374243657316531e-02, 2.3001359087794028e-02}},
}