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

Namespaces

namespace  array
namespace  traits
namespace  ashape
namespace  detail
 mat*vec multiply into pre-allocated y: y = A * x.
namespace  functor
namespace  generators
namespace  testsuite
namespace  interface
namespace  io
namespace  itl
namespace  mat
namespace  mx
namespace  math
namespace  memory_space
namespace  runtime
namespace  tag
namespace  vec
namespace  tensor
namespace  parallel
namespace  recursion
namespace  simd
namespace  sparse
namespace  util

Classes

struct  magnitude_trait
 Primary template: magnitude type is the type itself. More...
struct  magnitude_trait< std::complex< T > >
 Specialization for std::complex. More...
struct  is_complex
 Detect std::complex specializations. More...
struct  is_complex< std::complex< T > >
struct  block_kernels
 Customization point for a scheme's fused mat-vec kernel. More...
struct  zero_fill_is_value_init
 Whether all-zero bytes are T{}: arithmetic types, enumerations, object and function pointers, std::nullptr_t, and std::complex of a floating-point type. More...
struct  zero_fill_is_value_init< std::complex< T > >
struct  frechet_result
 f(A) and its Frechet derivative L_f(A, E), as returned by expm_frechet, logm_frechet and sqrtm_frechet. More...
struct  normalized_reflection
 A reflector H = I - tau*v*v^H with v(0) == 1, and beta, H*x = beta*e_1, as householder_reflector() returns them. More...
