Skip to main content

Module linalg

Module linalg 

Source
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 by lower is 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 (geqrf and orgqr): Householder reflectors with LAPACK’s larfg convention (beta = -sign(alpha) * norm), so the signs of Q and of the diagonal of R match LAPACK’s;
  • eigh (syevd): eigenvalues in ascending order, only the triangle given by lower read;
  • 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§

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

Traits§

LinalgFloat
The real element types of linear algebra: f32 and f64.
LinalgScalar
The element types of linear algebra: f32, f64, c64, and c128.

Functions§

cholesky
The Cholesky factorization A = L L^H of each n x n matrix of a batch of batch matrices, reading the lower triangle (LAPACK’s potrf with uplo = 'L'; only the real part of the diagonal is read).
cholesky_update
The rank-1 update of each Cholesky factor ([batch, n, n], upper triangular r with a = r^T r) by the vector w ([batch, n]): the upper triangular factor of a + w w^T, as JAX’s cholesky_update_p computes it on CPU (_cholesky_update_jax_fn): for each k, the Givens rotation of drotg(r[k, k], w[k]) applied to the row r[k, :] and w.
eig
The eigendecomposition of each n x n matrix of a batch (LAPACK’s geev; see the module’s description): the complex eigenvalues (n per matrix), and, if requested, the left eigenvectors (u^H a = w u^H) and the right eigenvectors (a v = w v), one per column of n x n complex matrices (empty if not requested).
eigh
The eigendecomposition A = V diag(w) V^H of each Hermitian (symmetric for real numbers) n x n matrix of a batch, reading the triangle given by lower (LAPACK’s syevd and heevd; only the real part of the diagonal is read), by the reduction to tridiagonal form and the QL or QR algorithm (LAPACK’s syev), or with jacobi, by cyclic Jacobi rotations.
hessenberg
The reduction of each n x n matrix of a batch to upper Hessenberg form A = Q H Q^H (LAPACK’s gehrd with ilo = 1, ihi = n, as lax.linalg.hessenberg): H on and above the subdiagonal and the Householder reflectors below it, and their n - 1 factors tau.
householder_product
The first n columns of the product Q = H_0 H_1 ... H_{k-1} of the Householder reflectors stored below the diagonal of the first k columns of each m x n matrix of a batch (m >= n >= k), as LAPACK’s orgqr (ungqr) and lax.linalg.householder_product.
lu
The LU factorization with partial pivoting P A = L U of each m x n matrix of a batch (LAPACK’s getrf).
lu_pivots_to_permutation
Converts the pivots of lu (k row swaps per batch element) into permutations of size elements: starting from the identity, swaps element i with element pivots[i] for each i in order (as lax.linalg.lu_pivots_to_permutation). Pivots out of range leave the permutation unchanged at that step.
ormqr
Multiplies each rows x cols matrix c of a batch by Q (Q^H with transpose) from the left (left) or the right, where Q = H_0 ... H_{k-1} is given by the reflectors below the diagonal of the first k columns of the m x n matrix a (m = rows from the left, cols from the right) and the factors taus, without forming Q (LAPACK’s ormqr, unmqr, and lax.linalg.ormqr).
qr
The QR decomposition A = Q R of each m x n matrix of a batch, as lax.linalg.qr computes it with LAPACK’s geqrf and orgqr (ungqr for complex numbers).
qr_pivoting
The QR decomposition with column pivoting A P = Q R of each m x n matrix of a batch, as lax.linalg.qr(pivoting=True) computes it with LAPACK’s geqp3 (its unblocked laqp2): 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^H of each n x n matrix of a batch, as LAPACK’s gees (without sorting) computes it: the permutations of gebal, gehd2, orghr, the QR algorithm (lahqr), and gebak. For real matrices, T is quasi-triangular with standardized 2 x 2 blocks for the complex conjugate eigenvalues (lanv2), and Z is orthogonal; for complex matrices, T is upper triangular and Z unitary. Returns T and, with vectors, 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^H of each m x n matrix of a batch (what JAX computes with LAPACK’s gesdd), by bidiagonalization and the QR algorithm (LAPACK’s gesvd), or with jacobi, by one-sided Jacobi rotations.
symmetric_product
alpha a a^T + beta c for each a ([batch, m, n]) and c ([batch, m, m]), as JAX’s symmetric_product_p computes it on CPU (the whole matrix; on GPU, cuBLAS’s syrk gives the lower triangle).
triangular_solve
Solves op(A) X = B or X op(A) = B for each pair of a batch, where A is triangular (k x k, k = m on the left side and n on the right) and B is m x n (LAPACK’s trsm).
tridiagonal
The reduction of each Hermitian (symmetric) n x n matrix of the batch to real tridiagonal form by a unitary similarity, as LAPACK’s sytrd (hetrd for complex types; the unblocked sytd2 and hetd2, which sytrd uses for matrices smaller than its crossover, 32 by default), reading only the lower (or upper) triangle.
tridiagonal_solve
Solves A x = b for each tridiagonal A of the batch (batch systems of m equations with n right-hand sides each): dl, d, and du are [batch, m], b is [batch, m, n].

Type Aliases§

Cx
The complex type of the eigenvalues and eigenvectors of matrices of type T.