MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
norms.hpp File Reference
#include <algorithm>
#include <cmath>
#include <cassert>
#include <concepts>
#include <cstddef>
#include <limits>
#include <mtl/concepts/vector.hpp>
#include <mtl/detail/wrapping_arithmetic.hpp>
#include <mtl/concepts/matrix.hpp>
#include <mtl/concepts/magnitude.hpp>
#include <mtl/math/identity.hpp>
#include <mtl/math/accumulator_traits.hpp>
#include <mtl/detail/accumulate.hpp>
#include <mtl/detail/thread_pool.hpp>
#include <mtl/interface/dispatch_traits.hpp>
#include <type_traits>
#include <mtl/simd/algorithm.hpp>
#include <mtl/tag/orientation.hpp>
#include <vector>

Namespaces

namespace  mtl
namespace  mtl::detail
 mat*vec multiply into pre-allocated y: y = A * x.
namespace  mtl::detail::norms_adl
 The default two_norm and frobenius_norm sum the squares unscaled, which overflows for elements above about sqrt(max) and loses everything below about sqrt(min) (#690).

Concepts

concept  mtl::detail::norms_adl::rescalable_sum_squares

Functions

template<typename Mag, typename ForEachAbs>
Mag mtl::detail::norms_adl::rescaled_two_norm (ForEachAbs &&for_each_abs)
 sqrt(sum a^2) over the magnitudes that for_each_abs(f) passes to f, computed with a power-of-two scale so that neither the squares nor their sum overflow or underflow.
template<typename Mag>
bool mtl::detail::sum_squares_needs_rescan (const Mag &ss)
template<typename Mag>
void mtl::detail::max_propagating_nan (Mag &result, const Mag &a)
 result = max(result, a), but a NaN a makes the result NaN and keeps it there (#690).
template<Vector V>
auto mtl::one_norm (const V &v)
 one_norm(v) = sum(|v[i]|)
template<typename Accumulator = void, typename Result = void, Vector V>
auto mtl::two_norm (const V &v)
 two_norm(v) = sqrt(sum(|v[i]|^2)).
template<Vector V>
auto mtl::infinity_norm (const V &v)
 infinity_norm(v) = max(|v[i]|)
template<typename M, typename F>
void mtl::detail::for_each_entry (const M &m, F &&f)
 Calls f(r, c, a) for every element a = m(r, c) that can be nonzero, in an order that suits the storage: a compressed2D's stored entries row by row (its operator() is a binary search, so the full m x n loop was O(m n log nnz) for an O(nnz) answer); a column-major matrix column by column; any other matrix row by row.
template<typename Accumulator = void, typename Result = void, Matrix M>
auto mtl::frobenius_norm (const M &m)
 frobenius_norm(m) = sqrt(sum(|m[i,j]|^2)).
template<Matrix M>
auto mtl::one_norm (const M &m)
 one_norm(m) = max column sum of |m[i,j]|
template<Matrix M>
auto mtl::infinity_norm (const M &m)
 infinity_norm(m) = max row sum of |m[i,j]|
template<typename Mag, typename ForEachAbs>
Mag mtl::detail::rescaled_two_norm (ForEachAbs &&for_each_abs)
 sqrt(sum a^2) over the magnitudes that for_each_abs(f) passes to f, computed with a power-of-two scale so that neither the squares nor their sum overflow or underflow.

Variables

template<typename Mag>
constexpr bool mtl::detail::rescalable_sum_squares_v = norms_adl::rescalable_sum_squares<Mag>
template<typename M>
constexpr bool mtl::detail::norm_col_major_v
 The loop order of a matrix norm follows the storage (issue 886): one_norm walked a row-major 6000^2 dense2D by columns, 6x slower than infinity_norm, and the other two were the mirror image on column-major.
template<typename M>
constexpr bool mtl::detail::norm_row_major_v