- torch.cholesky_solve(input, input2, upper=False, *, out=None) Tensor ¶
Solves a linear system of equations with a positive semidefinite matrix to be inverted given its Cholesky factor matrix .
False, is and lower triangular and c is returned such that:
Trueor not provided, is upper triangular and c is returned such that:
torch.cholesky_solve(b, u) can take in 2D inputs b, u or inputs that are batches of 2D matrices. If the inputs are batches, then returns batched outputs c
Supports real-valued and complex-valued inputs. For the complex-valued inputs the transpose operator above is the conjugate transpose.
input (Tensor) – input matrix of size , where is zero or more batch dimensions
input2 (Tensor) – input matrix of size , where is zero of more batch dimensions composed of upper or lower triangular Cholesky factor
upper (bool, optional) – whether to consider the Cholesky factor as a lower or upper triangular matrix. Default:
- Keyword Arguments
out (Tensor, optional) – the output tensor for c
>>> a = torch.randn(3, 3) >>> a = torch.mm(a, a.t()) # make symmetric positive definite >>> u = torch.linalg.cholesky(a) >>> a tensor([[ 0.7747, -1.9549, 1.3086], [-1.9549, 6.7546, -5.4114], [ 1.3086, -5.4114, 4.8733]]) >>> b = torch.randn(3, 2) >>> b tensor([[-0.6355, 0.9891], [ 0.1974, 1.4706], [-0.4115, -0.6225]]) >>> torch.cholesky_solve(b, u) tensor([[ -8.1625, 19.6097], [ -5.8398, 14.2387], [ -4.3771, 10.4173]]) >>> torch.mm(a.inverse(), b) tensor([[ -8.1626, 19.6097], [ -5.8398, 14.2387], [ -4.3771, 10.4173]])