torch.Tensor.Tensor.cholesky_inverse
Tensor.cholesky_inverse(options?: CholeskyOptions): Tensor<DynamicShape, D, Dev>Tensor.cholesky_inverse(upper: boolean, options?: CholeskyOptions): Tensor<DynamicShape, D, Dev>Computes the inverse of a symmetric positive-definite matrix given its Cholesky factor.
Takes a Cholesky factor (output from cholesky()) and returns the inverse of the original matrix.
Much more efficient than computing cholesky().cholesky_inverse() separately.
Uses forward/backward substitution with the triangular factor instead of general matrix inversion.
If you have matrix A and its Cholesky factor L (where A = L L^T), this computes A^(-1) directly from L without reconstructing A first. Essential optimization for high-dimensional Gaussian problems where you need both determinants and inverses.
Use Cases:
- Inverting covariance matrices efficiently in Bayesian inference
- Computing precision matrices from Cholesky factors
- Gaussian likelihood computations (need both log-det and inverse)
- Variational inference with full-rank Gaussian posteriors
- Optimization problems with linear constraints (KKT matrices)
- Lower by default: If you used
cholesky()(default), usecholesky_inverse(false) - Upper triangular: If you used
cholesky(true), usecholesky_inverse(true) - Efficiency: O(n²) operations, much faster than O(n³) for general matrix inverse
- Symmetry: Result is symmetric (A_inv = A_inv^T)
- Batch support: Works with batched matrices (..., n, n)
- Must use Cholesky factor: Input must actually be from cholesky(), not arbitrary triangular matrix
- Positive-diagonal assumption: Assumes diagonal elements are positive (as from cholesky)
- Sign parameter matters: Must match the form used in cholesky()
Parameters
optionsCholeskyOptionsoptional
Returns
Tensor<DynamicShape, D, Dev>– Matrix A^(-1) with same shape as the Cholesky factor inputExamples
// Direct inversion from Cholesky factor
const A = torch.tensor([[4, 2], [2, 3]]);
const L = A.cholesky(); // Lower triangular factor
const A_inv = L.cholesky_inverse(); // Compute inverse from L
// Verify: A @ A_inv ≈ I
// Gaussian likelihood with efficient computation
const Sigma = torch.eye(100); // 100x100 covariance
const x = torch.randn(100);
// Decompose once, reuse for both logdet and solve
const L = Sigma.cholesky();
// Compute inverse
const Sigma_inv = L.cholesky_inverse();
// Log-determinant
const logdet = 2 * L.diagonal().log().sum();
// Mahalanobis distance: x^T Sigma^(-1) x
const mahal = x.matmul(Sigma_inv).matmul(x);
// Gaussian PDF: exp(-0.5 * mahal) / sqrt((2π)^n |Sigma|)
const logprob = -0.5 * mahal - 0.5 * logdet - 0.5 * 100 * Math.log(2 * Math.PI);
// Upper triangular form
const U = A.cholesky(true); // Upper: A = U^T U
const A_inv_upper = U.cholesky_inverse(true);See Also
- PyTorch torch.cholesky_inverse() (or tensor.cholesky_inverse())
- cholesky - Compute Cholesky factor
- cholesky_solve - Solve A x = b using Cholesky factor
- inverse - General matrix inverse (slower, works for any invertible matrix)
- lu - LU decomposition alternative