torch.Tensor.Tensor.cholesky_solve
Tensor.cholesky_solve(u: Tensor, options?: CholeskyOptions): Tensor<DynamicShape, D, Dev>Tensor.cholesky_solve(u: Tensor, upper: boolean, options?: CholeskyOptions): Tensor<DynamicShape, D, Dev>Solves a linear system using a Cholesky factor (numerically stable and efficient).
Given a Cholesky factor from a symmetric positive-definite matrix A, efficiently solves A X = B for X. Much faster than solving the system directly because it uses the triangular structure. If you have A = L L^T and want to solve A X = B, this does the computation with two triangular solves instead of general inversion.
Commonly used pattern: (1) factor A = L L^T via cholesky(), (2) solve for multiple right-hand sides using cholesky_solve(). One factorization, multiple solves = efficient computation.
Use Cases:
- Solving Gaussian process regression (many RHS with same covariance)
- Variational inference with GP priors
- Bayesian optimization and uncertainty quantification
- Solving normal equations in constrained optimization
- Multiple right-hand side problems where factorization is expensive
- Input shapes: self (B) shape (..., n, k) and u shape (..., n, n)
- Output shape: Same as self (B), containing solution(s)
- Efficiency: O(n²k) for k right-hand sides, much faster than O(n³k) for general solve
- Stability: Very numerically stable due to triangular structure
- Lower form: Default assumes u from cholesky() (lower triangular)
- Batch support: Works with batched (..., n, n) and (..., n, k) tensors
- Must be Cholesky factor: u must be from cholesky(), not arbitrary triangular
- Match factorization: If you used cholesky(true), must use cholesky_solve(..., true)
- A must be SPD: Original A must have been symmetric positive-definite
Parameters
uTensor- The Cholesky factor (lower triangular L from A = L L^T, or upper U from A = U^T U)
optionsCholeskyOptionsoptional
Returns
Tensor<DynamicShape, D, Dev>– Solution X where A X = self (self is the B in A X = B)Examples
// Solve a linear system using Cholesky
const A = torch.tensor([[4, 2], [2, 3]]);
const B = torch.ones(2);
const L = A.cholesky(); // Factor: A = L L^T
const X = B.cholesky_solve(L); // Solve A X = B
// Verify: A @ X ≈ B
// Gaussian process regression: solve (K + λI) α = y
const K = torch.randn(100, 100);
const K_reg = K.add(torch.eye(100).mul(1e-6)); // Add regularization
const y = torch.randn(100);
const L = K_reg.cholesky();
const alpha = y.cholesky_solve(L); // Efficient solve
// Multiple right-hand sides with same A
const A = torch.tensor([[4, 2], [2, 3]]);
const B = torch.randn(2, 5); // 5 right-hand side vectors
const L = A.cholesky(); // Factor once
const X = B.cholesky_solve(L); // Solve for all 5 RHS with one factorization
// Optimal experimental design: solve covariance equations
const Sigma = torch.eye(50); // Information matrix
const L = Sigma.cholesky();
const gradients = torch.randn(50);
const fisher_direction = gradients.cholesky_solve(L);
// Upper triangular form
const U = A.cholesky(true); // Upper: A = U^T U
const X_upper = B.cholesky_solve(U, true);See Also
- PyTorch torch.cholesky_solve() (or tensor.cholesky_solve())
- cholesky - Compute Cholesky factor
- cholesky_inverse - Compute A^(-1) from Cholesky factor
- solve - General matrix solver (works for any invertible matrix)
- lu - LU decomposition for general solves