Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.linalg.cholesky function

PyTorch torch.linalg.cholesky function


PyTorch torch reference manual PyTorch torch reference manual

torch.linalg.cholesky is a function in PyTorch's linear algebra module (linalg) used to compute the Cholesky decomposition of a symmetric positive-definite matrix. It is the torch.cholesky recommended replacement.

Function definition

torch.linalg.cholesky(A, upper=False, out=None)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create a symmetric positive-definite matrix

A

=

torch.

tensor

(

[

[

4.0

,

2.0

,

2.0

]

,

                 

[

2.0

,

5.0

,

3.0

]

,

                 

[

2.0

,

3.0

,

6.0

]

]

,

dtype

=

torch.

float64

)

Cholesky decomposition

L

=

torch.

linalg

.

cholesky

(

A

)

print

(

"Original matrix A:"

)

print

(

A

)

print

(

"nCholesky decomposition (lower triangular matrix L):"

)

print

(

L

)

print

(

"nVerify: L @ L.T = "

)

print

(

L

@

L.

T

)

The output is:

原矩阵 A:

tensor([[4., 2., 2.],

        [2., 5., 3.],

        [2., 3., 6.]], dtype=torch.float64)

Cholesky 分解 (下三角矩阵 L):

tensor([[2.0000, 0.0000, 0.0000],

        [1.0000, 2.0000, 0.0000],

        [1.0000, 1.0000, 2.0000]], dtype=torch.float64)

验证: L @ L.T =

tensor([[4., 2., 2.],

        [2., 5., 3.],

        [2., 3., 6.]], dtype=torch.float64)


PyTorch torch reference manual PyTorch torch reference manual