Class Linalg

java.lang.Object
ai.beestream.jitnn.Linalg

public final class Linalg extends Object
Linear algebra on matrices and batches of matrices [..., rows, cols], after torch.linalg: LU, triangular and general solves, inverse, determinants, Cholesky, QR, symmetric eigendecomposition and SVD. Every function is differentiable with PyTorch's formulas.

The decompositions run one work-group per matrix (see LinalgKernels), so they serve batches of small and medium matrices (up to a few hundred rows), the sizes found inside models. Eigenvectors and singular vectors are only defined up to sign; jitNN makes the largest-magnitude component of each eigenvector, and of each left singular vector, positive. General (non-symmetric) eigendecomposition is not provided: it needs complex numbers.

  • Method Summary

    Modifier and Type
    Method
    Description
    static Tensor
    Lower Cholesky factor L, A = L L^T, of symmetric positive-definite matrices (only the lower triangle is read).
    static Tensor
    Determinants [...] of square matrices.
    static Tensor[]
    Eigenvalues (ascending) [..., n] and eigenvectors (columns) [..., n, n] of symmetric matrices, torch.linalg.eigh.
    static Tensor
    Eigenvalues (ascending) of symmetric matrices, torch.linalg.eigvalsh.
    static Tensor
    Inverse of square matrices.
    static Tensor[]
    P, L, U with A = P L U, torch.linalg.lu for square matrices.
    static Tensor[]
    LU factorisation with partial pivoting, torch.linalg.lu_factor: the packed factors (L unit lower below the diagonal, U on and above) and INT32 row indices perm, with row i of P^T A being row perm[i] of A (0-based, unlike LAPACK's swap list).
    static Tensor[]
    Reduced QR, torch.linalg.qr: Q [..., m, k] and R [..., k, n], k = min(m, n).
    static Tensor[]
    torch.linalg.slogdet: [sign, log |det|], each [...]; only the logarithm carries a gradient.
    static Tensor
    Solves A X = B for square A [..., n, n] and B [..., n, k] through LU with partial pivoting.
    static Tensor
    solveTriangular(Tensor t, Tensor b, boolean upper, boolean unitDiagonal)
    Solves T X = B for triangular T, torch.linalg.solve_triangular (left side): only T's upper or lower triangle is read, and with unitDiagonal not its diagonal either.
    static Tensor[]
    Reduced SVD, torch.linalg.svd(full_matrices=False): U [..., m, k], S [..., k] descending and V [..., n, k] (V, not V^T), k = min(m, n).
    static Tensor
    Singular values (descending), torch.linalg.svdvals.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • luFactor

      public static Tensor[] luFactor(Tensor a)
      LU factorisation with partial pivoting, torch.linalg.lu_factor: the packed factors (L unit lower below the diagonal, U on and above) and INT32 row indices perm, with row i of P^T A being row perm[i] of A (0-based, unlike LAPACK's swap list).
    • lu

      public static Tensor[] lu(Tensor a)
      P, L, U with A = P L U, torch.linalg.lu for square matrices.
    • solveTriangular

      public static Tensor solveTriangular(Tensor t, Tensor b, boolean upper, boolean unitDiagonal)
      Solves T X = B for triangular T, torch.linalg.solve_triangular (left side): only T's upper or lower triangle is read, and with unitDiagonal not its diagonal either.
    • solve

      public static Tensor solve(Tensor a, Tensor b)
      Solves A X = B for square A [..., n, n] and B [..., n, k] through LU with partial pivoting.
    • inv

      public static Tensor inv(Tensor a)
      Inverse of square matrices.
    • det

      public static Tensor det(Tensor a)
      Determinants [...] of square matrices.
    • slogdet

      public static Tensor[] slogdet(Tensor a)
      torch.linalg.slogdet: [sign, log |det|], each [...]; only the logarithm carries a gradient.
    • cholesky

      public static Tensor cholesky(Tensor a)
      Lower Cholesky factor L, A = L L^T, of symmetric positive-definite matrices (only the lower triangle is read).
    • qr

      public static Tensor[] qr(Tensor a)
      Reduced QR, torch.linalg.qr: Q [..., m, k] and R [..., k, n], k = min(m, n).
    • eigh

      public static Tensor[] eigh(Tensor a)
      Eigenvalues (ascending) [..., n] and eigenvectors (columns) [..., n, n] of symmetric matrices, torch.linalg.eigh. The whole matrix is read, so it should be symmetric.
    • eigvalsh

      public static Tensor eigvalsh(Tensor a)
      Eigenvalues (ascending) of symmetric matrices, torch.linalg.eigvalsh.
    • svd

      public static Tensor[] svd(Tensor a)
      Reduced SVD, torch.linalg.svd(full_matrices=False): U [..., m, k], S [..., k] descending and V [..., n, k] (V, not V^T), k = min(m, n).
    • svdvals

      public static Tensor svdvals(Tensor a)
      Singular values (descending), torch.linalg.svdvals.