|
NumericAL
A header-only C++20 lexer built on REAL
|
The NumericAL public API. More...
Namespaces | |
| namespace | blas |
| namespace | detail |
Classes | |
| class | cholesky_decomposition |
A Cholesky factorisation A = L Lᴴ of a Hermitian positive-definite matrix. More... | |
| class | convergence_error |
| Thrown when an iterative algorithm has not converged within its bound of sweeps. More... | |
| class | dimension_error |
| Thrown when an operation's operands have incompatible shapes. More... | |
| class | eigen_decomposition |
The eigenvalues, and optionally the right eigenvectors, of a general square matrix, as numpy.linalg.eig. More... | |
| class | einsum_error |
| Thrown when an einsum specification is malformed or inconsistent. More... | |
| class | hermitian_eigen |
| The eigenvalues and eigenvectors of a complex Hermitian matrix. More... | |
| struct | least_squares_solution |
A least-squares solution and what numpy.linalg.lstsq reports beside it (least_squares). More... | |
| class | lu_decomposition |
| An LU factorisation with partial pivoting of a square matrix. More... | |
| class | matrix |
A dense, row-major matrix of T with value semantics. More... | |
| class | non_finite_error |
| Thrown when a decomposition's input holds an infinite or NaN entry: no factorisation of it means anything, and the iterative ones (eigh, SVD) would stop at once and return plausible values. More... | |
| class | not_positive_definite_error |
| Thrown when a Cholesky factorisation finds the matrix not positive-definite. More... | |
| class | qr_decomposition |
A QR factorisation A = Q R of an m × n matrix, as NumPy's qr, reduced by default. More... | |
| class | rank_cutoff |
The magnitude at or under which a singular value counts as zero, in a rank (matrix_rank), a pseudo-inverse (pinv) or a least-squares solution (lstsq): by default NumPy's, the largest singular value times the machine epsilon times the larger dimension; relative to the largest, as NumPy's rcond and rtol; or absolute, as matrix_rank's tol. More... | |
| class | singular_matrix_error |
| Thrown when a matrix has no unique solution (it is singular). More... | |
| class | svd_decomposition |
The singular value decomposition A = U Σ Vᴴ of an m × n matrix. More... | |
| class | symmetric_eigen |
| The eigenvalues and eigenvectors of a real symmetric matrix. More... | |
| class | tensor |
A dense, row-major, N-dimensional tensor of T with value semantics. More... | |
| class | vector |
A dense vector of T with value semantics. More... | |
Typedefs | |
| template<typename T > | |
| using | buffer = std::vector< T, detail::default_init_allocator< T > > |
The storage of vector, matrix and tensor, namely a std::vector whose buffer<T>(n) and resize(n) leave a double uninitialised, for a result about to be written in full. buffer<T>(n, T {}) zeroes, as std::vector<T>(n) does. | |
Enumerations | |
| enum class | qr_mode { reduced , complete } |
The factors a numerical::qr_decomposition keeps, as numpy.linalg.qr's modes name them. More... | |
| enum class | eigen_method { tridiagonal_ql , jacobi , divide_and_conquer } |
| How numerical::symmetric_eigen diagonalises. More... | |
| enum class | svd_method { bidiagonal_qr , jacobi , divide_and_conquer } |
How numerical::svd_decomposition computes the decomposition of R, after a Householder QR. More... | |
| enum class | gemm_path : std::uint8_t { portable = 0 , neon = 1 , avx2 = 2 , avx512 = 3 , amx = 4 } |
The kernels a double matrix product can run on (a float one too on arm64), from the most portable. Each is used only where the processor has it: NEON on every arm64 chip, the AVX ones where cpuid reports them, the Apple AMX on an M1 to M4 chip whose self-test passes (see x86.hpp and amx.hpp). More... | |
Functions | |
| template<typename T > | |
| vector< T > | solve (matrix< T > a, const vector< T > &b) |
Solves the linear system A x = b for a square A. | |
| template<typename T > | |
| matrix< T > | solve (matrix< T > a, const matrix< T > &b) |
Solves A X = B for a square A and every column of B at once, as numpy.linalg.solve with a matrix right-hand side: one factorisation of A, then one substitution per column. | |
| template<typename T > | |
| T | determinant (matrix< T > a) |
| The determinant of a square matrix. | |
| template<typename T > | |
| matrix< T > | inverse (matrix< T > a) |
| The inverse of a square matrix. | |
| template<typename T > | |
| cholesky_decomposition< T > | cholesky (matrix< T > a) |
| Cholesky-factorises a Hermitian positive-definite matrix. | |
| template<typename T > | |
| qr_decomposition< T > | qr (const matrix< T > &a) |
QR-factorises an m × n matrix. | |
| template<typename T > | |
| vector< T > | lstsq (const matrix< T > &a, const vector< T > &b, rank_cutoff cutoff={}) |
The minimum-norm least-squares solution of A x ≈ b, as NumPy's lstsq gives it. | |
| template<typename T > | |
| matrix< T > | lstsq (const matrix< T > &a, const matrix< T > &b, rank_cutoff cutoff={}) |
The minimum-norm least-squares solution of A X ≈ B for every column of B at once, as numpy.linalg.lstsq with a matrix right-hand side: one SVD of A, X = V Σ⁺ Uᴴ B; or, where a bound on the condition number shows the rank full with room to spare, the same solution to rounding by one QR factorisation (detail::lstsq_by_qr). | |
| template<typename T > | |
| vector< double > | singular_values (const matrix< T > &a) |
The singular values of a, descending, without its singular vectors, as numpy.linalg.svd(a, compute_uv=False): the Householder R of a tall A (of Aᴴ when wide), its Golub–Kahan bidiagonal and the implicit-shift QR iteration on it, no basis formed nor rotated. Each value to an absolute accuracy of the largest times the machine epsilon, as svd_decomposition's. | |
| template<typename T > | |
| vector< double > | symmetric_eigenvalues (const matrix< T > &a) |
The eigenvalues of the real symmetric or complex Hermitian a, ascending, without its eigenvectors, as numpy.linalg.eigvalsh: its Householder tridiagonal (no basis formed) and the implicit QL iteration on it, no rotation kept. Only the lower triangle is read, and of the diagonal its real part. Each value to an absolute accuracy of the largest magnitude times the machine epsilon, as symmetric_eigen's. | |
| template<typename T > | |
| least_squares_solution< T > | least_squares (const matrix< T > &a, const matrix< T > &b, rank_cutoff cutoff={}) |
lstsq, with the residuals, the rank and the singular values numpy.linalg.lstsq returns beside the solution: the residual sums of squares are given only where the solution is unique and need not be exact, A tall (m > n) and of full column rank, as NumPy gives them. | |
| template<typename T > | |
| std::size_t | matrix_rank (const matrix< T > &a, rank_cutoff cutoff={}, bool hermitian=false) |
The numerical rank of a, as numpy.linalg.matrix_rank counts it: its singular values above cutoff. | |
| template<typename T > | |
| matrix< T > | pinv (const matrix< T > &a, rank_cutoff cutoff={}, bool hermitian=false) |
The Moore–Penrose pseudo-inverse of the m × n a (n × m), as numpy.linalg.pinv gives it: V Σ⁺ Uᴴ, a singular value at or under cutoff counting as zero. | |
| template<typename T > | |
| vector< std::complex< double > > | eigenvalues (const matrix< T > &a) |
The eigenvalues alone of the square a, as numpy.linalg.eigvals. | |
| gemm_path | limit_gemm_path (gemm_path most) noexcept |
Keeps double matrix products on most or a more portable path: the most capable path at or below it that can run here. gemm_path::amx restores the best one; gemm_path::portable keeps them on the compiler's own vectors, with no instruction chosen at run time. Paths below the cap are not probed. | |
| gemm_path | gemm_path_in_use () noexcept |
The path double matrix products take. | |
| template<typename T > | |
| matrix< T > | operator+ (const matrix< T > &a, const matrix< T > &b) |
| Element-wise sum. | |
| template<typename T > | |
| matrix< T > | operator- (const matrix< T > &a, const matrix< T > &b) |
| Element-wise difference. | |
| template<typename T > | |
| matrix< T > | operator* (const T &scalar, const matrix< T > &m) |
| Scalar times matrix. | |
| template<typename T > | |
| matrix< T > | operator* (const matrix< T > &m, const T &scalar) |
| Matrix times scalar. | |
| template<typename T > | |
| vector< T > | operator* (const matrix< T > &a, const vector< T > &v) |
Matrix–vector product: each element its row's dot product with v (detail::matrix_times_vector). | |
| template<typename T > | |
| matrix< T > | operator* (const matrix< T > &a, const matrix< T > &b) |
| Matrix–matrix product. | |
| template<typename T > | |
| matrix< T > | transpose (const matrix< T > &m) |
| The transpose, by blocks of transpose_tile, the result's blocks of rows shared among the threads. | |
| template<typename T > | |
| bool | approx_equal (const matrix< T > &a, const matrix< T > &b, double tolerance=1e-9) |
| Element-wise closeness within a tolerance (for inexact scalars). | |
| void | set_max_threads (std::size_t threads) noexcept |
Caps the threads a kernel uses at threads, the caller's included (1: none beside it, and no thread is started); 0 lifts the cap. For a process that runs several kernels side by side (one per worker process, say), so that together they do not ask for more threads than the machine has. | |
| std::size_t | max_threads () |
| The threads a kernel may use: the cap if one is set, else the hardware threads (starting none). | |
| template<typename T > | |
| bool | approx_equal (const tensor< T > &a, const tensor< T > &b, double tolerance=1e-9) |
| Element-wise closeness within a tolerance (for inexact scalars). | |
| template<typename T , typename ... Rest> | |
| tensor< T > | einsum (const std::string &spec, const tensor< T > &first, const Rest &... rest) |
| Einstein summation over one or more tensor operands. | |
| template<typename T > | |
| tensor< T > | einsum (const std::string &spec, const std::vector< const tensor< T > * > &operands) |
Einstein summation over operands counted at run time: einsum for a caller that holds them in a container (an interpreter evaluating einsum("ij,jk->ik", a, b) from a parse). | |
| template<typename T > | |
| tensor< T > | matmul (const tensor< T > &a, const tensor< T > &b) |
The matrix product of two tensors, as NumPy's matmul: each operand a stack of matrices along its leading axes, those axes broadcast against the other's (aligned from the right, an extent of 1 repeated), one product per matrix of the broadcast stack through the packed kernel, the products in parallel. A vector first is a row (its axis absent from the result), a vector second a column (likewise); two vectors give their dot product, of rank 0. The broadcast operands are not copied: a repeated matrix is read where it is. | |
| std::vector< std::size_t > | broadcast_shape (const std::vector< std::size_t > &a, const std::vector< std::size_t > &b) |
The shape two shapes broadcast to, as NumPy's broadcast_shapes. | |
| template<typename T , typename Op > | |
| tensor< T > | broadcast_apply (const tensor< T > &a, const tensor< T > &b, const Op &op) |
op(a, b) element by element, the operands broadcast against each other. | |
| template<detail::split_complex C> | |
| tensor< C > | numpy_multiply (const tensor< C > &a, const tensor< C > &b) |
a · b of complex tensors, broadcast, each product as NumPy's array loop computes it (detail::numpy_multiply on this processor): the binding's *, where std::complex's operator (this library's *) recovers infinities NumPy's makes NaN. | |
| template<detail::split_complex C> | |
| tensor< C > | numpy_divide (const tensor< C > &a, const tensor< C > &b) |
a / b of complex tensors, broadcast, each quotient as NumPy's array loop computes it (detail::numpy_divide on this processor): the binding's /. | |
| template<typename T > | |
| tensor< T > | operator+ (const tensor< T > &a, const tensor< T > &b) |
| Element-wise sum, broadcast. | |
| template<typename T > | |
| tensor< T > | operator- (const tensor< T > &a, const tensor< T > &b) |
| Element-wise difference, broadcast. | |
| template<typename T > | |
| tensor< T > | operator* (const tensor< T > &a, const tensor< T > &b) |
| Element-wise product, broadcast. | |
| template<typename T > | |
| tensor< T > | operator/ (const tensor< T > &a, const tensor< T > &b) |
| Element-wise quotient, broadcast. | |
| template<typename T > | |
| tensor< T > | operator- (const tensor< T > &a) |
| Element-wise negation. | |
| template<typename T , typename F > | |
| auto | map (const tensor< T > &t, const F &f) -> tensor< std::decay_t< decltype(f(std::declval< const T & >()))> > |
f(x) for every element, in a tensor of the same shape and of f's result type. | |
| template<typename T > | |
| tensor< T > | pow (const tensor< T > &a, const tensor< T > &b) |
a to the power b element by element, broadcast, as std::pow; a single exponent of 2, 0.5 or -1 is computed as NumPy computes it, x·x, sqrt(x) or 1/x (exact where pow rounds: a complex square has no stray real part). | |
| template<typename T > | |
| T | sum (const tensor< T > &t) |
| The sum of every element, by pairwise halving (0 for an empty tensor). | |
| template<typename T > | |
| tensor< T > | sum (const tensor< T > &t, std::size_t axis) |
The sums along axis, by pairwise halving. | |
| template<typename T > | |
| T | mean (const tensor< T > &t) |
| The mean of every element. An empty tensor's mean is NaN, as NumPy's (which also warns). | |
| template<typename T > | |
| tensor< T > | mean (const tensor< T > &t, std::size_t axis) |
The means along axis. | |
| template<std::totally_ordered T> | |
| T | max (const tensor< T > &t) |
| The largest element (a NaN, if there is one). | |
| template<std::totally_ordered T> | |
| T | min (const tensor< T > &t) |
| The smallest element (a NaN, if there is one). | |
| template<std::totally_ordered T> | |
| tensor< T > | max (const tensor< T > &t, std::size_t axis) |
The largest elements along axis. | |
| template<std::totally_ordered T> | |
| tensor< T > | min (const tensor< T > &t, std::size_t axis) |
The smallest elements along axis. | |
| template<typename T > | |
| tensor< T > | reshape (const tensor< T > &t, std::vector< std::size_t > shape) |
| The same elements in the same order under another shape. | |
| template<typename T > | |
| tensor< T > | full (std::vector< std::size_t > shape, const T &value) |
A tensor of shape with every element value. | |
| template<typename T > | |
| tensor< T > | zeros (std::vector< std::size_t > shape) |
A tensor of shape full of zeros. | |
| template<typename T > | |
| tensor< T > | ones (std::vector< std::size_t > shape) |
A tensor of shape full of ones. | |
| template<typename T > | |
| tensor< T > | eye (std::size_t n) |
The n × n identity. | |
| tensor< double > | arange (double start, double stop, double step) |
start, start + step, … below stop (above it for a negative step), as NumPy's arange: its length is ceil((stop − start) / step) and element i is start + i·delta with delta = (start + step) − start, the step as the first two elements hold it, rounded once (a fused multiply-add, as NumPy's arm64 builds compute it; one without fusion rounds the product first and can differ in the last bits). | |
| tensor< double > | linspace (double start, double stop, std::size_t count) |
count values evenly spaced from start to stop, both included, as NumPy's linspace: element i is start + i·step with step = (stop − start) / (count − 1), and the last is stop exactly. | |
| template<typename T > | |
| vector< T > | operator+ (const vector< T > &a, const vector< T > &b) |
| Element-wise sum. | |
| template<typename T > | |
| vector< T > | operator- (const vector< T > &a, const vector< T > &b) |
| Element-wise difference. | |
| template<typename T > | |
| vector< T > | operator* (const T &scalar, const vector< T > &v) |
| Scalar times vector. | |
| template<typename T > | |
| vector< T > | operator* (const vector< T > &v, const T &scalar) |
| Vector times scalar. | |
| template<typename T > | |
| T | dot (const vector< T > &a, const vector< T > &b) |
| Dot product. | |
| template<typename T > | |
| bool | approx_equal (const vector< T > &a, const vector< T > &b, double tolerance=1e-9) |
| Element-wise closeness within a tolerance (for inexact scalars). | |
Variables | |
| constexpr std::size_t | transpose_tile {32} |
| The square blocks transpose copies one at a time: a block's rows of the source and of the result both stay in the L1 cache, where a row of the result walked a column of the source a stride apart. | |
The NumericAL public API.
| using numerical::buffer = typedef std::vector<T, detail::default_init_allocator<T> > |
|
strong |
How numerical::symmetric_eigen diagonalises.
Definition at line 4382 of file decomposition.hpp.
|
strong |
The kernels a double matrix product can run on (a float one too on arm64), from the most portable. Each is used only where the processor has it: NEON on every arm64 chip, the AVX ones where cpuid reports them, the Apple AMX on an M1 to M4 chip whose self-test passes (see x86.hpp and amx.hpp).
|
strong |
The factors a numerical::qr_decomposition keeps, as numpy.linalg.qr's modes name them.
| Enumerator | |
|---|---|
| reduced |
|
| complete |
|
Definition at line 2535 of file decomposition.hpp.
|
strong |
How numerical::svd_decomposition computes the decomposition of R, after a Householder QR.
Definition at line 5994 of file decomposition.hpp.
| bool numerical::approx_equal | ( | const matrix< T > & | a, |
| const matrix< T > & | b, | ||
| double | tolerance = 1e-9 |
||
| ) |
Element-wise closeness within a tolerance (for inexact scalars).
| [in] | a,b | Matrices to compare. |
| [in] | tolerance | Maximum allowed magnitude of each element-wise difference. |
true if the shapes match and every element pair is equal or differs by at most tolerance; a NaN is close to nothing. Definition at line 278 of file matrix.hpp.
| bool numerical::approx_equal | ( | const tensor< T > & | a, |
| const tensor< T > & | b, | ||
| double | tolerance = 1e-9 |
||
| ) |
Element-wise closeness within a tolerance (for inexact scalars).
| [in] | a,b | Tensors to compare. |
| [in] | tolerance | Maximum allowed magnitude of each element-wise difference. |
true if the shapes match and every element pair is equal or differs by at most tolerance; a NaN is close to nothing. Definition at line 192 of file tensor.hpp.
| bool numerical::approx_equal | ( | const vector< T > & | a, |
| const vector< T > & | b, | ||
| double | tolerance = 1e-9 |
||
| ) |
Element-wise closeness within a tolerance (for inexact scalars).
| [in] | a,b | Vectors to compare. |
| [in] | tolerance | Maximum allowed magnitude of each element-wise difference. |
true if the sizes match and every element pair is equal or differs by at most tolerance; a NaN is close to nothing. Definition at line 209 of file vector.hpp.
start, start + step, … below stop (above it for a negative step), as NumPy's arange: its length is ceil((stop − start) / step) and element i is start + i·delta with delta = (start + step) − start, the step as the first two elements hold it, rounded once (a fused multiply-add, as NumPy's arm64 builds compute it; one without fusion rounds the product first and can differ in the last bits).
| dimension_error | If step is zero or not finite. |
Definition at line 859 of file tensor_ops.hpp.
| tensor< T > numerical::broadcast_apply | ( | const tensor< T > & | a, |
| const tensor< T > & | b, | ||
| const Op & | op | ||
| ) |
op(a, b) element by element, the operands broadcast against each other.
| dimension_error | If the shapes do not broadcast. |
Definition at line 538 of file tensor_ops.hpp.
|
inline |
The shape two shapes broadcast to, as NumPy's broadcast_shapes.
| dimension_error | If an axis has two extents, neither of them 1. |
Definition at line 515 of file tensor_ops.hpp.
Cholesky-factorises a Hermitian positive-definite matrix.
Definition at line 1907 of file decomposition.hpp.
The determinant of a square matrix.
| dimension_error | If not square. |
Definition at line 1533 of file decomposition.hpp.
Dot product.
| dimension_error | If the sizes differ. |
Definition at line 190 of file vector.hpp.
The eigenvalues alone of the square a, as numpy.linalg.eigvals.
| dimension_error | If a is not square. |
| non_finite_error | If an entry is infinite or NaN. |
| convergence_error | If the QR iterations did not converge. |
| tensor< T > numerical::einsum | ( | const std::string & | spec, |
| const std::vector< const tensor< T > * > & | operands | ||
| ) |
Einstein summation over operands counted at run time: einsum for a caller that holds them in a container (an interpreter evaluating einsum("ij,jk->ik", a, b) from a parse).
| [in] | spec | The einsum specification. |
| [in] | operands | The operands, in the spec's order (none null). |
| einsum_error | As einsum, and if operands is empty. |
| dimension_error | As einsum. |
Definition at line 1315 of file tensor.hpp.
| tensor< T > numerical::einsum | ( | const std::string & | spec, |
| const tensor< T > & | first, | ||
| const Rest &... | rest | ||
| ) |
Einstein summation over one or more tensor operands.
Evaluates spec — input subscripts separated by ,, then ->, then the output subscripts — against the operands. Examples: "ij,jk->ik" (matrix product), "i,i->" (dot product), "ij->ji" (transpose), "ii->" (trace), "i,j->ij" (outer product), "ij->i" (row sums).
| [in] | spec | The einsum specification. |
| [in] | first | The first operand (fixes the scalar type). |
| [in] | rest | Any further operands. |
| einsum_error | If the spec is malformed, the operand count or a rank disagrees with it, or an output label is invalid. |
| dimension_error | If a shared label labels axes of differing extents. |
Definition at line 1297 of file tensor.hpp.
The n × n identity.
Definition at line 842 of file tensor_ops.hpp.
A tensor of shape with every element value.
Definition at line 816 of file tensor_ops.hpp.
|
inlinenoexcept |
The inverse of a square matrix.
| [in] | a | The matrix. |
| dimension_error | If a is not square. |
| singular_matrix_error | If a is singular. |
Definition at line 1546 of file decomposition.hpp.
| least_squares_solution< T > numerical::least_squares | ( | const matrix< T > & | a, |
| const matrix< T > & | b, | ||
| rank_cutoff | cutoff = {} |
||
| ) |
lstsq, with the residuals, the rank and the singular values numpy.linalg.lstsq returns beside the solution: the residual sums of squares are given only where the solution is unique and need not be exact, A tall (m > n) and of full column rank, as NumPy gives them.
| [in] | a | The m × n matrix. |
| [in] | b | The right-hand sides (m × k). |
| [in] | cutoff | Where a singular value counts as zero, in the solution and the rank. |
| dimension_error | If b's rows differ from a's. |
| non_finite_error | If an entry of a is infinite or NaN. |
Definition at line 6607 of file decomposition.hpp.
Keeps double matrix products on most or a more portable path: the most capable path at or below it that can run here. gemm_path::amx restores the best one; gemm_path::portable keeps them on the compiler's own vectors, with no instruction chosen at run time. Paths below the cap are not probed.
count values evenly spaced from start to stop, both included, as NumPy's linspace: element i is start + i·step with step = (stop − start) / (count − 1), and the last is stop exactly.
Definition at line 884 of file tensor_ops.hpp.
| matrix< T > numerical::lstsq | ( | const matrix< T > & | a, |
| const matrix< T > & | b, | ||
| rank_cutoff | cutoff = {} |
||
| ) |
The minimum-norm least-squares solution of A X ≈ B for every column of B at once, as numpy.linalg.lstsq with a matrix right-hand side: one SVD of A, X = V Σ⁺ Uᴴ B; or, where a bound on the condition number shows the rank full with room to spare, the same solution to rounding by one QR factorisation (detail::lstsq_by_qr).
| T | The scalar element type (double or std::complex<double>). |
| [in] | a | The m × n matrix. |
| [in] | b | The right-hand sides (m × k). |
| [in] | cutoff | Where a singular value counts as zero. |
X (n × k). | dimension_error | If b's row count differs from a's. |
| non_finite_error | If an entry of a is infinite or NaN. |
Definition at line 6487 of file decomposition.hpp.
| vector< T > numerical::lstsq | ( | const matrix< T > & | a, |
| const vector< T > & | b, | ||
| rank_cutoff | cutoff = {} |
||
| ) |
The minimum-norm least-squares solution of A x ≈ b, as NumPy's lstsq gives it.
| T | The scalar element type (double or std::complex<double>). |
From the SVD of A: x = V Σ⁺ Uᴴ b, where a singular value at or under cutoff (by default NumPy's, rank_cutoff) counts as zero. Any shape, any rank: an overdetermined full-rank system gives its least-squares solution, an underdetermined or rank-deficient one the solution of smallest norm.
| [in] | a | The m × n matrix. |
| [in] | b | The right-hand side (size m). |
| [in] | cutoff | Where a singular value counts as zero. |
x (size n). | dimension_error | If b's size differs from the row count. |
| non_finite_error | If an entry of a is infinite or NaN. |
Definition at line 6465 of file decomposition.hpp.
| auto numerical::map | ( | const tensor< T > & | t, |
| const F & | f | ||
| ) | -> tensor<std::decay_t<decltype(f(std::declval<const T&>()))>> |
f(x) for every element, in a tensor of the same shape and of f's result type.
Definition at line 689 of file tensor_ops.hpp.
The matrix product of two tensors, as NumPy's matmul: each operand a stack of matrices along its leading axes, those axes broadcast against the other's (aligned from the right, an extent of 1 repeated), one product per matrix of the broadcast stack through the packed kernel, the products in parallel. A vector first is a row (its axis absent from the result), a vector second a column (likewise); two vectors give their dot product, of rank 0. The broadcast operands are not copied: a repeated matrix is read where it is.
| [in] | a,b | The operands, of rank 1 or more. |
a @ b, of the broadcast leading axes, then the rows of a and the columns of b. | dimension_error | If an operand is of rank 0, the inner extents differ, or the leading axes do not broadcast. |
Definition at line 1332 of file tensor.hpp.
| std::size_t numerical::matrix_rank | ( | const matrix< T > & | a, |
| rank_cutoff | cutoff = {}, |
||
| bool | hermitian = false |
||
| ) |
The numerical rank of a, as numpy.linalg.matrix_rank counts it: its singular values above cutoff.
| [in] | a | The matrix. |
| [in] | cutoff | Where a singular value counts as zero; by default NumPy's (rank_cutoff). |
| [in] | hermitian | Whether a is real symmetric or complex Hermitian, as NumPy's hermitian=True: its singular values are then the magnitudes of its eigenvalues, cheaper to find (in double, real or complex; any other scalar takes its singular values), and only its lower triangle is read. |
| dimension_error | If hermitian and a is not square. |
| non_finite_error | If an entry read is infinite or NaN. |
Definition at line 6789 of file decomposition.hpp.
The largest element (a NaN, if there is one).
| dimension_error | If t is empty. |
Definition at line 767 of file tensor_ops.hpp.
| tensor< T > numerical::max | ( | const tensor< T > & | t, |
| std::size_t | axis | ||
| ) |
The largest elements along axis.
| dimension_error | If axis is not an axis or is empty. |
Definition at line 781 of file tensor_ops.hpp.
|
inlineprivate |
The threads a kernel may use: the cap if one is set, else the hardware threads (starting none).
Definition at line 732 of file parallel.hpp.
The mean of every element. An empty tensor's mean is NaN, as NumPy's (which also warns).
Definition at line 746 of file tensor_ops.hpp.
The means along axis.
| dimension_error | If axis is not an axis. |
Definition at line 753 of file tensor_ops.hpp.
The smallest element (a NaN, if there is one).
| dimension_error | If t is empty. |
Definition at line 774 of file tensor_ops.hpp.
| tensor< T > numerical::min | ( | const tensor< T > & | t, |
| std::size_t | axis | ||
| ) |
The smallest elements along axis.
| dimension_error | If axis is not an axis or is empty. |
Definition at line 789 of file tensor_ops.hpp.
| tensor< C > numerical::numpy_divide | ( | const tensor< C > & | a, |
| const tensor< C > & | b | ||
| ) |
a / b of complex tensors, broadcast, each quotient as NumPy's array loop computes it (detail::numpy_divide on this processor): the binding's /.
Definition at line 638 of file tensor_ops.hpp.
| tensor< C > numerical::numpy_multiply | ( | const tensor< C > & | a, |
| const tensor< C > & | b | ||
| ) |
a · b of complex tensors, broadcast, each product as NumPy's array loop computes it (detail::numpy_multiply on this processor): the binding's *, where std::complex's operator (this library's *) recovers infinities NumPy's makes NaN.
Definition at line 628 of file tensor_ops.hpp.
A tensor of shape full of ones.
Definition at line 835 of file tensor_ops.hpp.
Matrix–matrix product.
| dimension_error | If shapes mismatch. |
Definition at line 225 of file matrix.hpp.
Matrix–vector product: each element its row's dot product with v (detail::matrix_times_vector).
| dimension_error | If shapes mismatch. |
Definition at line 207 of file matrix.hpp.
Matrix times scalar.
| [in] | m,scalar | Operands. |
Definition at line 198 of file matrix.hpp.
Scalar times matrix.
| [in] | scalar,m | Operands. |
Definition at line 187 of file matrix.hpp.
Scalar times vector.
| [in] | scalar,v | Operands. |
Definition at line 171 of file vector.hpp.
Element-wise product, broadcast.
| dimension_error | If the shapes do not broadcast. |
Definition at line 663 of file tensor_ops.hpp.
Vector times scalar.
| [in] | v,scalar | Operands. |
Definition at line 182 of file vector.hpp.
Element-wise sum.
| dimension_error | If the shapes differ. |
Definition at line 161 of file matrix.hpp.
Element-wise sum, broadcast.
| dimension_error | If the shapes do not broadcast. |
Definition at line 647 of file tensor_ops.hpp.
Element-wise sum.
| dimension_error | If the sizes differ. |
Definition at line 145 of file vector.hpp.
Element-wise difference.
| dimension_error | If the shapes differ. |
Definition at line 174 of file matrix.hpp.
Element-wise negation.
Definition at line 679 of file tensor_ops.hpp.
Element-wise difference, broadcast.
| dimension_error | If the shapes do not broadcast. |
Definition at line 655 of file tensor_ops.hpp.
Element-wise difference.
| dimension_error | If the sizes differ. |
Definition at line 158 of file vector.hpp.
Element-wise quotient, broadcast.
| dimension_error | If the shapes do not broadcast. |
Definition at line 671 of file tensor_ops.hpp.
| matrix< T > numerical::pinv | ( | const matrix< T > & | a, |
| rank_cutoff | cutoff = {}, |
||
| bool | hermitian = false |
||
| ) |
The Moore–Penrose pseudo-inverse of the m × n a (n × m), as numpy.linalg.pinv gives it: V Σ⁺ Uᴴ, a singular value at or under cutoff counting as zero.
| [in] | a | The matrix. |
| [in] | cutoff | Where a singular value counts as zero; by default NumPy's (rank_cutoff). |
| [in] | hermitian | Whether a is real symmetric or complex Hermitian, as NumPy's hermitian=True: from its eigendecomposition V Λ Vᴴ, V Λ⁺ Vᴴ, cheaper (in double, real or complex; any other scalar takes its singular value decomposition), and only its lower triangle is read. |
| dimension_error | If hermitian and a is not square. |
| non_finite_error | If an entry read is infinite or NaN. |
Definition at line 6815 of file decomposition.hpp.
a to the power b element by element, broadcast, as std::pow; a single exponent of 2, 0.5 or -1 is computed as NumPy computes it, x·x, sqrt(x) or 1/x (exact where pow rounds: a complex square has no stray real part).
Definition at line 704 of file tensor_ops.hpp.
QR-factorises an m × n matrix.
Definition at line 2667 of file decomposition.hpp.
The same elements in the same order under another shape.
| dimension_error | If the shapes hold different counts of elements. |
Definition at line 800 of file tensor_ops.hpp.
|
inlineprivatenoexcept |
Caps the threads a kernel uses at threads, the caller's included (1: none beside it, and no thread is started); 0 lifts the cap. For a process that runs several kernels side by side (one per worker process, say), so that together they do not ask for more threads than the machine has.
Definition at line 726 of file parallel.hpp.
The singular values of a, descending, without its singular vectors, as numpy.linalg.svd(a, compute_uv=False): the Householder R of a tall A (of Aᴴ when wide), its Golub–Kahan bidiagonal and the implicit-shift QR iteration on it, no basis formed nor rotated. Each value to an absolute accuracy of the largest times the machine epsilon, as svd_decomposition's.
| non_finite_error | If an entry of a is infinite or NaN. |
| convergence_error | If the iteration does not converge within its bound (not observed). |
Definition at line 6511 of file decomposition.hpp.
Solves A X = B for a square A and every column of B at once, as numpy.linalg.solve with a matrix right-hand side: one factorisation of A, then one substitution per column.
| [in] | a | The square coefficient matrix (n × n). |
| [in] | b | The right-hand sides (n × k). |
X (n × k). | dimension_error | If a is not square or b's row count differs from it. |
| singular_matrix_error | If a is singular. |
Definition at line 1525 of file decomposition.hpp.
Solves the linear system A x = b for a square A.
| [in] | a | The square coefficient matrix. |
| [in] | b | The right-hand side. |
x. | dimension_error | If a is not square or b's size differs from it. |
| singular_matrix_error | If a is singular. |
Definition at line 1509 of file decomposition.hpp.
The sum of every element, by pairwise halving (0 for an empty tensor).
Definition at line 726 of file tensor_ops.hpp.
The sums along axis, by pairwise halving.
| dimension_error | If axis is not an axis. |
Definition at line 733 of file tensor_ops.hpp.
The eigenvalues of the real symmetric or complex Hermitian a, ascending, without its eigenvectors, as numpy.linalg.eigvalsh: its Householder tridiagonal (no basis formed) and the implicit QL iteration on it, no rotation kept. Only the lower triangle is read, and of the diagonal its real part. Each value to an absolute accuracy of the largest magnitude times the machine epsilon, as symmetric_eigen's.
| dimension_error | If a is not square. |
| non_finite_error | If an entry read is infinite or NaN. |
| convergence_error | If the iteration does not converge within its bound (not observed). |
Definition at line 6549 of file decomposition.hpp.
The transpose, by blocks of transpose_tile, the result's blocks of rows shared among the threads.
| [in] | m | The matrix. |
cols×rows matrix. Definition at line 250 of file matrix.hpp.
A tensor of shape full of zeros.
Definition at line 828 of file tensor_ops.hpp.
|
inlineconstexpr |
The square blocks transpose copies one at a time: a block's rows of the source and of the result both stay in the L1 cache, where a row of the result walked a column of the source a stride apart.
Definition at line 243 of file matrix.hpp.