Rate this Page

torch.cholesky#

torch.cholesky(input,upper=False,*,out=None)Tensor#

Computes the Cholesky decomposition of a symmetric positive-definitematrixAA or for batches of symmetric positive-definite matrices.

Ifupper isTrue, the returned matrixU is upper-triangular, andthe decomposition has the form:

A=UTUA = U^TU

Ifupper isFalse, the returned matrixL is lower-triangular, andthe decomposition has the form:

A=LLTA = LL^T

Ifupper isTrue, andAA is a batch of symmetric positive-definitematrices, then the returned tensor will be composed of upper-triangular Cholesky factorsof each of the individual matrices. Similarly, whenupper isFalse, the returnedtensor will be composed of lower-triangular Cholesky factors of each of the individualmatrices.

Warning

torch.cholesky() is deprecated in favor oftorch.linalg.cholesky()and will be removed in a future PyTorch release.

L=torch.cholesky(A) should be replaced with

L=torch.linalg.cholesky(A)

U=torch.cholesky(A,upper=True) should be replaced with

U=torch.linalg.cholesky(A).mH

This transform will produce equivalent results for all valid (symmetric positive definite) inputs.

Parameters
  • input (Tensor) – the input tensorAA of size(,n,n)(*, n, n) where* is zero or morebatch dimensions consisting of symmetric positive-definite matrices.

  • upper (bool,optional) – flag that indicates whether to return aupper or lower triangular matrix. Default:False

Keyword Arguments

out (Tensor,optional) – the output matrix

Example:

>>>a=torch.randn(3,3)>>>a=a@a.mT+1e-3# make symmetric positive-definite>>>l=torch.cholesky(a)>>>atensor([[ 2.4112, -0.7486,  1.4551],        [-0.7486,  1.3544,  0.1294],        [ 1.4551,  0.1294,  1.6724]])>>>ltensor([[ 1.5528,  0.0000,  0.0000],        [-0.4821,  1.0592,  0.0000],        [ 0.9371,  0.5487,  0.7023]])>>>l@l.mTtensor([[ 2.4112, -0.7486,  1.4551],        [-0.7486,  1.3544,  0.1294],        [ 1.4551,  0.1294,  1.6724]])>>>a=torch.randn(3,2,2)# Example for batched input>>>a=a@a.mT+1e-03# make symmetric positive-definite>>>l=torch.cholesky(a)>>>z=l@l.mT>>>torch.dist(z,a)tensor(2.3842e-07)