Shortcuts

torch.cholesky_solve

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 uu.

If upper is False, uu is and lower triangular and c is returned such that:

c=(uuT)1bc = (u u^T)^{{-1}} b

If upper is True or not provided, uu is upper triangular and c is returned such that:

c=(uTu)1bc = (u^T u)^{{-1}} b

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.

Parameters
  • input (Tensor) – input matrix bb of size (,m,k)(*, m, k), where * is zero or more batch dimensions

  • input2 (Tensor) – input matrix uu of size (,m,m)(*, m, m), 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: False.

Keyword Arguments

out (Tensor, optional) – the output tensor for c

Example:

>>> 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]])

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources