Skip to main content

Module linalg

Module linalg 

Source
Expand description

Linear algebra following jax.lax.linalg: decompositions of batches of matrices ([..., m, n], batch dimensions first) of f32, f64, c64, or c128. For complex matrices, transposes are conjugate transposes (cholesky gives x = l l^H, eigh takes Hermitian matrices and gives real eigenvalues, and svd gives real singular values and vt = v^H), and eigenvectors and singular vectors are defined up to a phase rather than a sign.

The functions bind the primitives as JAX’s do (with the same symmetrization and masking around them), so traced programs have JAX’s jaxprs. On the native backend they run the kernels of ruxla_kernels::linalg; compiled by XLA, ruxla’s FFI handlers (or, in JAX, the LAPACK and cuSOLVER calls JAX itself makes).

Structs§

TriangularSolveOptions
The options of triangular_solve, as in lax.linalg.triangular_solve.

Enums§

EighImplementation
The algorithm of eigh (JAX’s EighImplementation).
SvdAlgorithm
The algorithm of svd (JAX’s SvdAlgorithm).

Functions§

cholesky
The Cholesky factor L of each symmetric positive definite matrix (x = L L^T, L lower triangular), as lax.linalg.cholesky.
cholesky_update
The rank-1 update of a Cholesky factorization, as lax.linalg.cholesky_update: given the upper triangular r of a = r^T r and the vector w, the upper triangular factor of a + w w^T in O(n^2) (by Givens rotations, as JAX computes it on CPU; the diagonal may come out negative). Real matrices only, not differentiable, as in JAX.
eig
The eigendecomposition of each general (nonsymmetric) square matrix, as lax.linalg.eig: the complex eigenvalues w, and, if requested, the left eigenvectors (u^H x = w u^H) and the right eigenvectors (x v = w v), one per column, with unit norm and the component of largest magnitude real, as LAPACK’s geev gives them (the eigenvalues in the order of LAPACK’s Schur form; see ruxla_kernels::linalg::eig).
eigh
The eigendecomposition of each symmetric (Hermitian) matrix, as lax.linalg.eigh: the eigenvectors v (one per column) and the real eigenvalues w in ascending order, with x = v diag(w) v^H.
hessenberg
The reduction of each square matrix to upper Hessenberg form x = q h q^H, as lax.linalg.hessenberg (LAPACK’s gehrd): h on and above the subdiagonal with the Householder reflectors of q below it, and their n - 1 factors (for householder_product and ormqr). Not differentiable, as in JAX.
householder_product
The first n columns of the product of the Householder reflectors below the diagonal of a ([..., m, n], m >= n) with the factors taus ([..., k]), as lax.linalg.householder_product (LAPACK’s orgqr). Not differentiable, as in JAX.
lu
The LU factorization with partial pivoting of each matrix, as lax.linalg.lu: the factors (L below the diagonal, with an implicit unit diagonal, and U), the pivots (i32[..., min(m, n)]: row i was swapped with row pivots[i]), and the permutation (i32[..., m]), with a[perm] = L U.
lu_pivots_to_permutation
Converts the pivots of lu to a permutation of permutation_size elements, as lax.linalg.lu_pivots_to_permutation.
ormqr
q c, q^H c (transpose), c q, or c q^H (not left), where q is the product of the Householder reflectors of a with the factors taus, without forming q, as lax.linalg.ormqr (LAPACK’s ormqr). Not differentiable, as in JAX.
qdwh
The polar decomposition x = u h of a full-rank matrix (m x n with m >= n) by the QR-based dynamically weighted Halley iteration, as lax.linalg.qdwh: (u, h, num_iters, is_converged) with u (m x n) having orthonormal columns and h (n x n) Hermitian positive semidefinite. The iteration follows JAX’s (jax._src.tpu.linalg.qdwh): the scaling by 1 / sqrt(|x|_1 |x|_inf), the weights of the steps computed in advance from the lower bound eps of the smallest singular value (QR steps while c > 100, then Cholesky steps), Halley’s steps until |u_k - u_{k-1}|_F <= (5 eps)^(1/3) within max_iterations (10 by default), and a Newton-Schulz refinement. eps defaults to the machine epsilon of T. With dynamic_shape (m, n), x is a matrix padded from its true shape m x n (which may be traced values), as in JAX: the entries outside are taken as zeros and stay zeros. (JAX’s unused is_hermitian is left out.)
qr
The QR decomposition of each matrix, as lax.linalg.qr: q with orthonormal columns and an upper triangular r (x = q r), with the signs of LAPACK’s Householder reflectors. With full_matrices, q is [..., m, m] and r is [..., m, n]; otherwise [..., m, k] and [..., k, n] for k = min(m, n).
qr_pivoting
The QR decomposition with column pivoting of each matrix, as lax.linalg.qr(x, pivoting=True): (q, r, p) with x[..., p] = q r, where the permutation p (i32[..., n]) moves the columns of largest remaining norm forward, as LAPACK’s geqp3, so that the magnitudes of the diagonal of r do not increase (rank-revealing). The shapes of q and r are those of qr.
schur
The Schur decomposition x = z t z^H of each square matrix, as lax.linalg.schur (LAPACK’s gees, without sorting): t, upper quasi-triangular for real matrices (with standardized 2 x 2 blocks for the complex conjugate eigenvalues) and upper triangular for complex ones, and, with compute_schur_vectors, the orthogonal (unitary) z. Not differentiable, as in JAX.
svd
The singular value decomposition of each matrix, as lax.linalg.svd: (u, s, vt) with the real singular values s in descending order and x = u diag(s) vt. With full_matrices, u is [..., m, m] and vt is [..., n, n]; otherwise [..., m, k] and [..., k, n] for k = min(m, n). The signs (phases) make the component of largest magnitude of each column of u real and positive.
svd_values
The singular values of each matrix in descending order (lax.linalg.svd with compute_uv=False), only those of indices start..end with subset_by_index (differentiable), by algorithm (as in svd).
symmetric_product
alpha a a^T + beta c for each a ([..., m, n]) and symmetric c ([..., m, m]), as lax.linalg.symmetric_product (with symmetrize_output, the upper triangle is replaced by the transpose of the lower one; JAX guarantees only the lower triangle otherwise, which cuBLAS’s syrk computes on GPU). Real matrices only, not differentiable, as in JAX.
triangular_solve
Solves op(a) x = b (left_side) or x op(a) = b for x, where a is triangular, as lax.linalg.triangular_solve (whose defaults are those of TriangularSolveOptions::default). Only the triangle of a given by lower is read, without the diagonal for unit_diagonal.
tridiagonal
The reduction of each Hermitian (symmetric) matrix to real tridiagonal form by a unitary similarity, as lax.linalg.tridiagonal, reading only the lower (or upper) triangle: (a, d, e, taus) with the diagonal d and the off-diagonal e (real), and in that triangle of a the tridiagonal form and the Householder reflectors (with the factors taus) below (above) the off-diagonal; the other triangle is that of the input. Not differentiable, as in JAX.
tridiagonal_solve
The solution x of A x = b for each tridiagonal matrix A, as lax.linalg.tridiagonal_solve: dl[..., i] = A[i, i - 1] (dl[..., 0] is ignored), d[..., i] = A[i, i], and du[..., i] = A[i, i + 1] (du[..., m - 1] is ignored), each [..., m], and b is [..., m, n]. Gaussian elimination with partial pivoting (LAPACK’s gtsv): singular systems give NaNs, unless perturb_singular, which perturbs tiny pivots so that numerically singular systems (as in inverse iteration) give finite solutions. Differentiable in all inputs.

Type Aliases§

Svd
The singular value decomposition (u, s, vt) of svd, with real singular values s.