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§
- Triangular
Solve Options - The options of
triangular_solve, as inlax.linalg.triangular_solve.
Enums§
- Eigh
Implementation - The algorithm of
eigh(JAX’sEighImplementation). - SvdAlgorithm
- The algorithm of
svd(JAX’sSvdAlgorithm).
Functions§
- cholesky
- The Cholesky factor
Lof each symmetric positive definite matrix (x = L L^T,Llower triangular), aslax.linalg.cholesky. - cholesky_
update - The rank-1 update of a Cholesky factorization, as
lax.linalg.cholesky_update: given the upper triangularrofa = r^T rand the vectorw, the upper triangular factor ofa + w w^TinO(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 eigenvaluesw, 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’sgeevgives them (the eigenvalues in the order of LAPACK’s Schur form; seeruxla_kernels::linalg::eig). - eigh
- The eigendecomposition of each symmetric (Hermitian) matrix, as
lax.linalg.eigh: the eigenvectorsv(one per column) and the real eigenvalueswin ascending order, withx = v diag(w) v^H. - hessenberg
- The reduction of each square matrix to upper Hessenberg form
x = q h q^H, aslax.linalg.hessenberg(LAPACK’sgehrd):hon and above the subdiagonal with the Householder reflectors ofqbelow it, and theirn - 1factors (forhouseholder_productandormqr). Not differentiable, as in JAX. - householder_
product - The first
ncolumns of the product of the Householder reflectors below the diagonal ofa([..., m, n],m >= n) with the factorstaus([..., k]), aslax.linalg.householder_product(LAPACK’sorgqr). Not differentiable, as in JAX. - lu
- The LU factorization with partial pivoting of each matrix, as
lax.linalg.lu: the factors (Lbelow the diagonal, with an implicit unit diagonal, andU), the pivots (i32[..., min(m, n)]: rowiwas swapped with rowpivots[i]), and the permutation (i32[..., m]), witha[perm] = L U. - lu_
pivots_ to_ permutation - Converts the pivots of
luto a permutation ofpermutation_sizeelements, aslax.linalg.lu_pivots_to_permutation. - ormqr
q c,q^H c(transpose),c q, orc q^H(notleft), whereqis the product of the Householder reflectors ofawith the factorstaus, without formingq, aslax.linalg.ormqr(LAPACK’sormqr). Not differentiable, as in JAX.- qdwh
- The polar decomposition
x = u hof a full-rank matrix (m x nwithm >= n) by the QR-based dynamically weighted Halley iteration, aslax.linalg.qdwh:(u, h, num_iters, is_converged)withu(m x n) having orthonormal columns andh(n x n) Hermitian positive semidefinite. The iteration follows JAX’s (jax._src.tpu.linalg.qdwh): the scaling by1 / sqrt(|x|_1 |x|_inf), the weights of the steps computed in advance from the lower boundepsof the smallest singular value (QR steps whilec > 100, then Cholesky steps), Halley’s steps until|u_k - u_{k-1}|_F <= (5 eps)^(1/3)withinmax_iterations(10 by default), and a Newton-Schulz refinement.epsdefaults to the machine epsilon ofT. Withdynamic_shape(m, n),xis a matrix padded from its true shapem x n(which may be traced values), as in JAX: the entries outside are taken as zeros and stay zeros. (JAX’s unusedis_hermitianis left out.) - qr
- The QR decomposition of each matrix, as
lax.linalg.qr:qwith orthonormal columns and an upper triangularr(x = q r), with the signs of LAPACK’s Householder reflectors. Withfull_matrices,qis[..., m, m]andris[..., m, n]; otherwise[..., m, k]and[..., k, n]fork = min(m, n). - qr_
pivoting - The QR decomposition with column pivoting of each matrix, as
lax.linalg.qr(x, pivoting=True):(q, r, p)withx[..., p] = q r, where the permutationp(i32[..., n]) moves the columns of largest remaining norm forward, as LAPACK’sgeqp3, so that the magnitudes of the diagonal ofrdo not increase (rank-revealing). The shapes ofqandrare those ofqr. - schur
- The Schur decomposition
x = z t z^Hof each square matrix, aslax.linalg.schur(LAPACK’sgees, 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, withcompute_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 valuessin descending order andx = u diag(s) vt. Withfull_matrices,uis[..., m, m]andvtis[..., n, n]; otherwise[..., m, k]and[..., k, n]fork = min(m, n). The signs (phases) make the component of largest magnitude of each column ofureal and positive. - svd_
values - The singular values of each matrix in descending order
(
lax.linalg.svdwithcompute_uv=False), only those of indicesstart..endwithsubset_by_index(differentiable), byalgorithm(as insvd). - symmetric_
product alpha a a^T + beta cfor eacha([..., m, n]) and symmetricc([..., m, m]), aslax.linalg.symmetric_product(withsymmetrize_output, the upper triangle is replaced by the transpose of the lower one; JAX guarantees only the lower triangle otherwise, which cuBLAS’ssyrkcomputes on GPU). Real matrices only, not differentiable, as in JAX.- triangular_
solve - Solves
op(a) x = b(left_side) orx op(a) = bforx, whereais triangular, aslax.linalg.triangular_solve(whose defaults are those ofTriangularSolveOptions::default). Only the triangle ofagiven byloweris read, without the diagonal forunit_diagonal. - tridiagonal
- The reduction of each Hermitian (symmetric) matrix to real tridiagonal
form by a unitary similarity, as
lax.linalg.tridiagonal, reading only thelower(or upper) triangle:(a, d, e, taus)with the diagonaldand the off-diagonale(real), and in that triangle ofathe tridiagonal form and the Householder reflectors (with the factorstaus) below (above) the off-diagonal; the other triangle is that of the input. Not differentiable, as in JAX. - tridiagonal_
solve - The solution
xofA x = bfor each tridiagonal matrixA, aslax.linalg.tridiagonal_solve:dl[..., i] = A[i, i - 1](dl[..., 0]is ignored),d[..., i] = A[i, i], anddu[..., i] = A[i, i + 1](du[..., m - 1]is ignored), each[..., m], andbis[..., m, n]. Gaussian elimination with partial pivoting (LAPACK’sgtsv): singular systems give NaNs, unlessperturb_singular, which perturbs tiny pivots so that numerically singular systems (as in inverse iteration) give finite solutions. Differentiable in all inputs.