Expand description
Linear algebra on batches of row-major matrices: Cholesky, triangular solves, LU, QR, symmetric eigendecomposition, and SVD.
The results follow the conventions of the LAPACK routines that JAX calls on CPU, so that ruxla computes what JAX computes (up to rounding, since the algorithms differ in their order of operations):
cholesky(potrf): the lower factor in the lower triangle; the strictly upper triangle of the input is left as it is; a matrix that is not positive definite gives NaNs everywhere, as JAX returns;triangular_solve(trsm): only the triangle given byloweris read (and not the diagonal for a unit diagonal);lu(getrf): partial pivoting choosing the first row with the largest absolute value in the column, row swaps applied to whole rows, and the multipliers scaled by the reciprocal of the pivot;qr(geqrfandorgqr): Householder reflectors with LAPACK’slarfgconvention (beta = -sign(alpha) * norm), so the signs ofQand of the diagonal ofRmatch LAPACK’s;eigh(syevd): eigenvalues in ascending order, only the triangle given bylowerread;svd(gesdd): singular values in descending order.
Eigenvectors and singular vectors are only defined up to sign (and up to
a basis of each repeated eigenvalue), which LAPACK leaves to its
algorithm. ruxla computes the eigendecomposition as LAPACK’s syev
does (the reduction to tridiagonal form and the implicit QL or QR
algorithm, steqr), and the singular value decomposition as gesvd
does (the reduction to bidiagonal form and bdsqr; one-sided Jacobi
rotations on request), and then makes the component of largest magnitude of
each eigenvector (of each left singular vector) positive, which is
continuous in the input. Inputs with
infinities or NaNs give NaNs for eigh and svd (where LAPACK reports
an error, which JAX turns into NaNs).
Complex matrices (c64, c128) follow the conventions of the complex
LAPACK routines (zpotrf, ztrsm, zgetrf, zgeqrf and zungqr,
zheevd, zgesdd): conjugate transposes in place of transposes, the
pivots of getrf chosen by |re| + |im| (BLAS’s izamax), Householder
reflectors with zlarfg’s convention (a real beta), and real
eigenvalues and singular values. Eigenvectors and singular vectors are
defined up to a phase; ruxla makes the component of largest magnitude of
each real and positive.
Structs§
- Triangular
Solve Options - The options of
triangular_solve, as inlax.linalg.triangular_solve.
Traits§
- Linalg
Float - The real element types of linear algebra:
f32andf64. - Linalg
Scalar - The element types of linear algebra:
f32,f64,c64, andc128.
Functions§
- cholesky
- The Cholesky factorization
A = L L^Hof eachn x nmatrix of a batch ofbatchmatrices, reading the lower triangle (LAPACK’spotrfwithuplo = 'L'; only the real part of the diagonal is read). - cholesky_
update - The rank-1 update of each Cholesky factor (
[batch, n, n], upper triangularrwitha = r^T r) by the vectorw([batch, n]): the upper triangular factor ofa + w w^T, as JAX’scholesky_update_pcomputes it on CPU (_cholesky_update_jax_fn): for eachk, the Givens rotation ofdrotg(r[k, k], w[k])applied to the rowr[k, :]andw. - eig
- The eigendecomposition of each
n x nmatrix of a batch (LAPACK’sgeev; see the module’s description): the complex eigenvalues (nper matrix), and, if requested, the left eigenvectors (u^H a = w u^H) and the right eigenvectors (a v = w v), one per column ofn x ncomplex matrices (empty if not requested). - eigh
- The eigendecomposition
A = V diag(w) V^Hof each Hermitian (symmetric for real numbers)n x nmatrix of a batch, reading the triangle given bylower(LAPACK’ssyevdandheevd; only the real part of the diagonal is read), by the reduction to tridiagonal form and the QL or QR algorithm (LAPACK’ssyev), or withjacobi, by cyclic Jacobi rotations. - hessenberg
- The reduction of each
n x nmatrix of a batch to upper Hessenberg formA = Q H Q^H(LAPACK’sgehrdwithilo = 1,ihi = n, aslax.linalg.hessenberg):Hon and above the subdiagonal and the Householder reflectors below it, and theirn - 1factorstau. - householder_
product - The first
ncolumns of the productQ = H_0 H_1 ... H_{k-1}of the Householder reflectors stored below the diagonal of the firstkcolumns of eachm x nmatrix of a batch (m >= n >= k), as LAPACK’sorgqr(ungqr) andlax.linalg.householder_product. - lu
- The LU factorization with partial pivoting
P A = L Uof eachm x nmatrix of a batch (LAPACK’sgetrf). - lu_
pivots_ to_ permutation - Converts the pivots of
lu(krow swaps per batch element) into permutations ofsizeelements: starting from the identity, swaps elementiwith elementpivots[i]for eachiin order (aslax.linalg.lu_pivots_to_permutation). Pivots out of range leave the permutation unchanged at that step. - ormqr
- Multiplies each
rows x colsmatrixcof a batch byQ(Q^Hwithtranspose) from the left (left) or the right, whereQ = H_0 ... H_{k-1}is given by the reflectors below the diagonal of the firstkcolumns of them x nmatrixa(m=rowsfrom the left,colsfrom the right) and the factorstaus, without formingQ(LAPACK’sormqr,unmqr, andlax.linalg.ormqr). - qr
- The QR decomposition
A = Q Rof eachm x nmatrix of a batch, aslax.linalg.qrcomputes it with LAPACK’sgeqrfandorgqr(ungqrfor complex numbers). - qr_
pivoting - The QR decomposition with column pivoting
A P = Q Rof eachm x nmatrix of a batch, aslax.linalg.qr(pivoting=True)computes it with LAPACK’sgeqp3(its unblockedlaqp2): at each step, the column of largest remaining norm (the first one, if several) is moved forward, and the norms are downdated, or recomputed where the downdate loses accuracy. - schur
- The Schur decomposition
A = Z T Z^Hof eachn x nmatrix of a batch, as LAPACK’sgees(without sorting) computes it: the permutations ofgebal,gehd2,orghr, the QR algorithm (lahqr), andgebak. For real matrices,Tis quasi-triangular with standardized 2 x 2 blocks for the complex conjugate eigenvalues (lanv2), andZis orthogonal; for complex matrices,Tis upper triangular andZunitary. ReturnsTand, withvectors,Z(empty otherwise). Matrices with infinities or NaNs, and matrices on which the QR algorithm does not converge, give NaNs. - svd
- The singular value decomposition
A = U diag(s) V^Hof eachm x nmatrix of a batch (what JAX computes with LAPACK’sgesdd), by bidiagonalization and the QR algorithm (LAPACK’sgesvd), or withjacobi, by one-sided Jacobi rotations. - symmetric_
product alpha a a^T + beta cfor eacha([batch, m, n]) andc([batch, m, m]), as JAX’ssymmetric_product_pcomputes it on CPU (the whole matrix; on GPU, cuBLAS’ssyrkgives the lower triangle).- triangular_
solve - Solves
op(A) X = BorX op(A) = Bfor each pair of a batch, whereAis triangular (k x k,k = mon the left side andnon the right) andBism x n(LAPACK’strsm). - tridiagonal
- The reduction of each Hermitian (symmetric)
n x nmatrix of the batch to real tridiagonal form by a unitary similarity, as LAPACK’ssytrd(hetrdfor complex types; the unblockedsytd2andhetd2, whichsytrduses for matrices smaller than its crossover, 32 by default), reading only thelower(or upper) triangle. - tridiagonal_
solve - Solves
A x = bfor each tridiagonalAof the batch (batchsystems ofmequations withnright-hand sides each):dl,d, andduare[batch, m],bis[batch, m, n].
Type Aliases§
- Cx
- The complex type of the eigenvalues and eigenvectors of matrices of
type
T.