struct  textbook_reflection
 A textbook Householder reflector (#559): H = I - (2/vtv)*v*v^T with v NOT normalized, and H*x = alpha*e_1. More...
struct  bk_pivot_info
 Pivot information from Bunch-Kaufman factorization. More...
struct  lu_refine_options
 Controls for lu_iterative_refine. More...
struct  lu_refine_result
 Outcome of lu_iterative_refine. More...
struct  schur_result
 The factors of a Schur decomposition A = Q T Q^H. More...
struct  inertia_t
 Inertia of a symmetric matrix: the counts (positive, negative, zero) of its eigenvalues. More...
struct  sylvester_result
 The solution of a Sylvester equation. More...
struct  sylvester_scaled_result
 The solution of a Sylvester equation scaled against overflow, as LAPACK trsyl returns it: X solves A X + sgn X B = scale * C with 0 < scale <= 1. More...
class  block_diagonal2D
 Block diagonal matrix – stores vector of dense2D blocks. More...
class  block_matrix_view
 Read-only, row-major view of a rows x cols matrix stored as blocks of the scheme S, cols / S::block_size blocks per row. More...
class  compressed2D
 CSR sparse matrix: three arrays – data (values), indices (column indices), starts (row pointers of length nrows+1). More...
class  coordinate2D
 COO sparse matrix: stores (row, col, value) triplets. More...
class  dense2D
 Dense row/column-major matrix with configurable dimensions and storage. More...
class  ell_matrix
 ELLPACK sparse matrix: each row stores up to max_width non-zeros. More...
class  identity2D
 Implicit identity matrix: no storage, O(1) element access. More...
class  permutation_matrix
 Implicit permutation matrix – stores only perm vector, O(n) storage. More...
class  shifted_inserter
 Offset decorator for sparse matrix inserters. More...
class  dense_vector
 Dense vector with configurable orientation, storage, and dimensions. More...
class  sparse_vector
 Sparse vector stored as dual sorted arrays (indices + values). More...
class  strided_vector_ref
 Non-owning reference to strided data: pointer + length + stride. More...

Concepts

concept  BlockScheme
 A block-quantized storage format:
concept  ElementDecodableScheme
 Does the scheme decode one element without decoding its block?
concept  Collection
 A read-only collection with value_type, size_type, and size().
concept  MutableCollection
 A mutable collection allowing element modification.
concept  LinearOperator
 Anything that supports A * x producing a vector-like result Used by ITL Krylov solvers.
concept  Magnitude
 Concept: a type has a well-defined magnitude.
concept  Matrix
 A 2D collection with num_rows(), num_cols(), and (r,c) access.
concept  FieldMatrix
 A matrix whose elements form a FIELD – the requirement of every algorithm that divides by a matrix element: LU, QR, LQ, Cholesky, LDL^T, SVD, eigen, inverse.
concept  DenseMatrix
 A dense matrix: category tag is tag::dense.
concept  SparseMatrix
 A sparse matrix: category tag is tag::sparse.
concept  NdArray
 An N-dimensional array with rank, shape, and multi-dimensional element access.
concept  MutableNdArray
 A mutable NdArray that allows element modification.
concept  Preconditioner
 A preconditioner provides solve() and adjoint_solve().
concept  HasNumericLimits
 The number system describes itself through std::numeric_limits (#838): its epsilon, range, infinities and NaNs.
concept  Scalar
 A type that behaves like a scalar value (arithmetic or custom number type), and describes itself through std::numeric_limits.
concept  Field
 A type that forms a mathematical field: division is defined AND invertible.
concept  OrderedField
 An ordered field (field with comparison operators).
concept  Vector
 A 1D collection with indexed access.
concept  FieldVector
 A vector whose elements form a FIELD – the requirement of every algorithm that divides by a vector element or by a scalar derived from one.
concept  DenseVector
 A dense vector with contiguous storage.
concept  ColumnVector
 A column vector.
concept  RowVector
 A row vector.
concept  BlockGemvScheme
 Does the scheme supply a fused gemv?
concept  MemorySpace
 A memory space: says where elements live and who may touch them.
concept  AllocatingMemorySpace
 A memory space that can allocate and free storage for T.
concept  DeviceRuntime
 A device runtime: the programming model behind a device memory kind.
concept  quad_int_dot
 Does dot<Accumulator, Result>(v1, v2) name the quad-widening 8-bit kernel?
concept  quad_int_dot_swapped
 Does dot(v1, v2) name the quad kernel with the operands the OTHER way round?
concept  widening_int_dot
 Does dot<Accumulator, Result>(v1, v2) name the widening integer kernel?
concept  ProjectableOnto
 ProjectableOnto: Target has fewer (or equal) significant digits than Source.
concept  EmbeddableInto
 EmbeddableInto: Target has more (or equal) significant digits than Source.

Typedefs

template<typename T>
using magnitude_t = typename magnitude_trait<std::remove_cv_t<T>>::type
 Alias for the magnitude type of T, cv-qualifiers ignored (#838): magnitude_t<const std::complex<double>> is double.
using default_size_type = std::size_t
 Default size type for indices and dimensions.
template<typename Matrix, typename Updater = update_store<typename Matrix::value_type>>
using inserter
 Convenience alias: inserter<MatrixType, Updater>.

Enumerations

enum class  uplo { lower , upper }
 Which triangle of a square matrix an operation forms or reads. More...
enum class  gemmt_fill { mirror , keep }
 What gemmt does with the triangle it does not form. More...
enum class  sylvester_sign { plus , minus }
 The sign between the two terms of a Sylvester equation: plus for A X + X B = C, minus for A X - X B = C. More...

Functions

template<BlockScheme S>
std::size_t block_gemv_scratch_bytes (std::size_t cols)
 Scratch bytes mult() needs for a block matrix of scheme S with cols columns: the fused kernel's scratch_bytes(cols), or 0 when the scheme has no fused kernel or its kernel declares none.
template<typename Accumulator = void, BlockScheme S, Vector VIn, Vector VOut>
void mult (const mat::block_matrix_view< S > &A, const VIn &x, VOut &y, std::span< std::byte > scratch)
 y = A x for a block matrix, into a pre-allocated y, with the fused kernel's scratch supplied by the caller.
template<typename Accumulator = void, BlockScheme S, Vector VIn, Vector VOut>
void mult (const mat::block_matrix_view< S > &A, const VIn &x, VOut &y)
 y = A x for a block matrix, into a pre-allocated y.
template<BlockScheme S, Matrix MDst>
void convert (const mat::block_matrix_view< S > &src, MDst &dst)
 Decode a block matrix into a pre-allocated destination, a row at a time.
template<typename DstValue, BlockScheme S>
mat::dense2D< DstValue > convert (const mat::block_matrix_view< S > &src)
 Decode a block matrix into a new dense2D<DstValue>.
template<typename Matrix>
auto banded (const Matrix &A, std::ptrdiff_t lower, std::ptrdiff_t upper)
 Create a banded view of matrix A with given lower and upper bandwidth.
template<typename Matrix>
void banded (const Matrix &&, std::ptrdiff_t, std::ptrdiff_t)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename Matrix>
auto hermitian (const Matrix &A)
 Create a hermitian view of matrix A (upper triangle stored).
template<typename Matrix>
void hermitian (const Matrix &&)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename Matrix>
auto lower (const Matrix &A)
 Create a lower triangular view (includes diagonal).
template<typename Matrix>
void lower (const Matrix &&)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename Matrix>
auto mapped (const Matrix &A, const std::vector< typename Matrix::size_type > &row_map, const std::vector< typename Matrix::size_type > &col_map)
 Create a map view with row and column remapping.
template<typename Matrix>
void mapped (const Matrix &&, const std::vector< typename Matrix::size_type > &, const std::vector< typename Matrix::size_type > &)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename Matrix>
auto strict_lower (const Matrix &A)
 Create a strict lower triangular view (excludes diagonal).
template<typename Matrix>
void strict_lower (const Matrix &&)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename Matrix>
auto tril (const Matrix &A, std::ptrdiff_t k=0)
 MATLAB-compatible tril(A, k): elements on diag k and below.
template<typename Matrix>
void tril (const Matrix &&, std::ptrdiff_t=0)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename Matrix>
auto strict_upper (const Matrix &A)
 Create a strict upper triangular view (excludes diagonal).
template<typename Matrix>
void strict_upper (const Matrix &&)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename Matrix>
auto triu (const Matrix &A, std::ptrdiff_t k=0)
 MATLAB-compatible triu(A, k): elements on diag k and above.
template<typename Matrix>
void triu (const Matrix &&, std::ptrdiff_t=0)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename Matrix>
auto upper (const Matrix &A)
 Create an upper triangular view (includes diagonal).
template<typename Matrix>
void upper (const Matrix &&)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename V, typename P1, typename P2>
requires (!vec::dense_vector<V, P2>::read_only && std::is_same_v<typename P1::orientation, typename P2::orientation>)
void copy (const vec::dense_vector< V, P1 > &src, vec::dense_vector< V, P2 > &dst)
 dst receives src's elements (#1017).
template<typename V, typename P1, typename P2>
requires (!vec::dense_vector<V, P2>::read_only && std::is_same_v<typename P1::orientation, typename P2::orientation>)
void copy (const vec::dense_vector< V, P1 > &src, vec::dense_vector< V, P2 > &&dst)
 A temporary target, such as a view built at the call site: written through.
template<typename V, typename P1, typename P2>
requires (!mat::dense2D<V, P2>::read_only && std::is_same_v<typename P1::orientation, typename P2::orientation> && std::is_same_v<typename P1::index_type, typename P2::index_type>)
void copy (const mat::dense2D< V, P1 > &src, mat::dense2D< V, P2 > &dst)
 dst receives src's elements (#1017).
template<typename V, typename P1, typename P2>
requires (!mat::dense2D<V, P2>::read_only && std::is_same_v<typename P1::orientation, typename P2::orientation> && std::is_same_v<typename P1::index_type, typename P2::index_type>)
void copy (const mat::dense2D< V, P1 > &src, mat::dense2D< V, P2 > &&dst)
 A temporary target, such as a view built at the call site: written through.
template<typename Space, typename V, typename P>
auto copy_to (const vec::dense_vector< V, P > &x)
 A new owning vector in Space holding x's elements (#1017).
template<typename Space, typename V, typename P>
auto copy_to (const mat::dense2D< V, P > &x)
 A new owning matrix in Space holding x's elements (#1017).
template<typename C>
auto to_host (const C &x) -> decltype(copy_to< memory_space::host >(x))
 A new host container holding x's elements: always a copy (#1017).
template<Vector V>
auto abs (const V &v)
 Element-wise abs for vectors -> dense_vector<magnitude_t<T>>.
template<Matrix M>
auto abs (const M &m)
 Element-wise abs for matrices -> dense2D<magnitude_t<T>>.
template<Vector V>
auto acos (const V &v)
 Element-wise acos for vectors.
template<Matrix M>
auto acos (const M &m)
 Element-wise acos for matrices.
template<Vector V>
auto acosh (const V &v)
 Element-wise acosh for vectors.
template<Matrix M>
auto acosh (const M &m)
 Element-wise acosh for matrices.
template<Vector V>
auto asin (const V &v)
 Element-wise asin for vectors.
template<Matrix M>
auto asin (const M &m)
 Element-wise asin for matrices.
template<Vector V>
auto asinh (const V &v)
 Element-wise asinh for vectors.
template<Matrix M>
auto asinh (const M &m)
 Element-wise asinh for matrices.
template<Vector V>
auto atan (const V &v)
 Element-wise atan for vectors.
template<Matrix M>
auto atan (const M &m)
 Element-wise atan for matrices.
template<Vector V>
auto atanh (const V &v)
 Element-wise atanh for vectors.
template<Matrix M>
auto atanh (const M &m)
 Element-wise atanh for matrices.
template<typename Accumulator = void, Scalar S, Vector VX, Vector VY>
void axpy (const S &alpha, const VX &x, VY &y)
 y[i] += alpha * x[i]
template<typename T, typename PA, typename PV>
double normwise_backward_error (const mat::dense2D< T, PA > &A, const vec::dense_vector< T, PV > &x, const vec::dense_vector< T, PV > &b)
 Normwise backward error eta(x) = ||b - A x||_inf / (||A||_inf ||x||_inf + ||b||_inf).
template<Vector V>
auto cbrt (const V &v)
 Element-wise cbrt for vectors.
template<Matrix M>
auto cbrt (const M &m)
 Element-wise cbrt for matrices.
template<Vector V>
auto ceil (const V &v)
 Element-wise ceil for vectors.
template<Matrix M>
auto ceil (const M &m)
 Element-wise ceil for matrices.
template<typename Accumulator = void, FieldMatrix M>
int cholesky_factor (M &A)
 Cholesky factorization: A = L * L^T, for a REAL symmetric positive definite A.
template<FieldMatrix M>
int cholesky_factor (M &A, tag::subtract_sum)
 cholesky_factor(A), with the default summation order named explicitly.
template<FieldMatrix M>
int cholesky_factor (M &A, tag::subtract_term_by_term)
 Cholesky factorization A = L * L^T with each entry formed TERM BY TERM: start from the matrix entry and subtract each product in turn (#556),.
template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void cholesky_solve (const M &L, VecX &x, const VecB &b)
 Solve A*x = b using precomputed Cholesky factor L (stored in lower triangle of A).
template<typename Accumulator = void, FieldMatrix M>
int cholesky_h_factor (M &A)
 Cholesky factorization: A = L * L^H, for a HERMITIAN positive definite A.
template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void cholesky_h_solve (const M &L, VecX &x, const VecB &b)
 Solve A*x = b using precomputed Cholesky factors of a HERMITIAN A, i.e.
template<Vector V>
auto conj (const V &v)
 Element-wise conjugation for vectors.
template<Matrix M>
auto conj (const M &m)
 Element-wise conjugation for matrices.
template<Vector VSrc, Vector VDst>
void convert (const VSrc &src, VDst &dst)
 Convert a vector into a pre-allocated destination of (possibly) another type.
template<Matrix MSrc, Matrix MDst>
void convert (const MSrc &src, MDst &dst)
 Convert a matrix into a pre-allocated destination of (possibly) another type.
template<typename DstValue, Vector VSrc>
vec::dense_vector< DstValue > convert (const VSrc &src)
 Convert a vector to a new dense_vector<DstValue> (out-of-place convenience).
template<typename DstValue, Matrix MSrc>
mat::dense2D< DstValue > convert (const MSrc &src)
 Convert a matrix to a new dense2D<DstValue> (out-of-place convenience).
template<Vector V>
auto cos (const V &v)
 Element-wise cos for vectors.
template<Matrix M>
auto cos (const M &m)
 Element-wise cos for matrices.
template<Vector V>
auto cosh (const V &v)
 Element-wise cosh for vectors.
template<Matrix M>
auto cosh (const M &m)
 Element-wise cosh for matrices.
template<Matrix M>
auto diagonal (const M &A)
 Returns a dense_vector containing the diagonal entries A(i,i).
template<typename T>
auto diag (const vec::dense_vector< T > &v)
 Construct an n x n diagonal sparse matrix from a vector (inverse of diagonal).
template<typename Accumulator = void, typename Result = Accumulator, Vector V1, Vector V2>
auto dot (const V1 &v1, const V2 &v2)
 Hermitian dot product: sum(conj(v1[i]) * v2[i]).
template<typename Accumulator = void, typename Result = Accumulator, Vector V1, Vector V2>
auto dot_real (const V1 &v1, const V2 &v2)
 Real dot product: sum(v1[i] * v2[i]) – no conjugation.
template<typename Accumulator = void, FieldMatrix M>
auto eigenvalue (const M &A, typename M::value_type tol=1e-10, typename M::size_type max_iter=0)
 Compute eigenvalues of a general (non-symmetric) square matrix via the Francis implicit double-shift QR algorithm on the upper Hessenberg form.
template<typename Accumulator = void, FieldMatrix M>
auto eigen (const M &A, typename M::value_type tol=1e-10, typename M::size_type max_iter=0)
 Compute eigenvalues AND right eigenvectors of a general (non-symmetric) square matrix.
template<typename Accumulator = void, FieldMatrix M>
auto eigenvalue_symmetric_generic (const M &A, magnitude_t< typename M::value_type > tol=detail::default_eigen_tolerance< magnitude_t< typename M::value_type > >(), typename M::size_type max_iter=0)
 Generic (LAPACK-free) symmetric/Hermitian eigenvalue solver: tridiagonalize, then run implicit QR with Wilkinson shifts on the tridiagonal form.
template<typename Accumulator = void, FieldMatrix M>
auto eigenvalue_symmetric (const M &A, magnitude_t< typename M::value_type > tol=detail::default_eigen_tolerance< magnitude_t< typename M::value_type > >(), typename M::size_type max_iter=0)
 Compute eigenvalues of a symmetric/Hermitian matrix via implicit QR on tridiagonal form.
template<typename Accumulator = void, FieldMatrix M>
auto eigen_symmetric (const M &A, magnitude_t< typename M::value_type > tol=detail::default_eigen_tolerance< magnitude_t< typename M::value_type > >(), typename M::size_type max_iter=0)
 Compute eigenvalues and eigenvectors of a symmetric or Hermitian matrix.
template<FieldMatrix M>
auto eigen_symmetric_jacobi (const M &A, typename M::value_type tol=std::numeric_limits< typename M::value_type >::epsilon(), typename M::size_type max_sweeps=0)
 Eigenvalues and eigenvectors of a real symmetric matrix by the cyclic-by-row two-sided Jacobi method.
template<Vector V>
auto erf (const V &v)
 Element-wise erf for vectors.
template<Matrix M>
auto erf (const M &m)
 Element-wise erf for matrices.
template<Vector V>
auto erfc (const V &v)
 Element-wise erfc for vectors.
template<Matrix M>
auto erfc (const M &m)
 Element-wise erfc for matrices.
template<Vector V>
auto exp (const V &v)
 Element-wise exp for vectors.
template<Matrix M>
auto exp (const M &m)
 Element-wise exp for matrices.
template<Vector V>
auto exp2 (const V &v)
 Element-wise exp2 for vectors.
template<Matrix M>
auto exp2 (const M &m)
 Element-wise exp2 for matrices.
template<typename Accumulator = void, FieldMatrix M>
auto expm (const M &A_in)
 The matrix exponential exp(A) of a square matrix A, as a dense2D.
template<Matrix MA, typename V>
mat::dense2D< V > expm_multiply (const MA &A, const mat::dense2D< V > &B, const V &t=V(1))
 e^{tA} B for a square A (dense or compressed2D) and a dense n x n0 block B, without forming e^{tA}.
template<Matrix MA, typename V>
vec::dense_vector< V > expm_multiply (const MA &A, const vec::dense_vector< V > &b, const V &t=V(1))
 e^{tA} b for a vector b.
template<Matrix M>
bool is_spd (const M &A, magnitude_t< typename M::value_type > sym_tol=magnitude_t< typename M::value_type >(0))
 Symmetric positive definite: A is symmetric (within sym_tol, default exact) and its Cholesky factorization exists (every pivot strictly positive).
template<Matrix M>
bool is_positive_definite (const M &A, magnitude_t< typename M::value_type > sym_tol=magnitude_t< typename M::value_type >(0))
 Alias for is_spd.
template<Matrix M>
bool is_singular (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 Singular within tol: the LU factorization has a zero pivot, or the smallest |U(k,k)| is <= tol (default 0, i.e.
template<Matrix M>
bool is_nonsingular (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 Complement of is_singular.
template<Matrix M>
bool is_invertible (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 Alias for is_nonsingular.
template<Matrix M>
M::value_type determinant (const M &A)
 Determinant via LU: sign(permutation) * product of U(k,k).
template<MutableCollection C>
void fill (C &c, const typename C::value_type &val)
 Fill all elements of a collection with the given value.
template<Vector V>
auto floor (const V &v)
 Element-wise floor for vectors.
template<Matrix M>
auto floor (const M &m)
 Element-wise floor for matrices.
template<typename Accumulator = void, FieldMatrix MA, FieldMatrix ME>
auto expm_frechet (const MA &A, const ME &E)
 exp(A) and the Frechet derivative L_exp(A, E), by expm on [A E; 0 A].
template<typename Accumulator = void, FieldMatrix MA, FieldMatrix ME>
auto logm_frechet (const MA &A, const ME &E)
 log(A) and the Frechet derivative L_log(A, E), by logm on [A E; 0 A].
template<typename Accumulator = void, FieldMatrix MA, FieldMatrix ME>
auto sqrtm_frechet (const MA &A, const ME &E)
 sqrt(A) and the Frechet derivative L_sqrt(A, E): X = sqrtm(A), and L solves X L + L X = E.
template<typename Accumulator = void, FieldMatrix M>
auto expm_cond (const M &A)
 An estimate of the relative condition number of exp at A in the 1-norm, ||L_exp(A)|| ||A|| / ||exp(A)|| (Higham 2008, Sec.
template<typename Accumulator = void, FieldMatrix M>
auto logm_cond (const M &A)
 An estimate of the relative condition number of log at A in the 1-norm.
template<typename Accumulator = void, FieldMatrix M>
auto sqrtm_cond (const M &A)
 An estimate of the relative condition number of the principal square root at A in the 1-norm.
template<typename Dest, Matrix Expr>
requires traits::is_expression_v<Expr>
void fused_assign (Dest &dest, const Expr &expr)
 Evaluate a matrix expression into a pre-allocated target: dest = expr.
template<typename Dest, Vector Expr>
requires (traits::is_expression_v<Expr> && !Matrix<Expr>)
void fused_assign (Dest &dest, const Expr &expr)
 Evaluate a vector expression into a pre-allocated target: dest = expr.
template<typename Dest, Matrix Expr>
requires traits::is_expression_v<Expr>
void fused_plus_assign (Dest &dest, const Expr &expr)
 Evaluate a matrix expression and add to target: dest += expr In place unless expr reads dest elsewhere (see fused_assign): then the sum is formed from a temporary of expr.
template<typename Dest, Vector Expr>
requires (traits::is_expression_v<Expr> && !Matrix<Expr>)
void fused_plus_assign (Dest &dest, const Expr &expr)
 Evaluate a vector expression and add to target: dest += expr.
template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB, Matrix MC>
void gemmt (const S &alpha_in, const MA &A, const MB &B, const S &beta_in, MC &C, uplo t=uplo::lower, gemmt_fill fill=gemmt_fill::mirror)
 Triangular-output product: the t triangle of C = alpha*A*B + beta*C.
template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MP, Matrix MC>
void congruence (const S &alpha, const MA &A, const MP &P, const S &beta, MC &C)
 Congruence: C = alpha * A*P*A^T + beta*C, for a symmetric m x m result.
template<typename Accumulator = void, Scalar S, Matrix MA, Vector VR, Matrix MC>
requires (!Matrix<VR>)
void congruence (const S &alpha, const MA &A, const VR &r, const S &beta, MC &C)
 Congruence with a diagonal middle term: C = alpha * A*diag(r)*A^T + beta*C.
template<typename Accumulator = void, Matrix MA, Matrix MP, Matrix MC>
void congruence (const MA &A, const MP &P, MC &C)
 C = A*P*A^T.
template<typename Accumulator = void, Matrix MA, Vector VR, Matrix MC>
requires (!Matrix<VR>)
void congruence (const MA &A, const VR &r, MC &C)
 C = A*diag(r)*A^T.
template<typename Accumulator = void, Scalar S, Vector VX, Vector VY, Matrix M>
void ger (const S &alpha, const VX &x, const VY &y, M &A)
 Rank-1 update: A(i,j) += alpha * x(i) * y(j).
template<typename Matrix, typename Vector>
void apply_stored_rotation (Matrix &H, const Vector &c, const Vector &s, typename Matrix::size_type i, typename Matrix::size_type k)
 Apply a previously stored Givens rotation to column k of Hessenberg H at rows i, i+1: [H(i,k); H(i+1,k)] <- [c s; -conj(s) c] [H(i,k); H(i+1,k)].
template<typename Matrix, typename VecG, typename VecC, typename VecS>
void apply_givens_rotation (Matrix &H, VecG &g, VecC &c, VecS &s, typename Matrix::size_type k)
 Compute new Givens rotation for column k of Hessenberg H, apply it to H and RHS vector g, and store the rotation in c, s.
template<typename Accumulator = void, Matrix M>
void hessenberg_factor (M &A, vec::dense_vector< typename M::value_type > &tau)
 Reduce A to upper Hessenberg form in-place.
template<Matrix M>
auto hessenberg_extract_H (const M &A)
 Extract explicit upper Hessenberg matrix from factored A.
template<typename Accumulator = void, Matrix M>
auto hessenberg_extract_Q (const M &A, const vec::dense_vector< typename M::value_type > &tau)
 Form the unitary Q of A = Q H Q^H from the reflectors hessenberg_factor() left in the strict lower triangle of A and in tau (LAPACK orghr).
template<typename Accumulator = void, Matrix M>
auto hessenberg (const M &A)
 Reduce A to upper Hessenberg form and return H directly.
template<typename Accumulator = void, Matrix M>
void tridiagonalize (M &A, vec::dense_vector< typename M::value_type > &tau)
 Reduce a symmetric (or Hermitian) matrix to tridiagonal form in-place.
template<typename Accumulator = void, typename T>
normalized_reflection< T > householder_reflector (const vec::dense_vector< T > &x)
 Compute Householder vector v and scalar tau for a column vector x, such that H = I - tau*v*v^H satisfies H*x = beta*e_1, and return beta with them.
template<typename Accumulator = void, typename T>
std::pair< vec::dense_vector< T >, T > householder (const vec::dense_vector< T > &x)
 Compute Householder vector v and scalar tau for a column vector x, such that H = I - tau*v*v^H satisfies H*x = beta*e_1.
template<typename T>
textbook_reflection< T > householder (const vec::dense_vector< T > &x, tag::textbook_reflector)
 Textbook (Golub & Van Loan sec.
template<typename Accumulator = void, Matrix M, typename T>
void apply_householder_left (M &A, const vec::dense_vector< T > &v, T beta, typename M::size_type row, typename M::size_type col)
 Apply Householder reflection H = I - beta*v*v^H on the LEFT (A := H*A) to columns col..ncols-1 of matrix A, rows row..nrows-1.
template<Matrix M, typename T>
void apply_householder_left (M &A, const vec::dense_vector< T > &v, T vtv, typename M::size_type row, typename M::size_type col, tag::textbook_reflector)
 Apply a textbook reflector H = I - (2/vtv)*v*v^T on the LEFT (A := H*A) to columns col..ncols-1, rows row..row+v.size()-1 (#559).
template<typename Accumulator = void, Matrix M, typename T>
void apply_householder_right (M &A, const vec::dense_vector< T > &v, T beta, typename M::size_type row, typename M::size_type col)
 Apply Householder reflection on the right: A := A * (I - beta*v*v^H).
template<Matrix M, typename T>
void apply_householder_right (M &A, const vec::dense_vector< T > &v, T vtv, typename M::size_type row, typename M::size_type col, tag::textbook_reflector)
 Apply a textbook reflector H = I - (2/vtv)*v*v^T on the RIGHT (A := A*H) to rows row..nrows-1, columns col..col+v.size()-1 (#559).
template<Vector V>
auto imag (const V &v)
 Element-wise imag for vectors -> dense_vector<magnitude_t<T>>.
template<Matrix M>
auto imag (const M &m)
 Element-wise imag for matrices -> dense2D<magnitude_t<T>>.
template<typename Accumulator = void, FieldMatrix M>
auto inv (const M &A)
 Compute the inverse of a square matrix A via LU factorization.
template<Matrix MA, Matrix MB>
auto kron (const MA &A, const MB &B)
 Kronecker product: C = A (x) B, where C(i*rb+p, j*cb+q) = A(i,j)*B(p,q).
template<typename Expr>
requires (Matrix<Expr> && traits::is_expression_v<Expr>)
auto evaluate (const Expr &expr)
 Materialize a matrix expression into a concrete dense2D.
template<typename Expr>
requires (Vector<Expr> && !Matrix<Expr> && traits::is_expression_v<Expr>)
auto evaluate (const Expr &expr)
 Materialize a vector expression into a concrete dense_vector.
template<typename T>
requires (!traits::is_expression_v<T>)
const T & evaluate (const T &x)
 Pass-through for concrete types (no-op).
template<typename Accumulator = void, FieldMatrix M>
int ldlt_factor (M &A)
 LDL^T factorization: A = L * D * L^T.
template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void ldlt_solve (const M &A, VecX &x, const VecB &b)
 Solve A*x = b using precomputed LDL^T factors stored in A.
template<typename Accumulator = void, FieldMatrix M>
int ldlt_h_factor (M &A)
 LDL^H factorization: A = L * D * L^H, for a HERMITIAN matrix.
template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void ldlt_h_solve (const M &A, VecX &x, const VecB &b)
 Solve A*x = b using precomputed LDL^H factors stored in A.
template<Matrix M>
void symmetric_swap (M &A, std::size_t r1, std::size_t r2, std::size_t first_col=0)
 Swap rows and columns r1 and r2 in the lower triangle of a symmetric matrix, touching only columns >= first_col.
template<typename Accumulator = void, FieldMatrix M>
int ldlt_bk_factor (M &A, bk_pivot_info &pivots)
 Bunch-Kaufman pivoted LDL^T factorization: P*A*P^T = L*D*L^T.
template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void ldlt_bk_solve (const M &A, const bk_pivot_info &pivots, VecX &x, const VecB &b)
 Solve A*x = b using precomputed Bunch-Kaufman LDL^T factors.
template<Vector V>
auto log (const V &v)
 Element-wise log for vectors.
template<Matrix M>
auto log (const M &m)
 Element-wise log for matrices.
template<Vector V>
auto log10 (const V &v)
 Element-wise log10 for vectors.
template<Matrix M>
auto log10 (const M &m)
 Element-wise log10 for matrices.
template<Vector V>
auto log2 (const V &v)
 Element-wise log2 for vectors.
template<Matrix M>
auto log2 (const M &m)
 Element-wise log2 for matrices.
template<typename Accumulator = void, FieldMatrix M>
auto logm (const M &A)
 The principal logarithm of a square matrix: the X with exp(X) = A whose eigenvalues have imaginary parts in (-pi, pi), as a dense2D of A's element type.
template<typename Accumulator = void, Matrix M, Vector VecX, Vector VecB>
void lower_trisolve (const M &L, VecX &x, const VecB &b, bool unit_diag=false)
 Solve L*x = b by forward substitution where L is lower triangular.
template<typename Accumulator = void, Matrix M, Vector VecX>
void lower_trisolve (const M &L, VecX &x, bool unit_diag=false)
 In-place variant: solve L*x = x (b is x on input).
template<typename Accumulator = void, FieldMatrix M>
int lq_factor (M &A, vec::dense_vector< typename M::value_type > &tau)
 LQ factorization: A (m x n, n >= m) is overwritten with L on+below diagonal and Householder vectors above diagonal.
template<FieldMatrix M>
int lq_factor (M &A, vec::dense_vector< typename M::value_type > &tau, tag::textbook_reflector)
 LQ factorization with the textbook Householder reflector (#559): the row mirror of qr_factor(A, tau, tag::textbook_reflector{}).
template<typename Accumulator = void, Matrix M>
auto lq_extract_Q (const M &A, const vec::dense_vector< typename M::value_type > &tau)
 Extract explicit Q (n x n) from LQ factorization stored in A and tau.
template<Matrix M>
auto lq_extract_L (const M &A)
 Extract explicit L (m x n) from LQ factorization stored in A.
template<Matrix ML, Matrix MQ>
void lq_normalize_signs (ML &L, MQ &Q)
 Make L's diagonal non-negative: for each k < min(m, n) with L(k,k) < 0, negate column k of L and row k of Q.
template<typename Accumulator = void, FieldMatrix M>
int lu_factor (M &A, std::vector< typename M::size_type > &pivot)
 LU factorization with partial pivoting.
template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void lu_solve (const M &LU, const std::vector< typename M::size_type > &pivot, VecX &x, const VecB &b)
 Solve A*x = b using precomputed LU factorization.
template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void lu_adjoint_solve (const M &LU, const std::vector< typename M::size_type > &pivot, VecX &x, const VecB &b)
 Solve A^H * x = b using the precomputed LU factorization of A.
template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
int lu_apply (M &A, VecX &x, const VecB &b)
 Convenience: factor and solve A*x = b in one call.
template<typename Working, typename Residual, typename PA, typename PV>
lu_refine_result lu_iterative_refine (const mat::dense2D< Residual, PA > &A, const vec::dense_vector< Residual, PV > &b, vec::dense_vector< Residual, PV > &x, const lu_refine_options &opt={})
 Solve A x = b by LU iterative refinement.
template<Matrix M>
bool is_square (const M &A)
 A.num_rows() == A.num_cols().
template<Matrix M>
bool is_empty (const M &A)
 A has no rows or no columns.
template<Matrix M>
bool is_symmetric (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 A == A^T (within tol). Non-square matrices are never symmetric.
template<Matrix M>
bool is_hermitian (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 A == A^H (within tol): A(i,j) == conj(A(j,i)), and the diagonal is real.
template<Matrix M>
bool is_upper_triangular (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 Upper triangular: everything strictly below the main diagonal is ~0.
template<Matrix M>
bool is_lower_triangular (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 Lower triangular: everything strictly above the main diagonal is ~0.
template<Matrix M>
bool is_triangular (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 Upper or lower triangular.
template<Matrix M>
bool is_diagonal (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 Diagonal: every off-diagonal entry is ~0.
template<Matrix M>
bool is_banded (const M &A, std::size_t kl, std::size_t ku, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(0))
 Banded with lower bandwidth kl and upper bandwidth ku: an entry more than kl below (i - j > kl) or more than ku above (j - i > ku) the diagonal must be ~0.
template<Matrix M>
bool is_diagonally_dominant (const M &A, bool strict=false)
 Row diagonally dominant: |A(i,i)| >= sum_{j != i} |A(i,j)| for every row (strict: strictly greater).
template<Matrix M>
bool is_unitary (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(-1))
 Unitary: A is square and A^H A == I (within tol).
template<Matrix M>
bool is_orthogonal (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(-1))
 Orthogonal: alias for is_unitary (conventional name for real matrices).
template<Matrix M>
bool is_normal (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(-1))
 Normal: A is square and A A^H == A^H A (within tol) – the class of matrices unitarily diagonalizable, containing the symmetric/Hermitian, skew, and unitary matrices.
template<Collection C>
auto max (const C &c)
 Returns the maximum element value.
template<Collection C>
auto min (const C &c)
 Returns the minimum element value.
template<typename Accumulator = void, typename V, typename P, Vector VIn, Vector VOut>
void mult (const mat::view::transposed_view< mat::compressed2D< V, P > > &At, const VIn &x, VOut &y)
 y = A^T x for a transposed compressed2D.
template<typename Accumulator = void, Matrix M, Vector VIn, Vector VOut>
void mult (const M &A, const VIn &x, VOut &y)
 y = A x.
template<typename Accumulator = void, Matrix MA, Matrix MB, Matrix MC>
void mult (const MA &A, const MB &B, MC &C)
 mat*mat multiply into pre-allocated C: C = A * B.
template<typename Accumulator, Matrix MA, Matrix MB, Matrix MC>
void mult_quad (const MA &A, const MB &B, MC &C)
 C = A * B through the QUAD MULTIPLY-ACCUMULATE micro-kernel – VNNI vpdpbusd on x86, SDOT/UDOT on NEON (#451 phase 5).
template<Vector V>
auto negate (const V &v)
 Element-wise negation for vectors: -v[i].
template<Matrix M>
auto negate (const M &m)
 Element-wise negation for matrices: -m[r][c].
template<typename T, typename Apply, typename ApplyAdjoint>
detail::normest1_impl::real_of< T >::type normest1 (std::size_t n, Apply &&apply, ApplyAdjoint &&apply_adjoint, std::size_t t=2, int itmax=5)
 An estimate (a lower bound) of ||A||_1 for the n x n operator A, from apply(X) = A X and apply_adjoint(Y) = A^H Y on n x t blocks (dense2D<T>).
template<FieldMatrix M>
auto normest1 (const M &A, std::size_t t=2, int itmax=5)
 An estimate (a lower bound) of ||A||_1 for a square matrix, from products with A and A^H; see the operator overload.
template<Vector V>
auto one_norm (const V &v)
 one_norm(v) = sum(|v[i]|)
template<typename Accumulator = void, typename Result = void, Vector V>
auto two_norm (const V &v)
 two_norm(v) = sqrt(sum(|v[i]|^2)).
template<Vector V>
auto infinity_norm (const V &v)
 infinity_norm(v) = max(|v[i]|)
template<typename Accumulator = void, typename Result = void, Matrix M>
auto frobenius_norm (const M &m)
 frobenius_norm(m) = sqrt(sum(|m[i,j]|^2)).
template<Matrix M>
auto one_norm (const M &m)
 one_norm(m) = max column sum of |m[i,j]|
template<Matrix M>
auto infinity_norm (const M &m)
 infinity_norm(m) = max row sum of |m[i,j]|
template<Matrix M>
auto num_cols (const M &m)
 Return the number of columns.
template<Matrix M>
auto num_rows (const M &m)
 Return the number of rows.
template<Vector V, Scalar S>
auto pow (const V &v, const S &exponent)
 Element-wise pow for vectors: pow(v[i], exponent).
template<Matrix M, Scalar S>
auto pow (const M &m, const S &exponent)
 Element-wise pow for matrices: pow(m[r][c], exponent).
template<Vector V>
std::ostream & operator<< (std::ostream &os, const V &v)
 Print a vector: [v0, v1, ..., vn].
template<Matrix M>
std::ostream & operator<< (std::ostream &os, const M &m)
 Print a matrix in row-by-row format.
template<Vector V>
void print (std::ostream &os, const V &v, int precision=6)
 Print a vector to a stream with configurable precision.
template<Matrix M>
void print (std::ostream &os, const M &m, int precision=6)
 Print a matrix to a stream with configurable precision.
template<typename Value, typename Parameters>
void print_sparse (std::ostream &os, const mat::compressed2D< Value, Parameters > &A, int precision=6)
 Print sparse matrix in triplet format: (row, col) = value.
template<Matrix M>
void print_matlab (std::ostream &os, const M &m, const std::string &name="A", int precision=6)
 Print matrix in MATLAB format: name = [v1 v2 ...; v3 v4 ...; ...].
template<Collection C>
auto product (const C &c)
 Returns the product of all elements: product(c[i]).
template<Scalar Target, Scalar Source>
requires ProjectableOnto<Target, Source>
vec::dense_vector< Target > project_onto (const vec::dense_vector< Source > &src)
 Project a dense vector onto a narrower element type.
template<Scalar Target, Scalar Source, Scalar ScaleType>
requires ProjectableOnto<Target, Source>
vec::dense_vector< Target > project_onto (const vec::dense_vector< Source > &src, ScaleType scale)
 Scaled projection of a dense vector with saturating conversion.
template<Scalar Target, Scalar Source>
requires ProjectableOnto<Target, Source>
mat::dense2D< Target > project_onto (const mat::dense2D< Source > &src)
 Project a dense 2D matrix onto a narrower element type; integer targets saturate (see the vector overload).
template<Scalar Target, Scalar Source, Scalar ScaleType>
requires ProjectableOnto<Target, Source>
mat::dense2D< Target > project_onto (const mat::dense2D< Source > &src, ScaleType scale)
 Scaled projection of a dense 2D matrix with saturating conversion.
template<Scalar Target, Scalar Source>
requires EmbeddableInto<Target, Source>
vec::dense_vector< Target > embed_into (const vec::dense_vector< Source > &src)
 Embed a dense vector into a wider element type.
template<Scalar Target, Scalar Source, Scalar ScaleType>
requires EmbeddableInto<Target, Source>
vec::dense_vector< Target > embed_into (const vec::dense_vector< Source > &src, ScaleType scale)
 Scaled embedding of a dense vector with saturating conversion.
template<Scalar Target, Scalar Source>
requires EmbeddableInto<Target, Source>
mat::dense2D< Target > embed_into (const mat::dense2D< Source > &src)
 Embed a dense 2D matrix into a wider element type.
template<Scalar Target, Scalar Source, Scalar ScaleType>
requires EmbeddableInto<Target, Source>
mat::dense2D< Target > embed_into (const mat::dense2D< Source > &src, ScaleType scale)
 Scaled embedding of a dense 2D matrix with saturating conversion.
template<typename Accumulator = void, FieldMatrix M>
int qr_factor (M &A, vec::dense_vector< typename M::value_type > &tau)
 QR factorization: A (m x n, m >= n) is overwritten with R on+above diagonal and Householder vectors below diagonal.
template<FieldMatrix M>
int qr_factor (M &A, vec::dense_vector< typename M::value_type > &tau, tag::textbook_reflector)
 QR factorization with the textbook Householder reflector (#559).
template<typename Accumulator = void, Matrix M>
auto qr_extract_Q (const M &A, const vec::dense_vector< typename M::value_type > &tau)
 Extract explicit Q (m x m) from QR factorization stored in A and tau.
template<Matrix M>
auto qr_extract_R (const M &A)
 Extract explicit R (m x n) from QR factorization stored in A.
template<Matrix MQ, Matrix MR>
void qr_normalize_signs (MQ &Q, MR &R)
 Make R's diagonal non-negative: for each k < min(m, n) with R(k,k) < 0, negate row k of R and column k of Q.
template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void qr_solve (const M &QR, const vec::dense_vector< typename M::value_type > &tau, VecX &x, const VecB &b)
 Solve A*x = b via QR factorization (least-squares for m > n).
template<Vector V>
void fill_random (V &v, typename V::value_type lo, typename V::value_type hi, std::mt19937_64 &gen)
 Fill a vector with uniform random values in [lo, hi), drawn from gen.
template<Matrix M>
void fill_random (M &A, typename M::value_type lo, typename M::value_type hi, std::mt19937_64 &gen)
 Fill a matrix with uniform random values in [lo, hi), drawn from gen row by row.
template<Vector V>
void fill_random (V &v, typename V::value_type lo, typename V::value_type hi, std::uint64_t seed)
 Fill a vector with uniform random values in [lo, hi), reproducibly from seed.
template<Matrix M>
void fill_random (M &A, typename M::value_type lo, typename M::value_type hi, std::uint64_t seed)
 Fill a matrix with uniform random values in [lo, hi), reproducibly from seed.
template<Vector V>
void fill_random (V &v, typename V::value_type lo=typename V::value_type(0), typename V::value_type hi=typename V::value_type(1))
 Fill a vector with uniform random values in [lo, hi), non-deterministically.
template<Matrix M>
void fill_random (M &A, typename M::value_type lo=typename M::value_type(0), typename M::value_type hi=typename M::value_type(1))
 Fill a matrix with uniform random values in [lo, hi), non-deterministically.
template<typename T = double>
auto random_vector (std::size_t n, T lo, T hi, std::mt19937_64 &gen)
 A dense_vector of size n with uniform values in [lo, hi), drawn from gen.
template<typename T = double>
auto random_vector (std::size_t n, T lo, T hi, std::uint64_t seed)
 A dense_vector of size n with uniform values in [lo, hi), reproducibly from seed.
template<typename T = double>
auto random_vector (std::size_t n, T lo=T(0), T hi=T(1))
 A dense_vector of size n with uniform values in [lo, hi), non-deterministically.
template<typename T = double>
auto random_matrix (std::size_t m, std::size_t n, T lo, T hi, std::mt19937_64 &gen)
 An m x n dense2D with uniform values in [lo, hi), drawn from gen row by row.
template<typename T = double>
auto random_matrix (std::size_t m, std::size_t n, T lo, T hi, std::uint64_t seed)
 An m x n dense2D with uniform values in [lo, hi), reproducibly from seed.
template<typename T = double>
auto random_matrix (std::size_t m, std::size_t n, T lo=T(0), T hi=T(1))
 An m x n dense2D with uniform values in [lo, hi), non-deterministically.
template<Vector V>
auto real (const V &v)
 Element-wise real for vectors -> dense_vector<magnitude_t<T>>.
template<Matrix M>
auto real (const M &m)
 Element-wise real for matrices -> dense2D<magnitude_t<T>>.
template<Collection C>
auto resource (const C &c)
 Returns the resource descriptor of a collection (its size).
template<Vector V>
auto round (const V &v)
 Element-wise round for vectors.
template<Matrix M>
auto round (const M &m)
 Element-wise round for matrices.
template<typename Accumulator = void, Scalar S, MutableCollection C>
void scale (const S &alpha, C &c)
 In-place scale: c[i] *= alpha.
template<typename Accumulator = void, Scalar S, Collection C>
auto scaled (const S &alpha, const C &c)
 Returns a scaled copy of a vector.
template<typename Accumulator = void, FieldMatrix M>
auto schur (const M &A)
 Schur decomposition of a square matrix.
template<typename Value>
requires std::floating_point<Value>
schur_result< std::complex< Value > > rsf2csf (const mat::dense2D< Value > &Q, const mat::dense2D< Value > &T)
 Convert a real Schur decomposition A = Q T Q^T into the complex one, A = U R U^H with U unitary and R upper triangular, as MATLAB's rsf2csf does.
template<MutableCollection C>
void set_to_zero (C &c)
 Set all elements of a collection to zero.
template<Vector V>
auto signum (const V &v)
 Element-wise signum for vectors: +1, 0, or -1.
template<Matrix M>
auto signum (const M &m)
 Element-wise signum for matrices.
template<Vector V>
auto sin (const V &v)
 Element-wise sin for vectors.
template<Matrix M>
auto sin (const M &m)
 Element-wise sin for matrices.
template<Vector V>
auto sinh (const V &v)
 Element-wise sinh for vectors.
template<Matrix M>
auto sinh (const M &m)
 Element-wise sinh for matrices.
template<Collection C>
auto size (const C &c)
 Return the number of elements in a collection.
template<Matrix M, Vector VecX, Vector VecB>
void cholesky_solve_dispatch (const M &A, VecX &x, const VecB &b)
 Cholesky-based solve with automatic dispatch.
template<Matrix M, Vector VecX, Vector VecB>
void lu_solve_dispatch (const M &A, VecX &x, const VecB &b)
 LU-based solve with automatic dispatch.
template<Matrix M, Vector VecX, Vector VecB>
void qr_solve_dispatch (const M &A, VecX &x, const VecB &b)
 QR-based solve with automatic dispatch.
template<Matrix M, Vector VecX, Vector VecB>
void solve (const M &A, VecX &x, const VecB &b)
 General-purpose solve: A*x = b.
template<Matrix M>
magnitude_t< typename M::value_type > spectral_radius (const M &A)
 Spectral radius: max |eigenvalue|.
template<Matrix M>
magnitude_t< typename M::value_type > condition_number (const M &A)
 2-norm condition number sigma_max / sigma_min.
template<Matrix M>
magnitude_t< typename M::value_type > rcond (const M &A)
 Reciprocal 2-norm condition number sigma_min / sigma_max, in [0, 1] (0 for a rank-deficient or zero matrix).
template<Matrix M>
std::size_t numerical_rank (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(-1))
 Numerical rank: number of singular values above a threshold.
template<Matrix M>
std::size_t nullity (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(-1))
 Nullity: dimension of the null space = num_cols - numerical_rank.
template<Matrix M>
inertia_t inertia (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(-1))
template<Matrix M>
bool is_indefinite (const M &A, magnitude_t< typename M::value_type > tol=magnitude_t< typename M::value_type >(-1))
 Indefinite: a symmetric matrix with both positive and negative eigenvalues.
template<typename Accumulator = void, typename V1, typename P1, typename V2, typename P2>
auto spgemm (const mat::compressed2D< V1, P1 > &A, const mat::compressed2D< V2, P2 > &B)
 Sparse-sparse product C = A * B, all in CSR (compressed2D).
template<Vector V>
auto sqrt (const V &v)
 Element-wise sqrt for vectors.
template<Matrix M>
auto sqrt (const M &m)
 Element-wise sqrt for matrices.
template<typename Accumulator = void, FieldMatrix M>
auto sqrtm (const M &A)
 The principal square root of a square matrix: the X with X X = A whose eigenvalues have positive real parts, as a dense2D of A's element type.
template<typename Accumulator = void, Collection C>
auto sum (const C &c)
 Returns the sum of all elements: sum(c[i]).
template<int K, Collection C>
requires (K >= 1) && math::binary_floating_point<typename C::value_type>
auto sum_k (const C &x)
 The sum of x as if computed in K-fold working precision and rounded once: Ogita-Rump-Oishi SumK (K >= 2), and the plain recursive sum for K = 1.
template<int K, Vector V1, Vector V2>
requires (K >= 2) && std::is_same_v<typename V1::value_type, typename V2::value_type> && math::binary_floating_point<typename V1::value_type>
auto dot_k (const V1 &x, const V2 &y)
 The dot product of x and y as if computed in K-fold working precision and rounded once: Dot2 (Algorithm 5.3) for K = 2, DotK (Algorithm 5.10) for K >= 3.
template<typename Accumulator = void, FieldMatrix M>
void svd (const M &A, mat::dense2D< typename M::value_type > &U, mat::dense2D< typename M::value_type > &S, mat::dense2D< typename M::value_type > &V, typename M::value_type tol=std::numeric_limits< typename M::value_type >::epsilon())
 SVD: decompose A (m x n) = U * S * V^T U is m x m orthogonal, S is m x n diagonal (stored as m x n matrix), V is n x n orthogonal.
template<typename Accumulator = void, FieldMatrix M>
void svd (const M &A, vec::dense_vector< typename M::value_type > &s, mat::dense2D< typename M::value_type > &V, typename M::value_type tol=std::numeric_limits< typename M::value_type >::epsilon())
 SVD without U: the singular values s (length min(m,n), descending) and the n x n right singular vectors V, so that A * V(:,j) = s(j) * u_j for some unit u_j that is never formed (#566).
template<typename Accumulator = void, FieldMatrix M>
void svd (const M &A, mat::dense2D< typename M::value_type > &U, vec::dense_vector< typename M::value_type > &s, mat::dense2D< typename M::value_type > &V, typename M::value_type tol=std::numeric_limits< typename M::value_type >::epsilon())
 Thin SVD: A (m x n) = U * diag(s) * V^T with k = min(m, n), U m x k and V n x k, both with orthonormal columns, and s (length k) descending.
template<typename Accumulator = void, FieldMatrix M>
vec::dense_vector< typename M::value_type > null_vector (const M &A, typename M::value_type tol=std::numeric_limits< typename M::value_type >::epsilon())
 A unit vector x minimizing ||A x||: the right singular vector of A's smallest singular value, i.e.
template<typename Accumulator = void, FieldMatrix M>
auto svd (const M &A, typename M::value_type tol=std::numeric_limits< typename M::value_type >::epsilon())
 Convenience overload returning a tuple of (U, S, V).
template<typename Accumulator = void, FieldMatrix MA, FieldMatrix MB, FieldMatrix MC>
auto sylvester_triangular_scaled (const MA &A, const MB &B, const MC &C, sylvester_sign sign=sylvester_sign::plus)
 Solve A X + X B = scale * C (sylvester_sign::plus, the default) or A X - X B = scale * C (sylvester_sign::minus) for X and a scale factor 0 < scale <= 1, as LAPACK trsyl does.
template<typename Accumulator = void, FieldMatrix MA, FieldMatrix MB, FieldMatrix MC>
auto sylvester_triangular (const MA &A, const MB &B, const MC &C, sylvester_sign sign=sylvester_sign::plus)
 Solve A X + X B = C (sylvester_sign::plus, the default) or A X - X B = C (sylvester_sign::minus) for X, where A (m x m) and B (n x n) are upper quasi-triangular, as schur() returns them, or upper triangular, as rsf2csf() returns them.
template<typename Accumulator = void, FieldMatrix MA, FieldMatrix MB, FieldMatrix MC>
auto sylvester (const MA &A, const MB &B, const MC &C, sylvester_sign sign=sylvester_sign::plus)
 Solve A X + X B = C (sylvester_sign::plus, the default) or A X - X B = C (sylvester_sign::minus) for general square A (m x m) and B (n x n), and C (m x n), by the Bartels-Stewart method: A = Q_A T_A Q_A^H and B = Q_B T_B Q_B^H by schur(), then T_A Y + Y T_B = Q_A^H C Q_B by sylvester_triangular(), and X = Q_A Y Q_B^H.
template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB, Matrix MC>
void symm (const S &alpha, const MA &A, const MB &B, const S &beta, MC &C)
 Symmetric matrix-matrix product: C = alpha*A*B + beta*C, A assumed symmetric.
template<typename Accumulator = void, Scalar S, Matrix M, Vector VX, Vector VY>
void symv (const S &alpha, const M &A, const VX &x, const S &beta, VY &y)
 Symmetric matrix-vector product: y = alpha*A*x + beta*y, A assumed symmetric.
template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB, Matrix MC>
void syr2k (const S &alpha, const MA &A, const MB &B, const S &beta, MC &C)
 Symmetric rank-2k update: C = alpha*(A*B^T + B*A^T) + beta*C, C symmetric.
template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MC>
void syrk (const S &alpha, const MA &A, const S &beta, MC &C)
 Symmetric rank-k update: C = alpha*A*A^T + beta*C, C symmetric (full result).
template<Vector V>
auto tan (const V &v)
 Element-wise tan for vectors.
template<Matrix M>
auto tan (const M &m)
 Element-wise tan for matrices.
template<Vector V>
auto tanh (const V &v)
 Element-wise tanh for vectors.
template<Matrix M>
auto tanh (const M &m)
 Element-wise tanh for matrices.
template<typename Accumulator = void, Matrix M>
auto trace (const M &A)
 trace(A) = sum(A(i,i)) for i = 0..min(nrows,ncols)-1
template<Matrix M>
auto trans (const M &m)
 Returns a lightweight transposed view of matrix m.
template<Matrix M>
void trans (const M &&)=delete
 Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.
template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB>
void trmm (const S &alpha, const MA &A, MB &B, bool upper, bool unit_diag=false)
 Triangular matrix-matrix product: B = alpha * A * B, A upper/lower triangular.
template<typename Accumulator = void, Matrix M, Vector VX>
void trmv (const M &A, VX &x, bool upper, bool unit_diag=false)
 Triangular matrix-vector product: x = A*x, A upper/lower triangular.
template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB>
void trsm (const S &alpha, const MA &A, MB &B, bool upper, bool unit_diag=false)
 Triangular solve with multiple RHS: solve A * X = alpha * B, B := X.
template<typename Accumulator = void, Matrix M, Vector VX>
void trsv (const M &A, VX &x, bool upper, bool unit_diag=false)
 Solve A*x = x in place, A upper/lower triangular.
template<typename Accumulator = void, Matrix M, Vector VX, Vector VB>
void trsv (const M &A, VX &x, const VB &b, bool upper, bool unit_diag=false)
 Solve A*x = b, writing the solution into x (b unchanged).
template<typename Accumulator = void, Matrix M, Vector VecX, Vector VecB>
void upper_trisolve (const M &U, VecX &x, const VecB &b, bool unit_diag=false)
 Solve U*x = b by back substitution where U is upper triangular.
template<typename Accumulator = void, Matrix M, Vector VecX>
void upper_trisolve (const M &U, VecX &x, bool unit_diag=false)
 In-place variant: solve U*x = x (b is x on input).
template<typename Mag>
constexpr Mag default_norm_tol ()
 Default relative tolerance for the norm-based predicates: 128 * eps.
template<Vector V>
bool is_zero (const V &v, magnitude_t< typename V::value_type > tol=magnitude_t< typename V::value_type >(0))
 Every entry is within tol of zero (default tol 0: exactly zero).
template<Vector V>
bool is_finite (const V &v)
 Every entry is finite (no NaN, no +/-Inf).
template<Vector V>
bool has_nan (const V &v)
 At least one entry is NaN.
template<Vector V>
bool has_inf (const V &v)
 At least one entry is +/-Inf.
template<Vector V>
bool is_normalized (const V &v, magnitude_t< typename V::value_type > tol=default_norm_tol< magnitude_t< typename V::value_type > >())
 Unit 2-norm within a relative tolerance (default 128 * eps).
template<Vector V>
bool is_unit (const V &v, magnitude_t< typename V::value_type > tol=default_norm_tol< magnitude_t< typename V::value_type > >())
 Alias for is_normalized.
template<Vector V1, Vector V2>
bool is_orthogonal_to (const V1 &u, const V2 &v, magnitude_t< typename V1::value_type > tol=default_norm_tol< magnitude_t< typename V1::value_type > >())
 Numerically orthogonal: |<u,v>| <= tol * ||u|| * ||v|| (relative; default tol 128 * eps).
template<typename Value, typename Params>
dense2D< Value, Params > reorder_rows (const dense2D< Value, Params > &A, const std::vector< std::size_t > &perm)
 Reorder rows: B(i,:) = A(perm[i],:).
template<typename Value, typename Params>
dense2D< Value, Params > reorder_cols (const dense2D< Value, Params > &A, const std::vector< std::size_t > &perm)
 Reorder columns: B(:,j) = A(:,perm[j]).
template<typename Value, typename Params>
dense2D< Value, Params > reorder (const dense2D< Value, Params > &A, const std::vector< std::size_t > &perm)
 Symmetric reorder: B = P * A * P^T B(i,j) = A(perm[i], perm[j]).
template<typename Value = double>
dense_vector< Value > unit_vector (std::size_t n, std::size_t k)
 Create a unit vector of size n with 1 at position k, 0 elsewhere.

Variables

template<typename T>
constexpr bool is_complex_v = is_complex<std::remove_cv_t<T>>::value
 Whether T is a std::complex, cv-qualifiers ignored (#838).
constexpr std::size_t stack_size_limit = 256
 Threshold below which matrices are stored on the stack.
constexpr std::size_t default_block_size = 64
 Default block size for recursive operations.
constexpr bool bounds_checking = true
 Enable/disable bounds checking (debug builds).
template<BlockScheme S>
constexpr std::size_t block_gemv_scratch_alignment = detail::block_scratch_alignment<S>()
 The alignment that scratch must have: the fused kernel's scratch_alignment, which must be a power of two, or alignof(std::max_align_t).
template<typename S>
constexpr bool host_accessible_v
 Whether host code may read and write elements in space S; false for a type that is not a MemorySpace.
constexpr int CHOLESKY_NOT_HERMITIAN = -2
 Returned by cholesky_h_factor when the input is complex and has a non-real diagonal, which a Hermitian matrix cannot have.
constexpr int LDLT_NOT_SYMMETRIC = -1
 Returned by ldlt_factor when the input is complex and Hermitian but not symmetric – i.e.
constexpr int LDLT_NOT_HERMITIAN = -2
 Returned by ldlt_h_factor when the input is complex and has a non-real diagonal, which a Hermitian matrix cannot have – i.e.

Typedef Documentation

◆ default_size_type

using mtl::default_size_type = std::size_t

Default size type for indices and dimensions.

◆ inserter

template<typename Matrix, typename Updater = update_store<typename Matrix::value_type>>
using mtl::mat::inserter

Convenience alias: inserter<MatrixType, Updater>.

◆ magnitude_t

template<typename T>
using mtl::magnitude_t = typename magnitude_trait<std::remove_cv_t<T>>::type

Alias for the magnitude type of T, cv-qualifiers ignored (#838): magnitude_t<const std::complex<double>> is double.

Enumeration Type Documentation

◆ gemmt_fill

enum class mtl::gemmt_fill
strong

What gemmt does with the triangle it does not form.

Enumerator
mirror 

copy the formed triangle across the diagonal (default)

keep 

leave it as it was

◆ sylvester_sign

enum class mtl::sylvester_sign
strong

The sign between the two terms of a Sylvester equation: plus for A X + X B = C, minus for A X - X B = C.

Enumerator
plus 
minus 

◆ uplo

enum class mtl::uplo
strong

Which triangle of a square matrix an operation forms or reads.

Enumerator
lower 
upper 

Function Documentation

◆ abs() [1/2]

template<Matrix M>
auto mtl::abs ( const M & m)

Element-wise abs for matrices -> dense2D<magnitude_t<T>>.

◆ abs() [2/2]

template<Vector V>
auto mtl::abs ( const V & v)

Element-wise abs for vectors -> dense_vector<magnitude_t<T>>.

◆ acos() [1/2]

template<Matrix M>
auto mtl::acos ( const M & m)

Element-wise acos for matrices.

◆ acos() [2/2]

template<Vector V>
auto mtl::acos ( const V & v)

Element-wise acos for vectors.

◆ acosh() [1/2]

template<Matrix M>
auto mtl::acosh ( const M & m)

Element-wise acosh for matrices.

◆ acosh() [2/2]

template<Vector V>
auto mtl::acosh ( const V & v)

Element-wise acosh for vectors.

◆ apply_givens_rotation()

template<typename Matrix, typename VecG, typename VecC, typename VecS>
void mtl::apply_givens_rotation ( Matrix & H,
VecG & g,
VecC & c,
VecS & s,
typename Matrix::size_type k )

Compute new Givens rotation for column k of Hessenberg H, apply it to H and RHS vector g, and store the rotation in c, s.

◆ apply_householder_left() [1/2]

template<typename Accumulator = void, Matrix M, typename T>
void mtl::apply_householder_left ( M & A,
const vec::dense_vector< T > & v,
T beta,
typename M::size_type row,
typename M::size_type col )

Apply Householder reflection H = I - beta*v*v^H on the LEFT (A := H*A) to columns col..ncols-1 of matrix A, rows row..nrows-1.

Modifies A in-place.

◆ apply_householder_left() [2/2]

template<Matrix M, typename T>
void mtl::apply_householder_left ( M & A,
const vec::dense_vector< T > & v,
T vtv,
typename M::size_type row,
typename M::size_type col,
tag::textbook_reflector  )

Apply a textbook reflector H = I - (2/vtv)*v*v^T on the LEFT (A := H*A) to columns col..ncols-1, rows row..row+v.size()-1 (#559).

Real T only. Each column j is updated as a hand-written loop does it:

s = sum_i v(i)*A(row+i, j) from zero, ascending i f = (2*s) / vtv A(row+i, j) -= f*v(i)

Does nothing when !(vtv > 0), i.e. for a skipped (zero or NaN) column. Columns are independent, so they are split across the thread pool and the result doesn't depend on the thread count.

◆ apply_householder_right() [1/2]

template<typename Accumulator = void, Matrix M, typename T>
void mtl::apply_householder_right ( M & A,
const vec::dense_vector< T > & v,
T beta,
typename M::size_type row,
typename M::size_type col )

Apply Householder reflection on the right: A := A * (I - beta*v*v^H).

NOTE this is A*H, not A*H^H – for complex tau those differ, and a caller wanting the inverse/adjoint must pass conj(beta) itself. Modifies columns col..col+vlen-1 of rows row..nrows-1.

◆ apply_householder_right() [2/2]

template<Matrix M, typename T>
void mtl::apply_householder_right ( M & A,
const vec::dense_vector< T > & v,
T vtv,
typename M::size_type row,
typename M::size_type col,
tag::textbook_reflector  )

Apply a textbook reflector H = I - (2/vtv)*v*v^T on the RIGHT (A := A*H) to rows row..nrows-1, columns col..col+v.size()-1 (#559).

Real T only, so H = H^T and there is no conjugate to place. Each row i is updated as a hand-written loop does it:

s = sum_j A(i, col+j)*v(j) from zero, ascending j f = (2*s) / vtv A(i, col+j) -= f*v(j)

Does nothing when !(vtv > 0), i.e. for a skipped (zero or NaN) row. Rows are independent, so they are split across the thread pool and the result doesn't depend on the thread count.

◆ apply_stored_rotation()

template<typename Matrix, typename Vector>
void mtl::apply_stored_rotation ( Matrix & H,
const Vector & c,
const Vector & s,
typename Matrix::size_type i,
typename Matrix::size_type k )

Apply a previously stored Givens rotation to column k of Hessenberg H at rows i, i+1: [H(i,k); H(i+1,k)] <- [c s; -conj(s) c] [H(i,k); H(i+1,k)].

For a real element type conj is the identity, so this is [c s; -s c] (#853: the conjugate was missing, so a complex rotation was not unitary).

◆ asin() [1/2]

template<Matrix M>
auto mtl::asin ( const M & m)

Element-wise asin for matrices.

◆ asin() [2/2]

template<Vector V>
auto mtl::asin ( const V & v)

Element-wise asin for vectors.

◆ asinh() [1/2]

template<Matrix M>
auto mtl::asinh ( const M & m)

Element-wise asinh for matrices.

◆ asinh() [2/2]

template<Vector V>
auto mtl::asinh ( const V & v)

Element-wise asinh for vectors.

◆ atan() [1/2]

template<Matrix M>
auto mtl::atan ( const M & m)

Element-wise atan for matrices.

◆ atan() [2/2]

template<Vector V>
auto mtl::atan ( const V & v)

Element-wise atan for vectors.

◆ atanh() [1/2]

template<Matrix M>
auto mtl::atanh ( const M & m)

Element-wise atanh for matrices.

◆ atanh() [2/2]

template<Vector V>
auto mtl::atanh ( const V & v)

Element-wise atanh for vectors.

◆ axpy()

template<typename Accumulator = void, Scalar S, Vector VX, Vector VY>
void mtl::axpy ( const S & alpha,
const VX & x,
VY & y )

y[i] += alpha * x[i]

Mixed precision: pass an explicit Accumulator to form each element's update in a precision distinct from the operand type; the result is rounded out to y's element type on store (#261, Part C). The default Accumulator = void keeps today's SIMD / generic dispatch byte for byte.

WHY AN AXPY HAS AN ACCUMULATOR AT ALL, when it sums nothing. Each element is y(i) + alpha * x(i) – a one-term sum of products, seeded with y(i) rather than with zero. That is exactly the shape accumulator_traits describes, and the configurations do what they do everywhere else:

config 1 the product is formed in Acc and rounded, then added, and the sum is rounded out to y's type: an Acc wider than the element type buys precision, a narrower one deliberately spends it. config 2 fma_accumulator<T> fuses the product into the sum – one rounding per element rather than two. config 3 a quire holds y(i) and the product exactly; the single rounding is the store.

THE DEFAULT'S ROUNDING IS DISPATCH-DEPENDENT, and that is the strongest argument for the policy. Accumulator = void may reach any of three paths, which do not agree with each other:

simd::axpy body fma(alpha, x, y), fused, one rounding simd::axpy tail wrap_add(y, wrap_mul(alpha, x)), NOT fused, two generic loop y + alpha*x, not fused, two

So a vector shorter than one SIMD lane group is rounded differently from a long one. (Before #754 a BLAS build reached the vendor's ?axpy, whose rounding is unspecified, as a fourth path.) An explicit Accumulator is how a caller PINS the rounding across all of them – axpy<fma_accumulator<T>> is fused on every path, by construction.

This was originally documented here as "the default is already fused", from a build whose batch<float>::size is 1 so the tail never runs and no BLAS is linked. The Highway and LAPACK CI lanes disagreed. The body/tail split predates this change and is not touched here; it is recorded on #261.

This is the first caller to exercise the contract's assign. The reduction kernels all start from zero and use clear; an axpy starts from y(i), which is what assign is for, so a quire specialization that stubbed it out would be found here rather than in a peer-repo integration.

◆ banded() [1/2]

template<typename Matrix>
void mtl::banded ( const Matrix && ,
std::ptrdiff_t ,
std::ptrdiff_t  )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ banded() [2/2]

template<typename Matrix>
auto mtl::banded ( const Matrix & A,
std::ptrdiff_t lower,
std::ptrdiff_t upper )

Create a banded view of matrix A with given lower and upper bandwidth.

◆ block_gemv_scratch_bytes()

template<BlockScheme S>
std::size_t mtl::block_gemv_scratch_bytes ( std::size_t cols)

Scratch bytes mult() needs for a block matrix of scheme S with cols columns: the fused kernel's scratch_bytes(cols), or 0 when the scheme has no fused kernel or its kernel declares none.

◆ cbrt() [1/2]

template<Matrix M>
auto mtl::cbrt ( const M & m)

Element-wise cbrt for matrices.

◆ cbrt() [2/2]

template<Vector V>
auto mtl::cbrt ( const V & v)

Element-wise cbrt for vectors.

◆ ceil() [1/2]

template<Matrix M>
auto mtl::ceil ( const M & m)

Element-wise ceil for matrices.

◆ ceil() [2/2]

template<Vector V>
auto mtl::ceil ( const V & v)

Element-wise ceil for vectors.

◆ cholesky_factor() [1/3]

template<typename Accumulator = void, FieldMatrix M>
int mtl::cholesky_factor ( M & A)

Cholesky factorization: A = L * L^T, for a REAL symmetric positive definite A.

The lower triangle of A is overwritten with L. Upper triangle is untouched. Returns 0 on success, k+1 if the k-th pivot is not positive (not SPD), which includes a NaN pivot.

Each entry is formed as a - (sum of products): the products are summed from zero and subtracted once (tag::subtract_sum). Dispatches to LAPACK potrf when MTL5_HAS_LAPACK is defined and the matrix qualifies.

Complex element types are rejected at compile time; use cholesky_h_factor.

A non-void Accumulator forms each entry as one reduction (see the top of this file) and never dispatches to LAPACK.

◆ cholesky_factor() [2/3]

template<FieldMatrix M>
int mtl::cholesky_factor ( M & A,
tag::subtract_sum  )

cholesky_factor(A), with the default summation order named explicitly.

◆ cholesky_factor() [3/3]

template<FieldMatrix M>
int mtl::cholesky_factor ( M & A,
tag::subtract_term_by_term  )

Cholesky factorization A = L * L^T with each entry formed TERM BY TERM: start from the matrix entry and subtract each product in turn (#556),.

s = A(i,j); s = s - L(i,k) * L(j,k) for k = 0 .. j-1; L(i,j) = s / L(j,j)

which is the form many hand-written factorizations use. It rounds differently from the default, so a caller whose results are pinned to that form can reproduce them bit for bit (under the same FP contraction setting). This overload never dispatches to LAPACK, whose summation order is its own. Same return codes as cholesky_factor(A).

◆ cholesky_h_factor()

template<typename Accumulator = void, FieldMatrix M>
int mtl::cholesky_h_factor ( M & A)

Cholesky factorization: A = L * L^H, for a HERMITIAN positive definite A.

The lower triangle of A is overwritten with L, whose diagonal is REAL for a Hermitian A and is stored in the element type with a zero imaginary part. Only the lower triangle is read, so the caller's upper triangle is irrelevant and need not be populated consistently.

Returns 0 on success, k+1 if the k-th pivot is not positive (not HPD), or CHOLESKY_NOT_HERMITIAN if the diagonal is not real – a Hermitian matrix cannot have one, so that input does not belong here.

For real element types conjugation is the identity and this is exactly cholesky_factor – see the note at the top of this file (#353).

A non-void Accumulator forms each entry as one reduction and never dispatches to LAPACK; for a real element type it forwards to cholesky_factor<Accumulator>, so the two stay bit-identical.

◆ cholesky_h_solve()

template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void mtl::cholesky_h_solve ( const M & L,
VecX & x,
const VecB & b )

Solve A*x = b using precomputed Cholesky factors of a HERMITIAN A, i.e.

the L of A = L*L^H stored in the lower triangle by cholesky_h_factor. Solves L*y = b (forward), then L^H*x = y (backward). Accumulator forms each row's sum of products.

◆ cholesky_solve()

template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void mtl::cholesky_solve ( const M & L,
VecX & x,
const VecB & b )

Solve A*x = b using precomputed Cholesky factor L (stored in lower triangle of A).

Solves L*y = b (forward), then L^T*x = y (backward). Accumulator forms each row's sum of products.

◆ cholesky_solve_dispatch()

template<Matrix M, Vector VecX, Vector VecB>
void mtl::cholesky_solve_dispatch ( const M & A,
VecX & x,
const VecB & b )

Cholesky-based solve with automatic dispatch.

For sparse double (dense_vector<double> x, b) with CHOLMOD: uses CHOLMOD. For sparse (any type): uses native sparse Cholesky with AMD ordering. For dense: uses in-place dense Cholesky.

◆ condition_number()

template<Matrix M>
magnitude_t< typename M::value_type > mtl::condition_number ( const M & A)

2-norm condition number sigma_max / sigma_min.

A rank-deficient matrix (sigma_min == 0) has an infinite condition number. The degenerate empty matrix returns 1 (a trivial isometry).

◆ congruence() [1/4]

template<typename Accumulator = void, Matrix MA, Matrix MP, Matrix MC>
void mtl::congruence ( const MA & A,
const MP & P,
MC & C )

C = A*P*A^T.

◆ congruence() [2/4]

template<typename Accumulator = void, Matrix MA, Vector VR, Matrix MC>
requires (!Matrix<VR>)
void mtl::congruence ( const MA & A,
const VR & r,
MC & C )

C = A*diag(r)*A^T.

◆ congruence() [3/4]

template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MP, Matrix MC>
void mtl::congruence ( const S & alpha,
const MA & A,
const MP & P,
const S & beta,
MC & C )

Congruence: C = alpha * A*P*A^T + beta*C, for a symmetric m x m result.

A is m x n, dense or compressed2D; P is n x n. Computed as T = A*P with mult, then gemmt(T, A^T), so C is exactly symmetric and its lower triangle rounds as mult(mult(A, P), trans(A)) does on the generic path. P's symmetry is the caller's promise; it is not checked or exploited. With beta != 0, C must be symmetric too: only its lower triangle is read, and the result's upper triangle is the mirror of the lower one.

◆ congruence() [4/4]

template<typename Accumulator = void, Scalar S, Matrix MA, Vector VR, Matrix MC>
requires (!Matrix<VR>)
void mtl::congruence ( const S & alpha,
const MA & A,
const VR & r,
const S & beta,
MC & C )

Congruence with a diagonal middle term: C = alpha * A*diag(r)*A^T + beta*C.

The Joseph-form term K*R*K^T for a diagonal R. T(i,k) = A(i,k)*r(k) is formed directly (one rounding per entry, as mult by diag(r) gives), then gemmt(T, A^T) as in the dense-middle overload. With beta != 0, C must be symmetric, as there.

◆ conj() [1/2]

template<Matrix M>
auto mtl::conj ( const M & m)

Element-wise conjugation for matrices.

◆ conj() [2/2]

template<Vector V>
auto mtl::conj ( const V & v)

Element-wise conjugation for vectors.

◆ convert() [1/6]

template<typename DstValue, BlockScheme S>
mat::dense2D< DstValue > mtl::convert ( const mat::block_matrix_view< S > & src)

Decode a block matrix into a new dense2D<DstValue>.

◆ convert() [2/6]

template<BlockScheme S, Matrix MDst>
void mtl::convert ( const mat::block_matrix_view< S > & src,
MDst & dst )

Decode a block matrix into a pre-allocated destination, a row at a time.

◆ convert() [3/6]

template<typename DstValue, Matrix MSrc>
mat::dense2D< DstValue > mtl::convert ( const MSrc & src)

Convert a matrix to a new dense2D<DstValue> (out-of-place convenience).

◆ convert() [4/6]

template<Matrix MSrc, Matrix MDst>
void mtl::convert ( const MSrc & src,
MDst & dst )

Convert a matrix into a pre-allocated destination of (possibly) another type.

◆ convert() [5/6]

template<typename DstValue, Vector VSrc>
vec::dense_vector< DstValue > mtl::convert ( const VSrc & src)

Convert a vector to a new dense_vector<DstValue> (out-of-place convenience).

◆ convert() [6/6]

template<Vector VSrc, Vector VDst>
void mtl::convert ( const VSrc & src,
VDst & dst )

Convert a vector into a pre-allocated destination of (possibly) another type.

◆ copy() [1/4]

template<typename V, typename P1, typename P2>
requires (!mat::dense2D<V, P2>::read_only && std::is_same_v<typename P1::orientation, typename P2::orientation> && std::is_same_v<typename P1::index_type, typename P2::index_type>)
void mtl::copy ( const mat::dense2D< V, P1 > & src,
mat::dense2D< V, P2 > && dst )

A temporary target, such as a view built at the call site: written through.

◆ copy() [2/4]

template<typename V, typename P1, typename P2>
requires (!mat::dense2D<V, P2>::read_only && std::is_same_v<typename P1::orientation, typename P2::orientation> && std::is_same_v<typename P1::index_type, typename P2::index_type>)
void mtl::copy ( const mat::dense2D< V, P1 > & src,
mat::dense2D< V, P2 > & dst )

dst receives src's elements (#1017).

Both matrices have the same value type, orientation and index base; other dimensions throw std::length_error. Blocking.

◆ copy() [3/4]

template<typename V, typename P1, typename P2>
requires (!vec::dense_vector<V, P2>::read_only && std::is_same_v<typename P1::orientation, typename P2::orientation>)
void mtl::copy ( const vec::dense_vector< V, P1 > & src,
vec::dense_vector< V, P2 > && dst )

A temporary target, such as a view built at the call site: written through.

◆ copy() [4/4]

template<typename V, typename P1, typename P2>
requires (!vec::dense_vector<V, P2>::read_only && std::is_same_v<typename P1::orientation, typename P2::orientation>)
void mtl::copy ( const vec::dense_vector< V, P1 > & src,
vec::dense_vector< V, P2 > & dst )

dst receives src's elements (#1017).

Both vectors have the same value type and orientation; a different length throws std::length_error. Blocking.

◆ copy_to() [1/2]

template<typename Space, typename V, typename P>
auto mtl::copy_to ( const mat::dense2D< V, P > & x)

A new owning matrix in Space holding x's elements (#1017).

Space must be able to allocate. Always a copy, even when Space is x's own space.

◆ copy_to() [2/2]

template<typename Space, typename V, typename P>
auto mtl::copy_to ( const vec::dense_vector< V, P > & x)

A new owning vector in Space holding x's elements (#1017).

Space must be able to allocate. Always a copy, even when Space is x's own space.

◆ cos() [1/2]

template<Matrix M>
auto mtl::cos ( const M & m)

Element-wise cos for matrices.

◆ cos() [2/2]

template<Vector V>
auto mtl::cos ( const V & v)

Element-wise cos for vectors.

◆ cosh() [1/2]

template<Matrix M>
auto mtl::cosh ( const M & m)

Element-wise cosh for matrices.

◆ cosh() [2/2]

template<Vector V>
auto mtl::cosh ( const V & v)

Element-wise cosh for vectors.

◆ default_norm_tol()

template<typename Mag>
Mag mtl::default_norm_tol ( )
constexpr

Default relative tolerance for the norm-based predicates: 128 * eps.

◆ determinant()

template<Matrix M>
M::value_type mtl::determinant ( const M & A)

Determinant via LU: sign(permutation) * product of U(k,k).

Returns exactly zero when LU reports a zero pivot (singular). The empty (0x0) determinant is one by convention. Requires a square matrix. Runs LU on a copy; O(n^3).

◆ diag()

template<typename T>
auto mtl::diag ( const vec::dense_vector< T > & v)

Construct an n x n diagonal sparse matrix from a vector (inverse of diagonal).

◆ diagonal()

template<Matrix M>
auto mtl::diagonal ( const M & A)

Returns a dense_vector containing the diagonal entries A(i,i).

◆ dot()

template<typename Accumulator = void, typename Result = Accumulator, Vector V1, Vector V2>
auto mtl::dot ( const V1 & v1,
const V2 & v2 )

Hermitian dot product: sum(conj(v1[i]) * v2[i]).

Mixed precision: pass an explicit Accumulator to sum the products in a precision distinct from the element type (e.g. dot<float>(a, b) over bfloat16 vectors accumulates in fp32), and an optional Result to round the sum out to a delivery type (default = the accumulator type). With the default Accumulator = void, behavior is unchanged (SIMD fast path or the common-type loop). The mixed path is scalar; a SIMD variant is a follow-up.

◆ dot_k()

template<int K, Vector V1, Vector V2>
requires (K >= 2) && std::is_same_v<typename V1::value_type, typename V2::value_type> && math::binary_floating_point<typename V1::value_type>
auto mtl::dot_k ( const V1 & x,
const V2 & y )

The dot product of x and y as if computed in K-fold working precision and rounded once: Dot2 (Algorithm 5.3) for K = 2, DotK (Algorithm 5.10) for K >= 3.

Real vectors of one binary IEEE type. See the header for the bound.

◆ dot_real()

template<typename Accumulator = void, typename Result = Accumulator, Vector V1, Vector V2>
auto mtl::dot_real ( const V1 & v1,
const V2 & v2 )

Real dot product: sum(v1[i] * v2[i]) – no conjugation.

Mixed precision: see dot – pass Accumulator (and optional Result) to accumulate in a precision distinct from the element type.

◆ eigen()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::eigen ( const M & A,
typename M::value_type tol = 1e-10,
typename M::size_type max_iter = 0 )

Compute eigenvalues AND right eigenvectors of a general (non-symmetric) square matrix.

Returns {eigenvalues, eigenvectors} where: eigenvalues: dense_vector<complex> of size n eigenvectors: dense2D<complex> of size n x n, column k is the right eigenvector for eigenvalues(k), i.e. A * v_k = lambda_k * v_k

In-house path: the real Schur form A = Q T Q^T (Hessenberg reduction, then the Francis double-shift QR accumulating Q, as schur() runs it, on A scaled by a power of two), then each eigenvector of T by back-substitution on its quasi-triangular form, v_k = Q y_k (LAPACK dtrevc's method). That is O(n^3) in all. It used to factor a fresh complex n x n matrix A - lambda I for every eigenvalue, O(n^4): 0.38 s at n = 160 (#853). Eigenvectors are unit 2-norm with a canonical phase (largest entry made real-positive), and pair with the eigenvalues by column. The eigenvalues are T's, from the same Francis run: they agree with eigenvalue()'s to rounding at the given tol, but not necessarily in the same order (#894; compare them as a set). A repeated eigenvalue of a diagonalizable A gives independent vectors; for a defective A they are as ill-conditioned as the problem.

Throws std::invalid_argument for a non-square A or a NaN or infinite entry, and std::runtime_error when the iteration does not converge within max_iter sweeps per eigenvalue (default 100).

Dispatches to LAPACK geev (eigenvalues + right eigenvectors) when MTL5_HAS_LAPACK is defined and the type qualifies (dense2D<float/double>, either orientation); otherwise uses the in-house path above.

Accumulator (leading, default void) is forwarded to the Hessenberg reduction and its Q (#536), and a non-void accumulator skips geev. The QR iteration and the back-substitution keep plain arithmetic.

◆ eigen_symmetric()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::eigen_symmetric ( const M & A,
magnitude_t< typename M::value_type > tol = detail::default_eigen_tolerance<magnitude_t<typename M::value_type>>(),
typename M::size_type max_iter = 0 )

Compute eigenvalues and eigenvectors of a symmetric or Hermitian matrix.

Returns {eigenvalues, eigenvectors} where: eigenvalues: dense_vector of size n, sorted ascending. The eigenvalues of a Hermitian matrix are real, so the element type is the magnitude type magnitude_t<value_type> (== value_type real). eigenvectors: dense2D of size n x n, column k = eigenvector for eigenvalues(k)

so that A = Q * diag(eigenvalues) * Q^H (Q^T for a real matrix).

For complex Hermitian A the reduction is the UNITARY similarity A -> H*A*H^H (H^H = H^-1), and the Hermitian tridiagonal's phased subdiagonal is made real by a diagonal unitary D so the real symmetric QR can run. D preserves the eigenVALUES but rotates each eigenVECTOR by a per-row phase, so it must be folded into Q – skip it and eigenvalues still look right while A*v != lambda*v. For a real value_type conj() is the identity, D is the identity, real_t is value_type, and the arithmetic is bit-identical to the earlier H*A*H code.

Accumulator (leading, default void) is forwarded to every Householder call in the tridiagonalization, including the right-multiplications that accumulate Q (#536).

◆ eigen_symmetric_jacobi()

template<FieldMatrix M>
auto mtl::eigen_symmetric_jacobi ( const M & A,
typename M::value_type tol = std::numeric_limits<typename M::value_type>::epsilon(),
typename M::size_type max_sweeps = 0 )

Eigenvalues and eigenvectors of a real symmetric matrix by the cyclic-by-row two-sided Jacobi method.

Returns {eigenvalues, eigenvectors} exactly as eigen_symmetric does: eigenvalues ascending, column k of eigenvectors the unit eigenvector for eigenvalues(k), so that A = V * diag(eigenvalues) * V^T.

Why Jacobi: for a positive (semi)definite A it computes small eigenvalues, and their eigenvectors, to high RELATIVE accuracy (Demmel & Veselic, 1992), where tridiagonal QR (eigen_symmetric) is accurate only to about eps*||A|| in every eigenvalue. That matters for the null vector of a badly scaled normal matrix A^T A. It costs O(n^3) per sweep and takes several sweeps, so it is meant for small matrices: at n = 9..12 it is a few microseconds.

The rotation for pair (p,q) is the stable one, with theta = (a_qq - a_pp) / (2 a_pq), t = sign(theta) / (|theta| + sqrt(theta^2 + 1)), computed so that theta^2 cannot overflow. A pair is skipped when |a_pq| <= tol * sqrt(|a_pp|) * sqrt(|a_qq|), the relative test of Demmel & Veselic, and iteration stops after a sweep that rotates no pair; max_sweeps sweeps (default 60) that all rotate throw std::runtime_error. This, rather than a stop on off-diagonal mass <= tol^2 * ||A||_F^2, is what keeps small eigenvalues relatively accurate: a Frobenius-norm stop can leave an entry far below eps*||A|| that still couples two small eigenvalues and moves them both. An exactly zero diagonal entry cannot stall the test, since the rotation that zeroes a_pq also makes a_pp nonzero. No entry is ever squared, so matrices scaled to near the overflow or underflow threshold converge too.

Real element types only (posits and other custom reals included); a complex Hermitian A is rejected at compile time.

◆ eigenvalue()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::eigenvalue ( const M & A,
typename M::value_type tol = 1e-10,
typename M::size_type max_iter = 0 )

Compute eigenvalues of a general (non-symmetric) square matrix via the Francis implicit double-shift QR algorithm on the upper Hessenberg form.

Returns eigenvalues as a dense_vector of complex values (real and complex-conjugate pairs read from the 1x1/2x2 blocks of the real Schur form). Throws std::invalid_argument for a non-square A or a NaN or infinite entry, and std::runtime_error if the QR iteration fails to converge. The in-house path scales A by a power of two first, as schur() does (#853).

Dispatches to LAPACK geev when MTL5_HAS_LAPACK is defined and the type qualifies (dense2D<float/double>, either orientation); otherwise uses the in-house path above, which also serves custom number types (posits, LNS, ...).

Accumulator (leading, default void) is forwarded to the Householder Hessenberg reduction (#536). A non-void accumulator always takes the in-house path, since geev forms its sums its own way. The Francis QR iteration keeps plain arithmetic: its updates are fixed 2- and 3-term expressions, not sums.

◆ eigenvalue_symmetric()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::eigenvalue_symmetric ( const M & A,
magnitude_t< typename M::value_type > tol = detail::default_eigen_tolerance<magnitude_t<typename M::value_type>>(),
typename M::size_type max_iter = 0 )

Compute eigenvalues of a symmetric/Hermitian matrix via implicit QR on tridiagonal form.

Returns eigenvalues (real: magnitude_t<value_type>) sorted in ascending order. When MTL5_HAS_LAPACK is defined and the type qualifies, dispatches to LAPACK syev (real float/double) or heev == cheev/zheev (complex Hermitian); otherwise uses the in-house eigenvalue_symmetric_generic. The LAPACK Hermitian path is what test_lapack_dispatch cross-checks the native complex reduction against.

Accumulator (leading, default void) is forwarded to the generic path's tridiagonalization (#536). A non-void accumulator always takes the generic path, since syev/heev form their sums their own way.

◆ eigenvalue_symmetric_generic()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::eigenvalue_symmetric_generic ( const M & A,
magnitude_t< typename M::value_type > tol = detail::default_eigen_tolerance<magnitude_t<typename M::value_type>>(),
typename M::size_type max_iter = 0 )

Generic (LAPACK-free) symmetric/Hermitian eigenvalue solver: tridiagonalize, then run implicit QR with Wilkinson shifts on the tridiagonal form.

Returns the eigenvalues as a dense_vector sorted in ascending order. The eigenvalues of a Hermitian matrix are real, so the result element type is the magnitude type magnitude_t<value_type> (== value_type for a real matrix).

For a complex Hermitian A the reduction yields a Hermitian tridiagonal whose subdiagonal carries an arbitrary phase. Replacing each subdiagonal entry by its modulus is a diagonal unitary similarity D^H T D, which leaves the spectrum unchanged – so eigenVALUES need no phase bookkeeping. (Eigenvectors do: see eigen_symmetric, which accumulates D.)

This is the C++ reference path. eigenvalue_symmetric dispatches to LAPACK when available and otherwise calls this; benchmarks and tests can call this directly to exercise the generic algorithm regardless of MTL5_HAS_LAPACK.

Accumulator (leading, default void) is forwarded to the Householder tridiagonalization (#536). The implicit QR iteration that follows works on 2-term and 3-term expressions, not sums, and keeps plain arithmetic.

◆ embed_into() [1/4]

template<Scalar Target, Scalar Source>
requires EmbeddableInto<Target, Source>
mat::dense2D< Target > mtl::embed_into ( const mat::dense2D< Source > & src)

Embed a dense 2D matrix into a wider element type.

◆ embed_into() [2/4]

template<Scalar Target, Scalar Source, Scalar ScaleType>
requires EmbeddableInto<Target, Source>
mat::dense2D< Target > mtl::embed_into ( const mat::dense2D< Source > & src,
ScaleType scale )

Scaled embedding of a dense 2D matrix with saturating conversion.

◆ embed_into() [3/4]

template<Scalar Target, Scalar Source>
requires EmbeddableInto<Target, Source>
vec::dense_vector< Target > mtl::embed_into ( const vec::dense_vector< Source > & src)

Embed a dense vector into a wider element type.

◆ embed_into() [4/4]

template<Scalar Target, Scalar Source, Scalar ScaleType>
requires EmbeddableInto<Target, Source>
vec::dense_vector< Target > mtl::embed_into ( const vec::dense_vector< Source > & src,
ScaleType scale )

Scaled embedding of a dense vector with saturating conversion.

Typically used with the inverse of the projection scale for dequantization (e.g., int8 -> float with scale = 1.0/127).

◆ erf() [1/2]

template<Matrix M>
auto mtl::erf ( const M & m)

Element-wise erf for matrices.

◆ erf() [2/2]

template<Vector V>
auto mtl::erf ( const V & v)

Element-wise erf for vectors.

◆ erfc() [1/2]

template<Matrix M>
auto mtl::erfc ( const M & m)

Element-wise erfc for matrices.

◆ erfc() [2/2]

template<Vector V>
auto mtl::erfc ( const V & v)

Element-wise erfc for vectors.

◆ evaluate() [1/3]

template<typename Expr>
requires (Vector<Expr> && !Matrix<Expr> && traits::is_expression_v<Expr>)
auto mtl::evaluate ( const Expr & expr)

Materialize a vector expression into a concrete dense_vector.

◆ evaluate() [2/3]

template<typename Expr>
requires (Matrix<Expr> && traits::is_expression_v<Expr>)
auto mtl::evaluate ( const Expr & expr)

Materialize a matrix expression into a concrete dense2D.

◆ evaluate() [3/3]

template<typename T>
requires (!traits::is_expression_v<T>)
const T & mtl::evaluate ( const T & x)

Pass-through for concrete types (no-op).

◆ exp() [1/2]

template<Matrix M>
auto mtl::exp ( const M & m)

Element-wise exp for matrices.

◆ exp() [2/2]

template<Vector V>
auto mtl::exp ( const V & v)

Element-wise exp for vectors.

◆ exp2() [1/2]

template<Matrix M>
auto mtl::exp2 ( const M & m)

Element-wise exp2 for matrices.

◆ exp2() [2/2]

template<Vector V>
auto mtl::exp2 ( const V & v)

Element-wise exp2 for vectors.

◆ expm()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::expm ( const M & A_in)

The matrix exponential exp(A) of a square matrix A, as a dense2D.

Scaling and squaring with Pade approximants (Higham 2005), with the scaling chosen from ||A^k||^(1/k) rather than ||A|| (Al-Mohy & Higham 2009), and the degree selected for the element type's unit roundoff. See the top of this file for the algorithm and its precision handling.

Accumulator (leading, default void) is forwarded to every matrix product and to the LU factorization and solves; void keeps their BLAS/LAPACK dispatch.

Throws std::invalid_argument if A is not square, and std::runtime_error if the Pade denominator is singular (not expected for a finite A). A matrix with a NaN or infinite entry gives a matrix of NaN.

◆ expm_cond()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::expm_cond ( const M & A)

An estimate of the relative condition number of exp at A in the 1-norm, ||L_exp(A)|| ||A|| / ||exp(A)|| (Higham 2008, Sec.

3.4, with normest1).

◆ expm_frechet()

template<typename Accumulator = void, FieldMatrix MA, FieldMatrix ME>
auto mtl::expm_frechet ( const MA & A,
const ME & E )

exp(A) and the Frechet derivative L_exp(A, E), by expm on [A E; 0 A].

◆ expm_multiply() [1/2]

template<Matrix MA, typename V>
mat::dense2D< V > mtl::expm_multiply ( const MA & A,
const mat::dense2D< V > & B,
const V & t = V(1) )

e^{tA} B for a square A (dense or compressed2D) and a dense n x n0 block B, without forming e^{tA}.

Al-Mohy & Higham (2011), Algorithm 3.2; see the top of this file. Throws std::invalid_argument on mismatched sizes or a NaN or infinite entry in A, and std::overflow_error when ||t A||_1 would need more than 2^50 steps.

◆ expm_multiply() [2/2]

template<Matrix MA, typename V>
vec::dense_vector< V > mtl::expm_multiply ( const MA & A,
const vec::dense_vector< V > & b,
const V & t = V(1) )

e^{tA} b for a vector b.

◆ fill()

template<MutableCollection C>
void mtl::fill ( C & c,
const typename C::value_type & val )

Fill all elements of a collection with the given value.

◆ fill_random() [1/6]

template<Matrix M>
void mtl::fill_random ( M & A,
typename M::value_type lo,
typename M::value_type hi,
std::mt19937_64 & gen )

Fill a matrix with uniform random values in [lo, hi), drawn from gen row by row.

◆ fill_random() [2/6]

template<Matrix M>
void mtl::fill_random ( M & A,
typename M::value_type lo,
typename M::value_type hi,
std::uint64_t seed )

Fill a matrix with uniform random values in [lo, hi), reproducibly from seed.

◆ fill_random() [3/6]

template<Matrix M>
void mtl::fill_random ( M & A,
typename M::value_type lo = typename M::value_type(0),
typename M::value_type hi = typename M::value_type(1) )

Fill a matrix with uniform random values in [lo, hi), non-deterministically.

◆ fill_random() [4/6]

template<Vector V>
void mtl::fill_random ( V & v,
typename V::value_type lo,
typename V::value_type hi,
std::mt19937_64 & gen )

Fill a vector with uniform random values in [lo, hi), drawn from gen.

◆ fill_random() [5/6]

template<Vector V>
void mtl::fill_random ( V & v,
typename V::value_type lo,
typename V::value_type hi,
std::uint64_t seed )

Fill a vector with uniform random values in [lo, hi), reproducibly from seed.

◆ fill_random() [6/6]

template<Vector V>
void mtl::fill_random ( V & v,
typename V::value_type lo = typename V::value_type(0),
typename V::value_type hi = typename V::value_type(1) )

Fill a vector with uniform random values in [lo, hi), non-deterministically.

◆ floor() [1/2]

template<Matrix M>
auto mtl::floor ( const M & m)

Element-wise floor for matrices.

◆ floor() [2/2]

template<Vector V>
auto mtl::floor ( const V & v)

Element-wise floor for vectors.

◆ frobenius_norm()

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)).

Mixed precision: pass an explicit Accumulator to sum the squares in a wider precision than the element magnitude. Default Accumulator = void is unchanged. Result is the delivery type and defaults to the element magnitude type; it also selects the round-out type ahead of the square root – see the note on two_norm (#379).

◆ fused_assign() [1/2]

template<typename Dest, Vector Expr>
requires (traits::is_expression_v<Expr> && !Matrix<Expr>)
void mtl::fused_assign ( Dest & dest,
const Expr & expr )

Evaluate a vector expression into a pre-allocated target: dest = expr.

The vector expressions are element-wise (a product with a matrix is evaluated eagerly, not an expression here), so element i reads only element i of every operand, dest included: in place is always safe.

◆ fused_assign() [2/2]

template<typename Dest, Matrix Expr>
requires traits::is_expression_v<Expr>
void mtl::fused_assign ( Dest & dest,
const Expr & expr )

Evaluate a matrix expression into a pre-allocated target: dest = expr.

In place, unless the expression reads dest anywhere but at the element being written – A = trans(A), A = A * B – or dest's storage can't be seen: then through a temporary. Without the test, fused_assign(A, 1.0 * trans(A)) on [[1,2],[3,4]] gave [[1,3],[3,4]], and change_dim ran before expr was read, so a reallocation could leave expr dangling (issue 887).

◆ fused_plus_assign() [1/2]

template<typename Dest, Vector Expr>
requires (traits::is_expression_v<Expr> && !Matrix<Expr>)
void mtl::fused_plus_assign ( Dest & dest,
const Expr & expr )

Evaluate a vector expression and add to target: dest += expr.

◆ fused_plus_assign() [2/2]

template<typename Dest, Matrix Expr>
requires traits::is_expression_v<Expr>
void mtl::fused_plus_assign ( Dest & dest,
const Expr & expr )

Evaluate a matrix expression and add to target: dest += expr In place unless expr reads dest elsewhere (see fused_assign): then the sum is formed from a temporary of expr.

fused_plus_assign(C, trans(C) * 1.0) on [[1,2],[3,4]] gave [[2,5],[8,8]] (issue 887).

◆ gemmt()

template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB, Matrix MC>
void mtl::gemmt ( const S & alpha_in,
const MA & A,
const MB & B,
const S & beta_in,
MC & C,
uplo t = uplo::lower,
gemmt_fill fill = gemmt_fill::mirror )

Triangular-output product: the t triangle of C = alpha*A*B + beta*C.

C is n x n, A is n x k, B is k x n. The other triangle is mirrored from the formed one (fill = mirror, the default) or left untouched (keep). B may be a dense matrix, trans() of one, or trans() of a compressed2D. alpha and beta are converted to C's element type first, as ?gemmt takes them, so every path combines with the same coefficients. With beta != 0 and fill = mirror, C must be symmetric: only the formed triangle of the old C is read.

◆ ger()

template<typename Accumulator = void, Scalar S, Vector VX, Vector VY, Matrix M>
void mtl::ger ( const S & alpha,
const VX & x,
const VY & y,
M & A )

Rank-1 update: A(i,j) += alpha * x(i) * y(j).

Mixed precision: pass an explicit Accumulator to fold the existing A(i,j), and the product alpha*x(i)*y(j), into one rounding event (#261, Part C) instead of two (product round, then add round). Default Accumulator = void keeps the BLAS / generic dispatch byte for byte.

Gated on interface::accumulator_allows_blas_v, same as symv/gemv: a custom accumulator cannot be honored by external BLAS.

Unlike symv's per-row reduction, each entry here is a single term, so the accumulator is seeded with assign(A(i,j)) – not clear – then given one add_product, matching axpy's one-term seeded pattern (#511) rather than gemv/symv's zero-seeded multi-term row loop.

◆ has_inf()

template<Vector V>
bool mtl::has_inf ( const V & v)

At least one entry is +/-Inf.

◆ has_nan()

template<Vector V>
bool mtl::has_nan ( const V & v)

At least one entry is NaN.

◆ hermitian() [1/2]

template<typename Matrix>
void mtl::hermitian ( const Matrix && )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ hermitian() [2/2]

template<typename Matrix>
auto mtl::hermitian ( const Matrix & A)

Create a hermitian view of matrix A (upper triangle stored).

◆ hessenberg()

template<typename Accumulator = void, Matrix M>
auto mtl::hessenberg ( const M & A)

Reduce A to upper Hessenberg form and return H directly.

◆ hessenberg_extract_H()

template<Matrix M>
auto mtl::hessenberg_extract_H ( const M & A)

Extract explicit upper Hessenberg matrix from factored A.

◆ hessenberg_extract_Q()

template<typename Accumulator = void, Matrix M>
auto mtl::hessenberg_extract_Q ( const M & A,
const vec::dense_vector< typename M::value_type > & tau )

Form the unitary Q of A = Q H Q^H from the reflectors hessenberg_factor() left in the strict lower triangle of A and in tau (LAPACK orghr).

hessenberg_factor computes H = P A P^H with P = H_{k-1} ... H_0, so Q = P^H = H_0^H ... H_{k-1}^H, accumulated here from the right end. Accumulator (leading, default void) is forwarded to apply_householder_left().

◆ hessenberg_factor()

template<typename Accumulator = void, Matrix M>
void mtl::hessenberg_factor ( M & A,
vec::dense_vector< typename M::value_type > & tau )

Reduce A to upper Hessenberg form in-place.

On output, A contains H (upper Hessenberg) and the Householder vectors are stored in the strict lower triangle below the subdiagonal. tau stores the Householder scalars. Accumulator (leading, default void) is forwarded to householder() and apply_householder_left/right() (#536).

◆ householder() [1/2]

template<typename Accumulator = void, typename T>
std::pair< vec::dense_vector< T >, T > mtl::householder ( const vec::dense_vector< T > & x)

Compute Householder vector v and scalar tau for a column vector x, such that H = I - tau*v*v^H satisfies H*x = beta*e_1.

v(0) is always 1 (implicit). Returns {v, tau}. For complex x, beta is real by construction; householder_reflector() returns it as well.

◆ householder() [2/2]

template<typename T>
textbook_reflection< T > mtl::householder ( const vec::dense_vector< T > & x,
tag::textbook_reflector  )

Textbook (Golub & Van Loan sec.

5.1) Householder reflector for x, real T only. Unlike the default, x is not scaled, v(0) is not normalized to 1, and alpha takes the opposite sign of x(0), so R's diagonal is -sign(x0)*||x||:

norm = sqrt(sum x_i^2) from zero, ascending i alpha = x_0 >= 0 ? -norm : norm v = x; v_0 = x_0 - alpha vtv = sum v_i^2 from zero, ascending i

When !(norm > 0) – x is zero, or contains NaN – the column is to be skipped: vtv is returned as 0 and v = x. apply_householder_left skips on !(vtv > 0) as well, which also covers a vtv that underflows.

Squares are formed unscaled, as a hand-written loop forms them: entries beyond ~1e154 (double) overflow and entries below ~1e-154 underflow, where the default's scaling would not. That is the price of reproducing the loop.

◆ householder_reflector()

template<typename Accumulator = void, typename T>
normalized_reflection< T > mtl::householder_reflector ( const vec::dense_vector< T > & x)

Compute Householder vector v and scalar tau for a column vector x, such that H = I - tau*v*v^H satisfies H*x = beta*e_1, and return beta with them.

v(0) is always 1 (implicit). For complex x, beta is real by construction. When tau == 0, H = I and beta is x(0).

beta is what a factorization stores as its pivot (R(j,j) in QR, L(i,i) in LQ, the subdiagonal in a Hessenberg or tridiagonal reduction), as LAPACK's xGEQR2, xGELQ2, xGEHD2 and xSYTD2 store dlarfg's beta. Recomputing the pivot by applying H to x instead rounds again, and in a type with absolute resolution (fixed point) the products v(i)*x(i) of a column near that resolution round to zero, so the recomputed pivot is 0 although beta is not (#678).

◆ imag() [1/2]

template<Matrix M>
auto mtl::imag ( const M & m)

Element-wise imag for matrices -> dense2D<magnitude_t<T>>.

◆ imag() [2/2]

template<Vector V>
auto mtl::imag ( const V & v)

Element-wise imag for vectors -> dense_vector<magnitude_t<T>>.

◆ inertia()

template<Matrix M>
inertia_t mtl::inertia ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(-1) )

◆ infinity_norm() [1/2]

template<Matrix M>
auto mtl::infinity_norm ( const M & m)

infinity_norm(m) = max row sum of |m[i,j]|

On column-major storage the row sums accumulate in a buffer (in the column order the row loop used, so the bits stay); a compressed2D sums each row's stored entries (issue 886).

◆ infinity_norm() [2/2]

template<Vector V>
auto mtl::infinity_norm ( const V & v)

infinity_norm(v) = max(|v[i]|)

◆ inv()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::inv ( const M & A)

Compute the inverse of a square matrix A via LU factorization.

Returns inv(A) as a dense2D. Throws std::runtime_error if A is singular (a zero or NaN pivot) and std::invalid_argument if it is not square. A 0x0 A gives a 0x0 inverse. Accumulator (#585) is forwarded to lu_factor and to every lu_solve.

◆ is_banded()

template<Matrix M>
bool mtl::is_banded ( const M & A,
std::size_t kl,
std::size_t ku,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

Banded with lower bandwidth kl and upper bandwidth ku: an entry more than kl below (i - j > kl) or more than ku above (j - i > ku) the diagonal must be ~0.

◆ is_diagonal()

template<Matrix M>
bool mtl::is_diagonal ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

Diagonal: every off-diagonal entry is ~0.

◆ is_diagonally_dominant()

template<Matrix M>
bool mtl::is_diagonally_dominant ( const M & A,
bool strict = false )

Row diagonally dominant: |A(i,i)| >= sum_{j != i} |A(i,j)| for every row (strict: strictly greater).

Non-square matrices are never dominant.

◆ is_empty()

template<Matrix M>
bool mtl::is_empty ( const M & A)

A has no rows or no columns.

◆ is_finite()

template<Vector V>
bool mtl::is_finite ( const V & v)

Every entry is finite (no NaN, no +/-Inf).

◆ is_hermitian()

template<Matrix M>
bool mtl::is_hermitian ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

A == A^H (within tol): A(i,j) == conj(A(j,i)), and the diagonal is real.

For real element types this coincides with is_symmetric.

◆ is_indefinite()

template<Matrix M>
bool mtl::is_indefinite ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(-1) )

Indefinite: a symmetric matrix with both positive and negative eigenvalues.

◆ is_invertible()

template<Matrix M>
bool mtl::is_invertible ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

Alias for is_nonsingular.

◆ is_lower_triangular()

template<Matrix M>
bool mtl::is_lower_triangular ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

Lower triangular: everything strictly above the main diagonal is ~0.

◆ is_nonsingular()

template<Matrix M>
bool mtl::is_nonsingular ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

Complement of is_singular.

◆ is_normal()

template<Matrix M>
bool mtl::is_normal ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(-1) )

Normal: A is square and A A^H == A^H A (within tol) – the class of matrices unitarily diagonalizable, containing the symmetric/Hermitian, skew, and unitary matrices.

Default tol as for is_unitary. Non-square is never normal.

◆ is_normalized()

template<Vector V>
bool mtl::is_normalized ( const V & v,
magnitude_t< typename V::value_type > tol = default_norm_tol<magnitude_t<typename V::value_type>>() )

Unit 2-norm within a relative tolerance (default 128 * eps).

◆ is_orthogonal()

template<Matrix M>
bool mtl::is_orthogonal ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(-1) )

Orthogonal: alias for is_unitary (conventional name for real matrices).

◆ is_orthogonal_to()

template<Vector V1, Vector V2>
bool mtl::is_orthogonal_to ( const V1 & u,
const V2 & v,
magnitude_t< typename V1::value_type > tol = default_norm_tol<magnitude_t<typename V1::value_type>>() )

Numerically orthogonal: |<u,v>| <= tol * ||u|| * ||v|| (relative; default tol 128 * eps).

Zero-length vectors are trivially orthogonal.

◆ is_positive_definite()

template<Matrix M>
bool mtl::is_positive_definite ( const M & A,
magnitude_t< typename M::value_type > sym_tol = magnitude_t<typename M::value_type>(0) )

Alias for is_spd.

◆ is_singular()

template<Matrix M>
bool mtl::is_singular ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

Singular within tol: the LU factorization has a zero pivot, or the smallest |U(k,k)| is <= tol (default 0, i.e.

an exact zero pivot). Requires a square matrix. Runs LU on a copy; O(n^3).

◆ is_spd()

template<Matrix M>
bool mtl::is_spd ( const M & A,
magnitude_t< typename M::value_type > sym_tol = magnitude_t<typename M::value_type>(0) )

Symmetric positive definite: A is symmetric (within sym_tol, default exact) and its Cholesky factorization exists (every pivot strictly positive).

Non-square matrices are never SPD. Runs Cholesky on a copy; O(n^3).

◆ is_square()

template<Matrix M>
bool mtl::is_square ( const M & A)

A.num_rows() == A.num_cols().

◆ is_symmetric()

template<Matrix M>
bool mtl::is_symmetric ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

A == A^T (within tol). Non-square matrices are never symmetric.

◆ is_triangular()

template<Matrix M>
bool mtl::is_triangular ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

Upper or lower triangular.

◆ is_unit()

template<Vector V>
bool mtl::is_unit ( const V & v,
magnitude_t< typename V::value_type > tol = default_norm_tol<magnitude_t<typename V::value_type>>() )

Alias for is_normalized.

◆ is_unitary()

template<Matrix M>
bool mtl::is_unitary ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(-1) )

Unitary: A is square and A^H A == I (within tol).

For a real element type A^H = A^T, i.e. this is the orthogonality test. The default tol is a scale-aware relative threshold (~128 * n * eps * max|A|^2); pass tol >= 0 for an explicit absolute threshold. Non-square matrices are never unitary.

◆ is_upper_triangular()

template<Matrix M>
bool mtl::is_upper_triangular ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(0) )

Upper triangular: everything strictly below the main diagonal is ~0.

◆ is_zero()

template<Vector V>
bool mtl::is_zero ( const V & v,
magnitude_t< typename V::value_type > tol = magnitude_t<typename V::value_type>(0) )

Every entry is within tol of zero (default tol 0: exactly zero).

Written as !(abs <= tol) so a NaN entry fails the predicate rather than being accepted.

◆ kron()

template<Matrix MA, Matrix MB>
auto mtl::kron ( const MA & A,
const MB & B )

Kronecker product: C = A (x) B, where C(i*rb+p, j*cb+q) = A(i,j)*B(p,q).

C's value type is std::common_type_t of A's and B's value types, so a mixed-type product is not narrowed to A's type; for two operands of the same type it is that type.

◆ ldlt_bk_factor()

template<typename Accumulator = void, FieldMatrix M>
int mtl::ldlt_bk_factor ( M & A,
bk_pivot_info & pivots )

Bunch-Kaufman pivoted LDL^T factorization: P*A*P^T = L*D*L^T.

In-place: lower triangle of A is overwritten with L (unit diagonal implicit), D occupies the diagonal and first subdiagonal for 2x2 blocks. Returns 0 on success, k+1 if a singular block is encountered at step k. A non-void Accumulator runs the left-looking form (top of file).

◆ ldlt_bk_solve()

template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void mtl::ldlt_bk_solve ( const M & A,
const bk_pivot_info & pivots,
VecX & x,
const VecB & b )

Solve A*x = b using precomputed Bunch-Kaufman LDL^T factors.

The factored A contains L (unit lower, implicit diagonal) and D (diagonal and subdiagonal for 2x2 blocks). pivots records the permutation and block structure. A non-void Accumulator substitutes by rows, forming each b(i) - sum in one reduction (top of file).

◆ ldlt_factor()

template<typename Accumulator = void, FieldMatrix M>
int mtl::ldlt_factor ( M & A)

LDL^T factorization: A = L * D * L^T.

The strictly lower triangle of A is overwritten with L (unit diagonal implicit). The diagonal of A is overwritten with D. Returns 0 on success, k+1 if D(k,k) == 0 (zero pivot). A non-void Accumulator forms each entry as one reduction (top of file).

◆ ldlt_h_factor()

template<typename Accumulator = void, FieldMatrix M>
int mtl::ldlt_h_factor ( M & A)

LDL^H factorization: A = L * D * L^H, for a HERMITIAN matrix.

The strictly lower triangle of A is overwritten with L (unit diagonal implicit); the diagonal is overwritten with D, which is REAL for a Hermitian A and is stored in the element type with a zero imaginary part.

Only the lower triangle of A is read, so the caller's upper triangle is irrelevant and need not be populated consistently.

Returns 0 on success, k+1 if D(k) is zero (zero pivot), or LDLT_NOT_HERMITIAN if the diagonal is not real (see below) – a Hermitian matrix cannot have one, so that input belongs to ldlt_factor.

For real element types conjugation is the identity and this is exactly ldlt_factor. For complex elements it is the factorization a Hermitian matrix actually has – see the note at the top of this file (#352). A non-void Accumulator forms each entry as one reduction (top of file).

◆ ldlt_h_solve()

template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void mtl::ldlt_h_solve ( const M & A,
VecX & x,
const VecB & b )

Solve A*x = b using precomputed LDL^H factors stored in A.

Three phases: L*y = b (forward), D*z = y (diagonal), L^H*x = z (backward). Accumulator forms each row's sum of products.

◆ ldlt_solve()

template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void mtl::ldlt_solve ( const M & A,
VecX & x,
const VecB & b )

Solve A*x = b using precomputed LDL^T factors stored in A.

Lower triangle of A contains L (unit diagonal implicit), diagonal contains D. The factor must come from ldlt_factor, which is right for a real symmetric and a complex SYMMETRIC (A == A^T) matrix (#352). A factor from ldlt_h_factor, of a Hermitian matrix, needs ldlt_h_solve: this applies L^T, not L^H, and nothing in the stored factor tells the two apart (#854). Three phases: L*y = b (forward), D*z = y (diagonal), L^T*x = z (backward). Accumulator forms each row's sum of products.

◆ log() [1/2]

template<Matrix M>
auto mtl::log ( const M & m)

Element-wise log for matrices.

◆ log() [2/2]

template<Vector V>
auto mtl::log ( const V & v)

Element-wise log for vectors.

◆ log10() [1/2]

template<Matrix M>
auto mtl::log10 ( const M & m)

Element-wise log10 for matrices.

◆ log10() [2/2]

template<Vector V>
auto mtl::log10 ( const V & v)

Element-wise log10 for vectors.

◆ log2() [1/2]

template<Matrix M>
auto mtl::log2 ( const M & m)

Element-wise log2 for matrices.

◆ log2() [2/2]

template<Vector V>
auto mtl::log2 ( const V & v)

Element-wise log2 for vectors.

◆ logm()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::logm ( const M & A)

The principal logarithm of a square matrix: the X with exp(X) = A whose eigenvalues have imaginary parts in (-pi, pi), as a dense2D of A's element type.

A real A gives a real X, also when A has complex eigenvalues.

Throws std::invalid_argument if A is not square or has a NaN or infinite entry, std::domain_error if A has an eigenvalue on the closed negative real axis (then no principal logarithm exists, for a real and a complex A alike), std::overflow_error if the logarithm is too large to represent, and std::runtime_error if the Schur decomposition does not converge.

Accumulator (leading, default void) is forwarded to schur(), to the products of the norm estimates, and to the two products of Q L Q^H.

◆ logm_cond()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::logm_cond ( const M & A)

An estimate of the relative condition number of log at A in the 1-norm.

Throws as logm() does.

◆ logm_frechet()

template<typename Accumulator = void, FieldMatrix MA, FieldMatrix ME>
auto mtl::logm_frechet ( const MA & A,
const ME & E )

log(A) and the Frechet derivative L_log(A, E), by logm on [A E; 0 A].

Throws as logm() does.

◆ lower() [1/2]

template<typename Matrix>
void mtl::lower ( const Matrix && )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ lower() [2/2]

template<typename Matrix>
auto mtl::lower ( const Matrix & A)

Create a lower triangular view (includes diagonal).

◆ lower_trisolve() [1/2]

template<typename Accumulator = void, Matrix M, Vector VecX>
void mtl::lower_trisolve ( const M & L,
VecX & x,
bool unit_diag = false )

In-place variant: solve L*x = x (b is x on input).

◆ lower_trisolve() [2/2]

template<typename Accumulator = void, Matrix M, Vector VecX, Vector VecB>
void mtl::lower_trisolve ( const M & L,
VecX & x,
const VecB & b,
bool unit_diag = false )

Solve L*x = b by forward substitution where L is lower triangular.

x is overwritten with the solution. If unit_diag is true, the diagonal of L is assumed to be 1.

◆ lq_extract_L()

template<Matrix M>
auto mtl::lq_extract_L ( const M & A)

Extract explicit L (m x n) from LQ factorization stored in A.

◆ lq_extract_Q()

template<typename Accumulator = void, Matrix M>
auto mtl::lq_extract_Q ( const M & A,
const vec::dense_vector< typename M::value_type > & tau )

Extract explicit Q (n x n) from LQ factorization stored in A and tau.

Accumulator is forwarded to each apply_householder_left (#536).

◆ lq_factor() [1/2]

template<typename Accumulator = void, FieldMatrix M>
int mtl::lq_factor ( M & A,
vec::dense_vector< typename M::value_type > & tau )

LQ factorization: A (m x n, n >= m) is overwritten with L on+below diagonal and Householder vectors above diagonal.

tau(k) stores beta for row k. Returns 0 on success. Accumulator (leading, default void) is forwarded to householder() and apply_householder_right() (#536); void is today's arithmetic.

◆ lq_factor() [2/2]

template<FieldMatrix M>
int mtl::lq_factor ( M & A,
vec::dense_vector< typename M::value_type > & tau,
tag::textbook_reflector  )

LQ factorization with the textbook Householder reflector (#559): the row mirror of qr_factor(A, tau, tag::textbook_reflector{}).

Real element types only. For each row k (k < min(m, n)):

auto [v, vtv, alpha] = householder(A(k, k:n-1), tag::textbook_reflector{}); if !(vtv > 0): skip the row (tau(k) = 0, row k untouched) apply_householder_right(A, v, vtv, k+1, k, tag::textbook_reflector{}); L(k,k) = alpha

so L on and below the diagonal is bit-identical to a hand-written textbook LQ, including L's diagonal sign, -sign(x_k)*||x||. Above the diagonal and in tau the same reflector is stored in MTL5's packed form, v/v(0) with tau(k) = 2*v(0)^2/vtv, so lq_extract_Q works on the result unchanged; its Q agrees with the textbook Q to rounding, not to the bit. Returns 0.

◆ lq_normalize_signs()

template<Matrix ML, Matrix MQ>
void mtl::lq_normalize_signs ( ML & L,
MQ & Q )

Make L's diagonal non-negative: for each k < min(m, n) with L(k,k) < 0, negate column k of L and row k of Q.

L*Q is unchanged. The LQ counterpart of qr_normalize_signs, for the same reason: lq_factor takes LAPACK's sign from 5.22.0 on (#672), so L(k,k) < 0 wherever the pivot entry was positive.

◆ lu_adjoint_solve()

template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void mtl::lu_adjoint_solve ( const M & LU,
const std::vector< typename M::size_type > & pivot,
VecX & x,
const VecB & b )

Solve A^H * x = b using the precomputed LU factorization of A.

lu_factor produces P*A = L*U, so A = P^-1*L*U and

A^H = U^H * L^H * P^-H = U^H * L^H * P

because P is a real permutation, hence P^-H = P. The solve is therefore the mirror image of lu_solve: the triangular factors are applied conjugated, in the opposite order, and the permutation moves to the END and is inverted.

The permutation in lu_solve is a forward sequence of row interchanges, so its inverse is the same interchanges applied in reverse order.

Needed by bicg and qmr, the only solvers that ask a preconditioner for M^-H (#394).

Accumulator forms both substitutions' sums, as in lu_solve.

◆ lu_apply()

template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
int mtl::lu_apply ( M & A,
VecX & x,
const VecB & b )

Convenience: factor and solve A*x = b in one call.

A is modified in place. Returns 0 on success.

◆ lu_factor()

template<typename Accumulator = void, FieldMatrix M>
int mtl::lu_factor ( M & A,
std::vector< typename M::size_type > & pivot )

LU factorization with partial pivoting.

A is overwritten: L (unit lower, stored below diagonal) + U (stored on+above diagonal). pivot[k] = row index swapped with row k at step k. Returns 0 on success, k+1 if U(k,k) is zero (singular).

A non-void Accumulator forms each entry of L and U as one reduction (left-looking, see the top of this file) and never dispatches to LAPACK.

◆ lu_iterative_refine()

template<typename Working, typename Residual, typename PA, typename PV>
lu_refine_result mtl::lu_iterative_refine ( const mat::dense2D< Residual, PA > & A,
const vec::dense_vector< Residual, PV > & b,
vec::dense_vector< Residual, PV > & x,
const lu_refine_options & opt = {} )

Solve A x = b by LU iterative refinement.

Working – precision of the LU factorization and correction solves (explicit template argument, typically lower than Residual). Residual – precision of A, b, x and the residual (deduced from A). A and b are supplied in Residual precision; the refined x is returned in Residual precision (any prior contents are overwritten by the initial solve).

Returns the BEST iterate found. Throws std::invalid_argument for a non-square A or a b of the wrong size, and std::runtime_error when the Working-precision copy of A is singular (or overflows to a NaN pivot).

◆ lu_solve()

template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void mtl::lu_solve ( const M & LU,
const std::vector< typename M::size_type > & pivot,
VecX & x,
const VecB & b )

Solve A*x = b using precomputed LU factorization.

LU contains both L (below diagonal, unit) and U (on+above diagonal). Applies pivot permutation, then forward/back substitution. A non-void Accumulator forms each row's b(i) - sum in one reduction.

◆ lu_solve_dispatch()

template<Matrix M, Vector VecX, Vector VecB>
void mtl::lu_solve_dispatch ( const M & A,
VecX & x,
const VecB & b )

LU-based solve with automatic dispatch.

For sparse double (dense_vector<double> x, b) with UMFPACK: uses UMFPACK. For sparse (any type): uses native sparse LU. For dense: uses in-place dense LU with partial pivoting.

◆ mapped() [1/2]

template<typename Matrix>
void mtl::mapped ( const Matrix && ,
const std::vector< typename Matrix::size_type > & ,
const std::vector< typename Matrix::size_type > &  )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ mapped() [2/2]

template<typename Matrix>
auto mtl::mapped ( const Matrix & A,
const std::vector< typename Matrix::size_type > & row_map,
const std::vector< typename Matrix::size_type > & col_map )

Create a map view with row and column remapping.

◆ max()

template<Collection C>
auto mtl::max ( const C & c)

Returns the maximum element value.

A NaN element makes the result NaN, wherever it is: a plain > comparison skips a NaN, so the result depended on its position, as infinity_norm's did before #690. An empty collection throws std::invalid_argument; it has no maximum.

Seeded from the first element (issue 887): the seed was numeric_limits<T>::lowest(), so max({-inf}) returned the finite -1.79769e+308, an empty collection returned that sentinel, and a type without a numeric_limits specialization got a default value.

◆ min()

template<Collection C>
auto mtl::min ( const C & c)

Returns the minimum element value.

A NaN element makes the result NaN, wherever it is: a plain < comparison skips a NaN, so the result depended on its position, as infinity_norm's did before #690. An empty collection throws std::invalid_argument; it has no minimum.

Seeded from the first element (issue 887): the seed was numeric_limits<T>::max(), so min({+inf}) returned the finite +1.79769e+308, an empty collection returned that sentinel, and a type without a numeric_limits specialization got a default value.

◆ mult() [1/5]

template<typename Accumulator = void, Matrix M, Vector VIn, Vector VOut>
void mtl::mult ( const M & A,
const VIn & x,
VOut & y )

y = A x.

Every kernel writes y while it still reads x and A (the column-major gemv zeroes y first), so a y that shares storage with either – the same vector, a vector over part of the same buffer, over a compressed matrix's values, or over the matrix behind a view – is computed through a temporary, in every build (#840). It was a debug-only assert, and it saw only the same object.

◆ mult() [2/5]

template<typename Accumulator = void, Matrix MA, Matrix MB, Matrix MC>
void mtl::mult ( const MA & A,
const MB & B,
MC & C )

mat*mat multiply into pre-allocated C: C = A * B.

Mixed precision: pass an explicit Accumulator to sum each C element in a precision distinct from the operand element type (e.g. mult<float>(A, B, C) with bfloat16 A/B accumulates in fp32); the accumulator is rounded out to C's element type on store, so C's type selects the output precision. The default Accumulator = void keeps the BLAS / native-fast / generic dispatch unchanged. The mixed path is the generic kernel (scalar; SIMD is #165).

◆ mult() [3/5]

template<typename Accumulator = void, BlockScheme S, Vector VIn, Vector VOut>
void mtl::mult ( const mat::block_matrix_view< S > & A,
const VIn & x,
VOut & y )

y = A x for a block matrix, into a pre-allocated y.

As the overload above, with any scratch the fused kernel needs allocated for this call.

◆ mult() [4/5]

template<typename Accumulator = void, BlockScheme S, Vector VIn, Vector VOut>
void mtl::mult ( const mat::block_matrix_view< S > & A,
const VIn & x,
VOut & y,
std::span< std::byte > scratch )

y = A x for a block matrix, into a pre-allocated y, with the fused kernel's scratch supplied by the caller.

With the default Accumulator, float contiguous x and y, and a scheme that specializes block_kernels, the scheme's fused kernel runs on scratch, which must hold block_gemv_scratch_bytes(A.num_cols()) bytes aligned to block_gemv_scratch_alignment; otherwise this throws std::invalid_argument. On every other path scratch is unused: each row is decoded once and dotted with x, with an explicit Accumulator if one is given. Rows are partitioned across the thread pool like the generic dense mat-vec. Each y(r) is computed from row r alone, so the result does not depend on the thread count.

◆ mult() [5/5]

template<typename Accumulator = void, typename V, typename P, Vector VIn, Vector VOut>
void mtl::mult ( const mat::view::transposed_view< mat::compressed2D< V, P > > & At,
const VIn & x,
VOut & y )

y = A^T x for a transposed compressed2D.

A y that shares storage with x or with the matrix's values is computed through a temporary, in every build (#840).

◆ mult_quad()

template<typename Accumulator, Matrix MA, Matrix MB, Matrix MC>
void mtl::mult_quad ( const MA & A,
const MB & B,
MC & C )

C = A * B through the QUAD MULTIPLY-ACCUMULATE micro-kernel – VNNI vpdpbusd on x86, SDOT/UDOT on NEON (#451 phase 5).

WHY THIS IS A SEPARATE ENTRY POINT and not a silent upgrade inside mult. Both kernels are correct for an (i8, i8) pair, so making mult choose between them would mean the same call measures a different thing on different machines – and the benchmark README already warns that nothing in a timing distinguishes vpdpbusd from its decomposition. The whole reason to build this kernel was to find out what the instruction is worth, and that needs both arms compilable in ONE binary so they can be compared within a machine. The programme has paid for a missing within-machine control once already: the instruction's share looked like 1.42x from a single Zen 4 run and came out at ~1.2x once an i7 could run both arms decomposed. So mult is unchanged, this is explicit, and the default flips later with data behind it.

The operand pair must be one the hardware op accepts – (i8,i8), (u8,i8) or (u8,u8), accumulating in the matching 32-bit type. (i8,u8) is rejected rather than reordered: unlike a dot product a GEMM is NOT symmetric in its operands, so there is no argument swap that fixes it for the caller, and (u8,i8) – unsigned activations against signed weights – is the shape quantized inference actually produces.

Falls back to the accumulator-aware generic loop when the matrices are not dense and contiguous, so this is always correct, never merely fast. One case is worth naming: COLUMN-MAJOR C is computed as C^T = B^T A^T, which swaps the operand order, and (u8,i8) swapped is (i8,u8) – not a pairing the instruction has. That combination therefore takes the generic loop. The symmetric pairs are unaffected.

◆ negate() [1/2]

template<Matrix M>
auto mtl::negate ( const M & m)

Element-wise negation for matrices: -m[r][c].

◆ negate() [2/2]

template<Vector V>
auto mtl::negate ( const V & v)

Element-wise negation for vectors: -v[i].

◆ normest1() [1/2]

template<FieldMatrix M>
auto mtl::normest1 ( const M & A,
std::size_t t = 2,
int itmax = 5 )

An estimate (a lower bound) of ||A||_1 for a square matrix, from products with A and A^H; see the operator overload.

For a dense A whose 1-norm is cheap to form exactly, form it: this is for operators.

◆ normest1() [2/2]

template<typename T, typename Apply, typename ApplyAdjoint>
detail::normest1_impl::real_of< T >::type mtl::normest1 ( std::size_t n,
Apply && apply,
ApplyAdjoint && apply_adjoint,
std::size_t t = 2,
int itmax = 5 )

An estimate (a lower bound) of ||A||_1 for the n x n operator A, from apply(X) = A X and apply_adjoint(Y) = A^H Y on n x t blocks (dense2D<T>).

t is the block width (default 2, as MATLAB), itmax the iteration limit. When a product A X has an entry that is not finite, the norm is beyond the representable range, and the result is infinity (the largest finite value for a type without one).

◆ normwise_backward_error()

template<typename T, typename PA, typename PV>
double mtl::normwise_backward_error ( const mat::dense2D< T, PA > & A,
const vec::dense_vector< T, PV > & x,
const vec::dense_vector< T, PV > & b )

Normwise backward error eta(x) = ||b - A x||_inf / (||A||_inf ||x||_inf + ||b||_inf).

A must be square and match the length of x and b.

◆ null_vector()

template<typename Accumulator = void, FieldMatrix M>
vec::dense_vector< typename M::value_type > mtl::null_vector ( const M & A,
typename M::value_type tol = std::numeric_limits<typename M::value_type>::epsilon() )

A unit vector x minimizing ||A x||: the right singular vector of A's smallest singular value, i.e.

the last column of V from the V-only svd (#566). For a wide A (m < n) the null space has dimension at least n - m and x is one vector in it. The sign is arbitrary. Returns an empty vector when A has no columns.

◆ nullity()

template<Matrix M>
std::size_t mtl::nullity ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(-1) )

Nullity: dimension of the null space = num_cols - numerical_rank.

◆ num_cols()

template<Matrix M>
auto mtl::num_cols ( const M & m)

Return the number of columns.

◆ num_rows()

template<Matrix M>
auto mtl::num_rows ( const M & m)

Return the number of rows.

◆ numerical_rank()

template<Matrix M>
std::size_t mtl::numerical_rank ( const M & A,
magnitude_t< typename M::value_type > tol = magnitude_t<typename M::value_type>(-1) )

Numerical rank: number of singular values above a threshold.

The default threshold is max(m,n) * eps * sigma_max (the standard rank-revealing cutoff); pass tol to set an explicit absolute threshold on the singular values.

◆ one_norm() [1/2]

template<Matrix M>
auto mtl::one_norm ( const M & m)

one_norm(m) = max column sum of |m[i,j]|

On row-major and sparse storage the column sums accumulate in a buffer, in the row order the column loop used, so the result keeps its bits; the column loop walked a row-major matrix against its layout (issue 886).

◆ one_norm() [2/2]

template<Vector V>
auto mtl::one_norm ( const V & v)

one_norm(v) = sum(|v[i]|)

◆ operator<<() [1/2]

template<Matrix M>
std::ostream & mtl::operator<< ( std::ostream & os,
const M & m )

Print a matrix in row-by-row format.

◆ operator<<() [2/2]

template<Vector V>
std::ostream & mtl::operator<< ( std::ostream & os,
const V & v )

Print a vector: [v0, v1, ..., vn].

◆ pow() [1/2]

template<Matrix M, Scalar S>
auto mtl::pow ( const M & m,
const S & exponent )

Element-wise pow for matrices: pow(m[r][c], exponent).

◆ pow() [2/2]

template<Vector V, Scalar S>
auto mtl::pow ( const V & v,
const S & exponent )

Element-wise pow for vectors: pow(v[i], exponent).

◆ print() [1/2]

template<Matrix M>
void mtl::print ( std::ostream & os,
const M & m,
int precision = 6 )

Print a matrix to a stream with configurable precision.

Parameters
osOutput stream to write to.
mThe matrix to print in row-by-row format.
precisionNumber of significant digits (default 6).
See also
print(std::ostream&, const V&, int) for design rationale.

◆ print() [2/2]

template<Vector V>
void mtl::print ( std::ostream & os,
const V & v,
int precision = 6 )

Print a vector to a stream with configurable precision.

MTL4 intentionally omitted operator<<() for vectors and matrices, providing only explicit print() functions. The reasons were:

  1. Inserter conflict – MTL uses operator<< for sparse element insertion (e.g., ins[r][c] << 3.14). A stream operator<< on the same types risks overload ambiguity or surprising ADL interactions.
  2. Expression template safety – std::cout << A * B would silently force evaluation of a lazy expression. An explicit print() call makes the cost visible.
  3. Format control – There is no single right way to format a matrix (dense vs sparse, dimensions, precision). A free function is easier to parameterize.
  4. Compile-time cost – Including <iostream> in a header-only math library adds overhead to every translation unit, even when no output is needed.

MTL5 provides both operator<< (for convenience) and print() (for precision control), but print() remains the recommended explicit API for production code.

Parameters
osOutput stream to write to.
vThe vector to print.
precisionNumber of significant digits (default 6).

◆ print_matlab()

template<Matrix M>
void mtl::print_matlab ( std::ostream & os,
const M & m,
const std::string & name = "A",
int precision = 6 )

Print matrix in MATLAB format: name = [v1 v2 ...; v3 v4 ...; ...].

◆ print_sparse()

template<typename Value, typename Parameters>
void mtl::print_sparse ( std::ostream & os,
const mat::compressed2D< Value, Parameters > & A,
int precision = 6 )

Print sparse matrix in triplet format: (row, col) = value.

◆ product()

template<Collection C>
auto mtl::product ( const C & c)

Returns the product of all elements: product(c[i]).

◆ project_onto() [1/4]

template<Scalar Target, Scalar Source>
requires ProjectableOnto<Target, Source>
mat::dense2D< Target > mtl::project_onto ( const mat::dense2D< Source > & src)

Project a dense 2D matrix onto a narrower element type; integer targets saturate (see the vector overload).

◆ project_onto() [2/4]

template<Scalar Target, Scalar Source, Scalar ScaleType>
requires ProjectableOnto<Target, Source>
mat::dense2D< Target > mtl::project_onto ( const mat::dense2D< Source > & src,
ScaleType scale )

Scaled projection of a dense 2D matrix with saturating conversion.

◆ project_onto() [3/4]

template<Scalar Target, Scalar Source>
requires ProjectableOnto<Target, Source>
vec::dense_vector< Target > mtl::project_onto ( const vec::dense_vector< Source > & src)

Project a dense vector onto a narrower element type.

An integer target saturates, NaN to 0, as the scaled overloads do: a bare static_cast of an out-of-range or NaN floating value is undefined behavior (issue 887).

◆ project_onto() [4/4]

template<Scalar Target, Scalar Source, Scalar ScaleType>
requires ProjectableOnto<Target, Source>
vec::dense_vector< Target > mtl::project_onto ( const vec::dense_vector< Source > & src,
ScaleType scale )

Scaled projection of a dense vector with saturating conversion.

dst(i) = saturating_cast<Target>(scale * src(i)) The scale factor maps the source dynamic range onto the target dynamic range, essential for quantization workflows (e.g., float -> int8 with scale = 127). Integer targets are clamped to [min, max] to prevent overflow UB.

◆ qr_extract_Q()

template<typename Accumulator = void, Matrix M>
auto mtl::qr_extract_Q ( const M & A,
const vec::dense_vector< typename M::value_type > & tau )

Extract explicit Q (m x m) from QR factorization stored in A and tau.

Q = H_0^H * H_1^H * ... * H_{k-1}^H where H_j = I - tau(j) * v_j * v_j^H. (For real element types conj is the identity and this is the familiar Q = H_0 * H_1 * ... * H_{k-1}.) Accumulator is forwarded to each apply_householder_left (#536).

◆ qr_extract_R()

template<Matrix M>
auto mtl::qr_extract_R ( const M & A)

Extract explicit R (m x n) from QR factorization stored in A.

◆ qr_factor() [1/2]

template<typename Accumulator = void, FieldMatrix M>
int mtl::qr_factor ( M & A,
vec::dense_vector< typename M::value_type > & tau )

QR factorization: A (m x n, m >= n) is overwritten with R on+above diagonal and Householder vectors below diagonal.

tau(k) stores beta for column k. Returns 0 on success.

Accumulator (leading, default void) selects how each reflector's sums are rounded: the sum of squares in householder() and the per-column v^H*A(:,j) in apply_householder_left() (#536). void is today's arithmetic, including the LAPACK geqrf dispatch; any other accumulator runs the generic loop, since geqrf's sums are its own.

◆ qr_factor() [2/2]

template<FieldMatrix M>
int mtl::qr_factor ( M & A,
vec::dense_vector< typename M::value_type > & tau,
tag::textbook_reflector  )

QR factorization with the textbook Householder reflector (#559).

Real element types only; never dispatches to LAPACK, whose reflector is the default form. For each column k (k < min(m, n)):

auto [v, vtv, alpha] = householder(A(k:m-1, k), tag::textbook_reflector{}); if !(vtv > 0): skip the column (tau(k) = 0, column k untouched) apply_householder_left(A, v, vtv, k, k+1, tag::textbook_reflector{}); R(k,k) = alpha

so R on and above the diagonal is bit-identical to a hand-written textbook QR. R's diagonal sign, -sign(x_k)*||x||, is the default's too from 5.22.0 (#672); the values differ in rounding. Below the diagonal and in tau the same reflector is stored in MTL5's packed form, v/v(0) with tau(k) = 2*v(0)^2/vtv, so qr_extract_Q and qr_solve work on the result unchanged. Their Q agrees with the textbook Q to rounding, not to the bit: the packed form is a rescaling of v. Returns 0.

◆ qr_normalize_signs()

template<Matrix MQ, Matrix MR>
void mtl::qr_normalize_signs ( MQ & Q,
MR & R )

Make R's diagonal non-negative: for each k < min(m, n) with R(k,k) < 0, negate row k of R and column k of Q.

Q*R is unchanged (Q D D R with D = diag(+-1)), and for a full-rank A the result is the unique QR with a positive diagonal.

qr_factor reflects onto -sign(x_k)*||x||, LAPACK's sign, so R(k,k) < 0 wherever the pivot entry was positive (#672). This is for callers that relied on the non-negative diagonal qr_factor gave before 5.22.0. It needs the explicit Q and R (qr_extract_Q, qr_extract_R): the packed factor has no way to store a negated column of Q. For a complex A, R's diagonal is real by construction and its real part is tested.

◆ qr_solve()

template<typename Accumulator = void, FieldMatrix M, Vector VecX, Vector VecB>
void mtl::qr_solve ( const M & QR,
const vec::dense_vector< typename M::value_type > & tau,
VecX & x,
const VecB & b )

Solve A*x = b via QR factorization (least-squares for m > n).

A must already be factored via qr_factor. x has size n, b has size m. Throws std::invalid_argument for m < n or vectors of the wrong size. Accumulator (leading, default void) rounds the two sums this solve forms itself: each reflector's v^H*y when forming Q^H*b, and each row's sum of R(i,j)*x(j) in the back substitution (#536). The subtraction from y(i) and the division by R(i,i) happen after the sum is rounded out.

◆ qr_solve_dispatch()

template<Matrix M, Vector VecX, Vector VecB>
void mtl::qr_solve_dispatch ( const M & A,
VecX & x,
const VecB & b )

QR-based solve with automatic dispatch.

For sparse double (dense_vector<double> x, b) with SPQR: uses SPQR. Both sparse paths throw std::invalid_argument for m < n (underdetermined). For sparse (any type): uses native sparse QR. For dense: uses in-place dense QR.

◆ random_matrix() [1/3]

template<typename T = double>
auto mtl::random_matrix ( std::size_t m,
std::size_t n,
T lo,
T hi,
std::mt19937_64 & gen )

An m x n dense2D with uniform values in [lo, hi), drawn from gen row by row.

◆ random_matrix() [2/3]

template<typename T = double>
auto mtl::random_matrix ( std::size_t m,
std::size_t n,
T lo,
T hi,
std::uint64_t seed )

An m x n dense2D with uniform values in [lo, hi), reproducibly from seed.

◆ random_matrix() [3/3]

template<typename T = double>
auto mtl::random_matrix ( std::size_t m,
std::size_t n,
T lo = T(0),
T hi = T(1) )

An m x n dense2D with uniform values in [lo, hi), non-deterministically.

◆ random_vector() [1/3]

template<typename T = double>
auto mtl::random_vector ( std::size_t n,
T lo,
T hi,
std::mt19937_64 & gen )

A dense_vector of size n with uniform values in [lo, hi), drawn from gen.

◆ random_vector() [2/3]

template<typename T = double>
auto mtl::random_vector ( std::size_t n,
T lo,
T hi,
std::uint64_t seed )

A dense_vector of size n with uniform values in [lo, hi), reproducibly from seed.

◆ random_vector() [3/3]

template<typename T = double>
auto mtl::random_vector ( std::size_t n,
T lo = T(0),
T hi = T(1) )

A dense_vector of size n with uniform values in [lo, hi), non-deterministically.

◆ rcond()

template<Matrix M>
magnitude_t< typename M::value_type > mtl::rcond ( const M & A)

Reciprocal 2-norm condition number sigma_min / sigma_max, in [0, 1] (0 for a rank-deficient or zero matrix).

Numerically safer than condition_number when the matrix may be singular. The empty matrix returns 1.

◆ real() [1/2]

template<Matrix M>
auto mtl::real ( const M & m)

Element-wise real for matrices -> dense2D<magnitude_t<T>>.

◆ real() [2/2]

template<Vector V>
auto mtl::real ( const V & v)

Element-wise real for vectors -> dense_vector<magnitude_t<T>>.

◆ reorder()

template<typename Value, typename Params>
dense2D< Value, Params > mtl::mat::reorder ( const dense2D< Value, Params > & A,
const std::vector< std::size_t > & perm )

Symmetric reorder: B = P * A * P^T B(i,j) = A(perm[i], perm[j]).

◆ reorder_cols()

template<typename Value, typename Params>
dense2D< Value, Params > mtl::mat::reorder_cols ( const dense2D< Value, Params > & A,
const std::vector< std::size_t > & perm )

Reorder columns: B(:,j) = A(:,perm[j]).

◆ reorder_rows()

template<typename Value, typename Params>
dense2D< Value, Params > mtl::mat::reorder_rows ( const dense2D< Value, Params > & A,
const std::vector< std::size_t > & perm )

Reorder rows: B(i,:) = A(perm[i],:).

◆ resource()

template<Collection C>
auto mtl::resource ( const C & c)

Returns the resource descriptor of a collection (its size).

Named boundary for future distributed-vector extension.

◆ round() [1/2]

template<Matrix M>
auto mtl::round ( const M & m)

Element-wise round for matrices.

◆ round() [2/2]

template<Vector V>
auto mtl::round ( const V & v)

Element-wise round for vectors.

◆ rsf2csf()

template<typename Value>
requires std::floating_point<Value>
schur_result< std::complex< Value > > mtl::rsf2csf ( const mat::dense2D< Value > & Q,
const mat::dense2D< Value > & T )

Convert a real Schur decomposition A = Q T Q^T into the complex one, A = U R U^H with U unitary and R upper triangular, as MATLAB's rsf2csf does.

Each 2x2 block of T is split by a complex rotation; R's diagonal then holds the eigenvalues, with the one of positive imaginary part first in each pair. Element types with a std::complex (float, double, long double) for now; a customization point for Universal's complex type follows (#650).

◆ scale()

template<typename Accumulator = void, Scalar S, MutableCollection C>
void mtl::scale ( const S & alpha,
C & c )

In-place scale: c[i] *= alpha.

Mixed precision: pass an explicit Accumulator to form each product in a precision distinct from the element type; the result is rounded out to the element type on store (#261, Part C). Default Accumulator = void keeps today's SIMD / generic dispatch byte for byte.

WHAT THIS BUYS, STATED PRECISELY, because it is less than axpy's and it would be easy to imply otherwise. A scale sums nothing: each element is a SINGLE product, seeded from zero. So the configurations do not separate the way they do in a reduction –

  • config 2 buys NOTHING here. fma(m, v, 0) is m * v rounded once, and so is a plain multiply. There is no product rounding to fuse away.
  • config 3 buys NOTHING here either, for the same reason: an IEEE multiply is ALREADY correctly rounded, so a quire has no rounding to remove.

What a non-default accumulator does buy is WIDENING: the product is formed in Acc and rounded once to the element type, where the default forms it in the element type. Scaling a bfloat16 vector by a float with Acc = float is the case that matters, and it is a real difference – but it is a precision difference, not an exactness one.

It is threaded anyway because Part C's goal is that every BLAS routine be specializable by the same policy, and a caller writing scale<Acc> alongside axpy<Acc> and dot<Acc> should not have to know which of them the policy can actually help. The honest answer to "what does a quire do for scale" is "nothing", and it belongs in the code rather than in the reader's surprise.

◆ scaled()

template<typename Accumulator = void, Scalar S, Collection C>
auto mtl::scaled ( const S & alpha,
const C & c )

Returns a scaled copy of a vector.

Forwards the accumulator policy, so scaled<Acc> and scale<Acc> agree.

◆ schur()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::schur ( const M & A)

Schur decomposition of a square matrix.

Use as auto [Q, T] = mtl::schur(A);.

Real A: A = Q T Q^T with Q orthogonal and T quasi-upper-triangular. T's 1x1 diagonal blocks are the real eigenvalues; each 2x2 block [a b; c a] with b*c < 0 holds the complex pair a +- i sqrt(-b*c).

Complex A (std::complex<R>): A = Q T Q^H with Q unitary and T upper triangular, the eigenvalues on its diagonal. The in-house path is LAPACK zlahqr's single-shift QR iteration, generic in R as the real path is, after the same scaling by a power of two (of the largest real or imaginary part). dense2D<std::complex<float/double>> dispatch to LAPACK cgees/zgees. A non-void Accumulator selects the in-house path, which for a complex matrix keeps the default accumulation throughout (see detail::schur_complex).

Throws std::invalid_argument if A is not square or has a NaN or infinite entry, and std::runtime_error if the QR iteration does not converge.

In-house path, for every real element type:

  • The deflation test is relative to the type's own epsilon (measured for a type without numeric_limits), with LAPACK's safe-minimum floor when numeric_limits gives one that is meaningful.
  • A is first scaled by a power of two to max |a_ij| in [1/2, 1], and T is scaled back at the end. The EISPACK iteration forms products of two matrix entries, which overflow or underflow for an IEEE matrix with entries near 1e200 or 1e-200; scaling makes them safe, and is exact in a binary floating-point type. For a posit, whose precision is greatest near 1, it also keeps the deflation test reachable.
  • A fixed-point type has no dynamic range: the products in the iteration must stay representable, so A should be scaled well inside the range.

Dispatches to LAPACK gees when MTL5_HAS_LAPACK is defined and the type qualifies (dense2D<float/double>, either orientation). Accumulator (leading, default void) is forwarded to the Hessenberg reduction and the formation of its Q; a non-void accumulator takes the in-house path. The QR iteration's updates are fixed 2- and 3-term expressions and keep plain arithmetic.

◆ set_to_zero()

template<MutableCollection C>
void mtl::set_to_zero ( C & c)

Set all elements of a collection to zero.

◆ signum() [1/2]

template<Matrix M>
auto mtl::signum ( const M & m)

Element-wise signum for matrices.

◆ signum() [2/2]

template<Vector V>
auto mtl::signum ( const V & v)

Element-wise signum for vectors: +1, 0, or -1.

◆ sin() [1/2]

template<Matrix M>
auto mtl::sin ( const M & m)

Element-wise sin for matrices.

◆ sin() [2/2]

template<Vector V>
auto mtl::sin ( const V & v)

Element-wise sin for vectors.

◆ sinh() [1/2]

template<Matrix M>
auto mtl::sinh ( const M & m)

Element-wise sinh for matrices.

◆ sinh() [2/2]

template<Vector V>
auto mtl::sinh ( const V & v)

Element-wise sinh for vectors.

◆ size()

template<Collection C>
auto mtl::size ( const C & c)

Return the number of elements in a collection.

◆ solve()

template<Matrix M, Vector VecX, Vector VecB>
void mtl::solve ( const M & A,
VecX & x,
const VecB & b )

General-purpose solve: A*x = b.

Dispatches to LU (the most general factorization). For SPD systems, prefer cholesky_solve_dispatch for 2x performance.

◆ spectral_radius()

template<Matrix M>
magnitude_t< typename M::value_type > mtl::spectral_radius ( const M & A)

Spectral radius: max |eigenvalue|.

Requires a square matrix (precondition, as for eigenvalue); the empty (0x0) matrix has spectral radius 0.

◆ spgemm()

template<typename Accumulator = void, typename V1, typename P1, typename V2, typename P2>
auto mtl::spgemm ( const mat::compressed2D< V1, P1 > & A,
const mat::compressed2D< V2, P2 > & B )

Sparse-sparse product C = A * B, all in CSR (compressed2D).

Requires A.num_cols() == B.num_rows().

Accumulator selects how each C(i,j) accumulates (see math/accumulator_traits.hpp and the header note); the default void keeps the plain scatter.

◆ sqrt() [1/2]

template<Matrix M>
auto mtl::sqrt ( const M & m)

Element-wise sqrt for matrices.

◆ sqrt() [2/2]

template<Vector V>
auto mtl::sqrt ( const V & v)

Element-wise sqrt for vectors.

◆ sqrtm()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::sqrtm ( const M & A)

The principal square root of a square matrix: the X with X X = A whose eigenvalues have positive real parts, as a dense2D of A's element type.

A real A gives a real X, also when A has complex eigenvalues.

Throws std::invalid_argument if A is not square or has a NaN or infinite entry, std::domain_error if A has an eigenvalue on the closed negative real axis (then no principal square root exists, for a real and a complex A alike), std::overflow_error if the root is too large to represent, and std::runtime_error if the Schur decomposition does not converge or a pivot of the triangular recurrence underflows.

Accumulator (leading, default void) is forwarded to schur() and to the two products that form Q R Q^H; void keeps their LAPACK/BLAS dispatch. The triangular recurrence keeps plain arithmetic.

◆ sqrtm_cond()

template<typename Accumulator = void, FieldMatrix M>
auto mtl::sqrtm_cond ( const M & A)

An estimate of the relative condition number of the principal square root at A in the 1-norm.

Throws as sqrtm() does.

◆ sqrtm_frechet()

template<typename Accumulator = void, FieldMatrix MA, FieldMatrix ME>
auto mtl::sqrtm_frechet ( const MA & A,
const ME & E )

sqrt(A) and the Frechet derivative L_sqrt(A, E): X = sqrtm(A), and L solves X L + L X = E.

Throws as sqrtm() and sylvester() do, and std::runtime_error when sylvester() had to perturb a pivot to solve it: the derivative is then not determined to working precision.

◆ strict_lower() [1/2]

template<typename Matrix>
void mtl::strict_lower ( const Matrix && )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ strict_lower() [2/2]

template<typename Matrix>
auto mtl::strict_lower ( const Matrix & A)

Create a strict lower triangular view (excludes diagonal).

◆ strict_upper() [1/2]

template<typename Matrix>
void mtl::strict_upper ( const Matrix && )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ strict_upper() [2/2]

template<typename Matrix>
auto mtl::strict_upper ( const Matrix & A)

Create a strict upper triangular view (excludes diagonal).

◆ sum()

template<typename Accumulator = void, Collection C>
auto mtl::sum ( const C & c)

Returns the sum of all elements: sum(c[i]).

Accumulator selects how the sum accumulates (see the header note and math/accumulator_traits.hpp); the default void is the plain value_type sum.

◆ sum_k()

template<int K, Collection C>
requires (K >= 1) && math::binary_floating_point<typename C::value_type>
auto mtl::sum_k ( const C & x)

The sum of x as if computed in K-fold working precision and rounded once: Ogita-Rump-Oishi SumK (K >= 2), and the plain recursive sum for K = 1.

See the header for the bound.

◆ svd() [1/4]

template<typename Accumulator = void, FieldMatrix M>
void mtl::svd ( const M & A,
mat::dense2D< typename M::value_type > & U,
mat::dense2D< typename M::value_type > & S,
mat::dense2D< typename M::value_type > & V,
typename M::value_type tol = std::numeric_limits<typename M::value_type>::epsilon() )

SVD: decompose A (m x n) = U * S * V^T U is m x m orthogonal, S is m x n diagonal (stored as m x n matrix), V is n x n orthogonal.

Singular values are non-negative and returned in descending order.

Uses one-sided Jacobi: the columns are orthogonalized by plane rotations, which are accumulated into V, and the singular values are the resulting column norms.

tol is the relative threshold for treating a column pair as already orthogonal, i.e. the accuracy the singular values are driven to. It defaults to the machine epsilon of the value type; the previous default of 1e-10 would cap accuracy several orders of magnitude short of what the method achieves. Callers wanting the old, looser behaviour can pass 1e-10 explicitly, and a larger tolerance trades accuracy for fewer sweeps.

◆ svd() [2/4]

template<typename Accumulator = void, FieldMatrix M>
void mtl::svd ( const M & A,
mat::dense2D< typename M::value_type > & U,
vec::dense_vector< typename M::value_type > & s,
mat::dense2D< typename M::value_type > & V,
typename M::value_type tol = std::numeric_limits<typename M::value_type>::epsilon() )

Thin SVD: A (m x n) = U * diag(s) * V^T with k = min(m, n), U m x k and V n x k, both with orthonormal columns, and s (length k) descending.

Unlike svd(A, U, S, V) it never forms the m x m U, whose completion to a full basis is most of the full svd's time for a tall A (0.24 s at 400 x 9).

With LAPACK, a float or double dense2D goes to gesdd in its thin mode ('S'), as the full svd goes to gesdd in its full mode. Otherwise:

  • m > n: A = QR by Householder QR, one-sided Jacobi on the n x n R as in svd(A, s, V), and U = Q [U_R; 0], formed by applying the n stored reflectors to the n x n U_R, so in O(m n^2).
  • m <= n: one-sided Jacobi on A. U, s and V's columns are bit-identical to the first m of svd(A, U, S, V). U's columns for zero singular values are completed to an orthonormal set as in the full svd. tol is as for svd.

◆ svd() [3/4]

template<typename Accumulator = void, FieldMatrix M>
auto mtl::svd ( const M & A,
typename M::value_type tol = std::numeric_limits<typename M::value_type>::epsilon() )

Convenience overload returning a tuple of (U, S, V).

◆ svd() [4/4]

template<typename Accumulator = void, FieldMatrix M>
void mtl::svd ( const M & A,
vec::dense_vector< typename M::value_type > & s,
mat::dense2D< typename M::value_type > & V,
typename M::value_type tol = std::numeric_limits<typename M::value_type>::epsilon() )

SVD without U: the singular values s (length min(m,n), descending) and the n x n right singular vectors V, so that A * V(:,j) = s(j) * u_j for some unit u_j that is never formed (#566).

A null-space caller – the 8-point (2n x 9) or DLT (2n x 12) problem – needs only V's last column, and the full svd spends most of its time on the m x m U and on rotating m-long columns.

For a tall A (m > n) the matrix is first reduced by Householder QR, A = QR, and one-sided Jacobi runs on the n x n triangle R (Drmac & Veselic's preconditioner): R has A's singular values and right singular vectors, and the sweeps then cost O(n^3) instead of O(m n^2) each, after an O(m n^2) QR. Householder QR is column-wise backward stable, so a column scaling of A carries over to R and Jacobi's relative accuracy is kept. For m <= n the Jacobi runs on A itself and S and V are bit-identical to svd(A, U, S, V).

Always the generic C++ path: LAPACK's gesdd, the full svd's backend, has no V-only mode. tol is as for svd.

◆ sylvester()

template<typename Accumulator = void, FieldMatrix MA, FieldMatrix MB, FieldMatrix MC>
auto mtl::sylvester ( const MA & A,
const MB & B,
const MC & C,
sylvester_sign sign = sylvester_sign::plus )

Solve A X + X B = C (sylvester_sign::plus, the default) or A X - X B = C (sylvester_sign::minus) for general square A (m x m) and B (n x n), and C (m x n), by the Bartels-Stewart method: A = Q_A T_A Q_A^H and B = Q_B T_B Q_B^H by schur(), then T_A Y + Y T_B = Q_A^H C Q_B by sylvester_triangular(), and X = Q_A Y Q_B^H.

Use as auto [X, perturbed] = mtl::sylvester(A, B, C);.

Errors, each naming its cause:

  • std::invalid_argument when A or B is not square, when C is not m x n, or when an entry of A, B or C is NaN or infinite ("mtl::sylvester: C has a NaN or infinite entry"), checked here in the caller's basis;
  • std::overflow_error when the Schur form of A or B is not representable, although A and B are finite (an eigenvalue beyond the range);
  • std::overflow_error when X itself is too large to represent: an entry that is infinite, NaN, or at the type's largest value;
  • std::runtime_error from schur() when its QR iteration does not converge.

A large finite C, or a large Y, does not cause an error when X is representable (issue 991). The basis changes can grow an entry by up to sqrt(m n), and a real or imaginary part of a complex entry by sqrt(2 m n); so does each partial sum of the products. Where C, or Y before the back-transform, has a part above max / (m + n) (max / (2 (m + n)) for a complex type), it is scaled down by a power of two first, and X is scaled back at the end. In a binary type that scaling rounds nothing, unless it makes an entry much smaller than the largest subnormal or zero. Y is first solved unscaled; only when that solve overflows, in Y or in its own products of T_A or T_B with Y, is it solved again for 2^-k F, with k from m + n and the largest entry of the Schur forms. Input below these bounds takes none of these steps and gives the same X as before.

Accumulator (leading, default void) is forwarded to schur(), sylvester_triangular() and the four matrix products. Real and complex element types: for complex A and B the Schur forms are complex and triangular, and the transforms use Q^H (#650).

◆ sylvester_triangular()

template<typename Accumulator = void, FieldMatrix MA, FieldMatrix MB, FieldMatrix MC>
auto mtl::sylvester_triangular ( const MA & A,
const MB & B,
const MC & C,
sylvester_sign sign = sylvester_sign::plus )

Solve A X + X B = C (sylvester_sign::plus, the default) or A X - X B = C (sylvester_sign::minus) for X, where A (m x m) and B (n x n) are upper quasi-triangular, as schur() returns them, or upper triangular, as rsf2csf() returns them.

C and X are m x n. Use as auto [X, perturbed] = mtl::sylvester_triangular(TA, TB, C);.

The equation has a unique solution exactly when A and -B (B, for minus) have no eigenvalue in common. When they come within roundoff of one, the result's perturbed flag is set; see sylvester_result.

Throws std::invalid_argument when A or B is not square or not upper quasi-triangular, when C is not m x n, or when an entry of A, B or C is NaN or infinite. Throws std::overflow_error when X is too large to represent in the element type: an entry that is infinite, NaN, or at the type's largest value, where a posit saturates. Without that check an IEEE type would return infinities and a posit maxpos, silently. sylvester_triangular_scaled() returns such an X scaled down instead. The in-house path solves unscaled first, so it keeps the small entries of an X with a wide range. When that overflows, it solves again scaled and returns X divided back if that fits: a block's sum of products can overflow although X does not (issue 997).

In-house path, for every element type, real or complex:

  • X is computed block column by block column of B from the left, and in each, block row by block row of A from the bottom. Each block solves A_kk Y + sgn Y B_ll = C_kl - sum_j A_kj X_jl - sgn sum_j X_kj B_jl, of at most 2x2 unknowns, by complete pivoting (LAPACK dlasy2).
  • The sums are accumulated in Accumulator (leading, default void: plain arithmetic in the element type), so a quire makes each one exact.
  • The singularity threshold is LAPACK trsyl's, eps * max(max|a_ij|, max|b_ij|), with its safe-minimum floor when numeric_limits gives one that is below eps.

Dispatches to LAPACK trsyl when MTL5_HAS_LAPACK is defined, the accumulator is void and A, B and C are dense float/double, or dense complex<float/double> with A and B upper triangular.

◆ sylvester_triangular_scaled()

template<typename Accumulator = void, FieldMatrix MA, FieldMatrix MB, FieldMatrix MC>
auto mtl::sylvester_triangular_scaled ( const MA & A,
const MB & B,
const MC & C,
sylvester_sign sign = sylvester_sign::plus )

Solve A X + X B = scale * C (sylvester_sign::plus, the default) or A X - X B = scale * C (sylvester_sign::minus) for X and a scale factor 0 < scale <= 1, as LAPACK trsyl does.

A and B are as for sylvester_triangular(). Use as auto [X, scale, perturbed] = mtl::sylvester_triangular_scaled(TA, TB, C);.

scale is 1 unless the solution, or an intermediate of its computation, would exceed the range of the element type. Then the solve scales the right-hand side down by powers of two as it goes, so that X stays representable, and reports the product of those factors. This is for callers that need only the direction or the relative size of X, such as condition estimators, which solve many nearly singular equations; sylvester_triangular() is the call for X itself.

The solve scales once a block's solution would exceed max * eps / (m n), from numeric_limits; for double and for posits that is LAPACK's eps / (safmin m n). The margin of eps / (m n) below the largest value keeps the later sums of products of A, B and X in range. A type without numeric_limits has no threshold and always gets scale = 1. It also scales before forming a block's right-hand side, C_kl minus the sums of products of A, B and the X already solved, once a bound on it, taken in binary exponents, exceeds max / 32 (issue 997); reference trsyl leaves those sums unguarded, as LAPACK's trsyl3 does not. A LAPACK result with an infinite or NaN entry is solved again in-house. Scaling is by powers of two, so entries of X far smaller than its largest can become subnormal or zero; that is the price of a representable X.

Throws std::invalid_argument as sylvester_triangular() does. Dispatches to LAPACK trsyl in the same cases, passing its scale through.

◆ symm()

template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB, Matrix MC>
void mtl::symm ( const S & alpha,
const MA & A,
const MB & B,
const S & beta,
MC & C )

Symmetric matrix-matrix product: C = alpha*A*B + beta*C, A assumed symmetric.

◆ symmetric_swap()

template<Matrix M>
void mtl::symmetric_swap ( M & A,
std::size_t r1,
std::size_t r2,
std::size_t first_col = 0 )

Swap rows and columns r1 and r2 in the lower triangle of a symmetric matrix, touching only columns >= first_col.

Only the lower triangle (and diagonal) is accessed and modified.

first_col matters for Bunch-Kaufman. The factorization is a PRODUCT of per-step permutations and elementary transforms,

A = (P_0 L_0)(P_1 L_1)... D ...(P_1 L_1)^T (P_0 L_0)^T

not a single global permutation, and ldlt_bk_solve replays those permutations one step at a time (as LAPACK's dsytrs does). So the L columns already written by earlier steps must be left ALONE: they are recorded in the row ordering that was current when they were computed, and the solve reaches them before the later interchanges are replayed.

Permuting them here instead produces a factor in the "single global P" convention while the solve still reads the per-step one. The two disagree the moment any interchange happens, which silently returned wrong solutions with info == 0 (#335). Passing first_col = k keeps the swap inside the trailing submatrix, which is also what makes the stored factor match LAPACK's dsytrf byte for byte.

◆ symv()

template<typename Accumulator = void, Scalar S, Matrix M, Vector VX, Vector VY>
void mtl::symv ( const S & alpha,
const M & A,
const VX & x,
const S & beta,
VY & y )

Symmetric matrix-vector product: y = alpha*A*x + beta*y, A assumed symmetric.

Mixed precision: pass an explicit Accumulator to form each row's A*x reduction in a precision distinct from the operand type (#261, Part C); the result is rounded out to y's element type before the alpha/beta combine. Default Accumulator = void keeps the BLAS / generic dispatch byte for byte.

Gated on interface::accumulator_allows_blas_v, exactly as gemv (via mult) and dot are: a custom accumulator cannot be honored by external BLAS, whose symv accumulates in a hardware-fixed precision.

The accumulator sums only the row's A(i,j)*x(j) products, seeded with clear – the alpha/beta combine happens once, outside the reduction, same as gemv's generic row loop and unlike axpy's assign-seeded one-term sum.

◆ syr2k()

template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB, Matrix MC>
void mtl::syr2k ( const S & alpha,
const MA & A,
const MB & B,
const S & beta,
MC & C )

Symmetric rank-2k update: C = alpha*(A*B^T + B*A^T) + beta*C, C symmetric.

◆ syrk()

template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MC>
void mtl::syrk ( const S & alpha,
const MA & A,
const S & beta,
MC & C )

Symmetric rank-k update: C = alpha*A*A^T + beta*C, C symmetric (full result).

◆ tan() [1/2]

template<Matrix M>
auto mtl::tan ( const M & m)

Element-wise tan for matrices.

◆ tan() [2/2]

template<Vector V>
auto mtl::tan ( const V & v)

Element-wise tan for vectors.

◆ tanh() [1/2]

template<Matrix M>
auto mtl::tanh ( const M & m)

Element-wise tanh for matrices.

◆ tanh() [2/2]

template<Vector V>
auto mtl::tanh ( const V & v)

Element-wise tanh for vectors.

◆ to_host()

template<typename C>
auto mtl::to_host ( const C & x) ->decltype(copy_to< memory_space::host >(x))

A new host container holding x's elements: always a copy (#1017).

There is no aliasing variant: a container in shared or pinned memory is already host-accessible, and one in device memory can reach the host only as a copy.

◆ trace()

template<typename Accumulator = void, Matrix M>
auto mtl::trace ( const M & A)

trace(A) = sum(A(i,i)) for i = 0..min(nrows,ncols)-1

Accumulator selects how the sum accumulates; the default void is the plain value_type sum.

◆ trans() [1/2]

template<Matrix M>
void mtl::trans ( const M && )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ trans() [2/2]

template<Matrix M>
auto mtl::trans ( const M & m)

Returns a lightweight transposed view of matrix m.

◆ tridiagonalize()

template<typename Accumulator = void, Matrix M>
void mtl::tridiagonalize ( M & A,
vec::dense_vector< typename M::value_type > & tau )

Reduce a symmetric (or Hermitian) matrix to tridiagonal form in-place.

After this call, the diagonal and subdiagonal of A contain the tridiagonal matrix. Hessenberg reduction of a symmetric matrix is tridiagonal; of a Hermitian matrix it is Hermitian tridiagonal (real diagonal, conjugate off-diagonals), so the subdiagonal entries may carry a phase.

◆ tril() [1/2]

template<typename Matrix>
void mtl::tril ( const Matrix && ,
std::ptrdiff_t = 0 )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ tril() [2/2]

template<typename Matrix>
auto mtl::tril ( const Matrix & A,
std::ptrdiff_t k = 0 )

MATLAB-compatible tril(A, k): elements on diag k and below.

tril(A, 0) = lower(A), tril(A, -1) = strict_lower(A), etc.

◆ triu() [1/2]

template<typename Matrix>
void mtl::triu ( const Matrix && ,
std::ptrdiff_t = 0 )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ triu() [2/2]

template<typename Matrix>
auto mtl::triu ( const Matrix & A,
std::ptrdiff_t k = 0 )

MATLAB-compatible triu(A, k): elements on diag k and above.

triu(A, 0) = upper(A), triu(A, 1) = strict_upper(A), etc.

◆ trmm()

template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB>
void mtl::trmm ( const S & alpha,
const MA & A,
MB & B,
bool upper,
bool unit_diag = false )

Triangular matrix-matrix product: B = alpha * A * B, A upper/lower triangular.

Mixed precision: pass an explicit Accumulator to form each (row, col) reduction in a precision distinct from the operand type (#261, Part C). Default Accumulator = void keeps the BLAS / generic dispatch byte for byte.

Gated on interface::accumulator_allows_blas_v, same as trmv/symv: a custom accumulator cannot be honored by external BLAS.

The diagonal term (1*B(i,c) for unit_diag, A(i,i)*B(i,c) otherwise) is fed through add_product as the first term of a clear-seeded reduction per (row, col) pair – same shape as trmv's row loop extended over B's columns – not special-cased as a seed, so the diagonal gets the same rounding treatment as every off-diagonal term.

The traversal order (forward for upper, reverse for lower) is an in-place-overwrite hazard, not a precision concern: B(j,c) for the off-diagonal terms must still hold its original value when read, which this order guarantees regardless of Accumulator. Unchanged by this patch.

◆ trmv()

template<typename Accumulator = void, Matrix M, Vector VX>
void mtl::trmv ( const M & A,
VX & x,
bool upper,
bool unit_diag = false )

Triangular matrix-vector product: x = A*x, A upper/lower triangular.

Mixed precision: pass an explicit Accumulator to form each row's reduction in a precision distinct from the operand type (#261, Part C). Default Accumulator = void keeps the BLAS / generic dispatch byte for byte.

Gated on interface::accumulator_allows_blas_v, same as symv/gemv: a custom accumulator cannot be honored by external BLAS.

The diagonal term (1*x(i) for unit_diag, A(i,i)*x(i) otherwise) is fed through add_product as the first term of a clear-seeded reduction, same shape as symv's row loop – not special-cased as a seed – so the diagonal gets the same rounding treatment as every off-diagonal term.

The traversal order (forward for upper, reverse for lower) is an in-place-overwrite hazard, not a precision concern: x(j) for the off-diagonal terms must still hold its original value when read, which this order guarantees regardless of Accumulator. Unchanged by this patch.

◆ trsm()

template<typename Accumulator = void, Scalar S, Matrix MA, Matrix MB>
void mtl::trsm ( const S & alpha,
const MA & A,
MB & B,
bool upper,
bool unit_diag = false )

Triangular solve with multiple RHS: solve A * X = alpha * B, B := X.

alpha == 0 gives X = 0 without reading A or B, as BLAS does.

◆ trsv() [1/2]

template<typename Accumulator = void, Matrix M, Vector VX>
void mtl::trsv ( const M & A,
VX & x,
bool upper,
bool unit_diag = false )

Solve A*x = x in place, A upper/lower triangular.

◆ trsv() [2/2]

template<typename Accumulator = void, Matrix M, Vector VX, Vector VB>
void mtl::trsv ( const M & A,
VX & x,
const VB & b,
bool upper,
bool unit_diag = false )

Solve A*x = b, writing the solution into x (b unchanged).

◆ two_norm()

template<typename Accumulator = void, typename Result = void, Vector V>
auto mtl::two_norm ( const V & v)

two_norm(v) = sqrt(sum(|v[i]|^2)).

Mixed precision: pass an explicit Accumulator to sum the squares in a wider precision than the element magnitude (e.g. two_norm<double>(v) over a bfloat16/float vector), guarding the long reduction against overflow and precision loss. Default Accumulator = void keeps the SIMD / loop dispatch unchanged.

Result is the delivery type, as in dot (#379). It defaults to void, meaning the element magnitude type – today's behaviour, byte for byte.

Note what Result governs: NOT just the final cast. It also selects the type the accumulator is rounded out to before the square root. That distinction is the whole feature. accumulator_round_type_t<Acc, Mag> maps a non-arithmetic accumulator (a quire, a compensated sum) to Mag, so leaving it at the magnitude type would round an exact accumulation down to the element's precision BEFORE the sqrt, and a wider return type could not recover it – two_norm<quire, double> would then be no better than two_norm<>, and strictly worse than two_norm<double, double>. Measured on a 20000-element float vector: 2.372e-08 relative error that way, against 0.0 when Result feeds the round-out as it does here.

◆ unit_vector()

template<typename Value = double>
dense_vector< Value > mtl::vec::unit_vector ( std::size_t n,
std::size_t k )

Create a unit vector of size n with 1 at position k, 0 elsewhere.

◆ upper() [1/2]

template<typename Matrix>
void mtl::upper ( const Matrix && )
delete

Deleted for an rvalue (#695): the view refers to its matrix, so a view of a temporary dangles once the full expression ends.

Name the matrix first.

◆ upper() [2/2]

template<typename Matrix>
auto mtl::upper ( const Matrix & A)

Create an upper triangular view (includes diagonal).

◆ upper_trisolve() [1/2]

template<typename Accumulator = void, Matrix M, Vector VecX>
void mtl::upper_trisolve ( const M & U,
VecX & x,
bool unit_diag = false )

In-place variant: solve U*x = x (b is x on input).

◆ upper_trisolve() [2/2]

template<typename Accumulator = void, Matrix M, Vector VecX, Vector VecB>
void mtl::upper_trisolve ( const M & U,
VecX & x,
const VecB & b,
bool unit_diag = false )

Solve U*x = b by back substitution where U is upper triangular.

x is overwritten with the solution. If unit_diag is true, the diagonal of U is assumed to be 1.

Variable Documentation

◆ block_gemv_scratch_alignment

template<BlockScheme S>
std::size_t mtl::block_gemv_scratch_alignment = detail::block_scratch_alignment<S>()
inlineconstexpr

The alignment that scratch must have: the fused kernel's scratch_alignment, which must be a power of two, or alignof(std::max_align_t).

◆ bounds_checking

bool mtl::bounds_checking = true
inlineconstexpr

Enable/disable bounds checking (debug builds).

◆ CHOLESKY_NOT_HERMITIAN

int mtl::CHOLESKY_NOT_HERMITIAN = -2
inlineconstexpr

Returned by cholesky_h_factor when the input is complex and has a non-real diagonal, which a Hermitian matrix cannot have.

Negative so it cannot collide with the k+1 not-positive-definite codes.

◆ default_block_size

std::size_t mtl::default_block_size = 64
inlineconstexpr

Default block size for recursive operations.

◆ host_accessible_v

template<typename S>
bool mtl::host_accessible_v
inlineconstexpr
Initial value:
= [] {
if constexpr (MemorySpace<S>) return static_cast<bool>(S::host_accessible);
else return false;
}()
A memory space: says where elements live and who may touch them.
Definition memory_space.hpp:213

Whether host code may read and write elements in space S; false for a type that is not a MemorySpace.

(MemorySpace<S> && S::host_accessible would still substitute S::host_accessible, a hard error for such a type.)

◆ is_complex_v

template<typename T>
bool mtl::is_complex_v = is_complex<std::remove_cv_t<T>>::value
inlineconstexpr

Whether T is a std::complex, cv-qualifiers ignored (#838).

◆ LDLT_NOT_HERMITIAN

int mtl::LDLT_NOT_HERMITIAN = -2
inlineconstexpr

Returned by ldlt_h_factor when the input is complex and has a non-real diagonal, which a Hermitian matrix cannot have – i.e.

the caller wanted LDL^T and would otherwise have received a silently wrong LDL^H. Use ldlt_factor for that input.

◆ LDLT_NOT_SYMMETRIC

int mtl::LDLT_NOT_SYMMETRIC = -1
inlineconstexpr

Returned by ldlt_factor when the input is complex and Hermitian but not symmetric – i.e.

the caller wanted LDL^H and would otherwise have received a silently wrong LDL^T. Negative so it cannot collide with the k+1 zero-pivot codes. Use ldlt_h_factor for that input.

◆ stack_size_limit

std::size_t mtl::stack_size_limit = 256
inlineconstexpr

Threshold below which matrices are stored on the stack.