pytorch / 2 / generated / torch.cholesky_inverse.html

torch.cholesky_inverse

torch.cholesky_inverse(input, upper=False, *, out=None) → Tensor

Computes the inverse of a symmetric positive-definite matrix A A using its Cholesky factor u u : returns matrix inv. The inverse is computed using LAPACK routines dpotri and spotri (and the corresponding MAGMA routines).

If upper is False, u u is lower triangular such that the returned tensor is

i n v = ( u u T ) 1 inv = (uu^{{T}})^{{-1}}

If upper is True or not provided, u u is upper triangular such that the returned tensor is

i n v = ( u T u ) 1 inv = (u^T u)^{{-1}}

Supports input of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if A A is a batch of matrices then the output has the same batch dimensions.

Parameters
  • input (Tensor) – the input tensor A A of size ( , n , n ) (*, n, n) , consisting of symmetric positive-definite matrices where * is zero or more batch dimensions.
  • upper (bool, optional) – flag that indicates whether to return a upper or lower triangular matrix. Default: False
Keyword Arguments

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

Example:

>>> a = torch.randn(3, 3)
>>> a = torch.mm(a, a.t()) + 1e-05 * torch.eye(3) # make symmetric positive definite
>>> u = torch.linalg.cholesky(a)
>>> a
tensor([[  0.9935,  -0.6353,   1.5806],
        [ -0.6353,   0.8769,  -1.7183],
        [  1.5806,  -1.7183,  10.6618]])
>>> torch.cholesky_inverse(u)
tensor([[ 1.9314,  1.2251, -0.0889],
        [ 1.2251,  2.4439,  0.2122],
        [-0.0889,  0.2122,  0.1412]])
>>> a.inverse()
tensor([[ 1.9314,  1.2251, -0.0889],
        [ 1.2251,  2.4439,  0.2122],
        [-0.0889,  0.2122,  0.1412]])
>>> a = torch.randn(3, 2, 2) # Example for batched input
>>> a = a @ a.mT + 1e-03 # make symmetric positive-definite
>>> l = torch.linalg.cholesky(a)
>>> z = l @ l.mT
>>> torch.dist(z, a)
tensor(3.5894e-07)

© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.cholesky_inverse.html