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

PyTorch torch.cholesky_inverse function

PyTorch torch.cholesky_inverse function


PyTorch torch reference manual PyTorch torch reference manual

torch.cholesky_inverse is a function in PyTorch used to compute the inverse of a Cholesky decomposition. It uses the result of the Cholesky decomposition to compute the inverse of a matrix efficiently.

Function definition

torch.cholesky_inverse(L, 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.

cholesky

(

A

)

Compute the inverse matrix using Cholesky decomposition

A_inv

=

torch.

cholesky_inverse

(

L

)

print

(

"Original matrix A:"

)

print

(

A

)

print

(

"nInverse matrix A^-1:"

)

print

(

A_inv

)

print

(

"nVerify: A @ A^-1 ="

)

print

(

A

@

A_inv

)

The output is:

原矩阵 A:

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

        [2., 5., 3.],

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



逆矩阵 A^-1:

tensor([[ 0.7500, -0.5000, -0.2500],

        [-0.5000,  1.0000, -0.0000],

        [-0.2500, -0.0000,  0.2500]], dtype=torch.float64)



验证: A @ A^-1 =

tensor([[ 1.0000e+00, -1.4901e-08,  0.0000e+00],

        [-7.4506e-09,  1.0000e+00,  1.4901e-08],

        [ 0.0000e+00,  7.4506e-09,  1.0000e+00]], dtype=torch.float64)


PyTorch torch reference manual PyTorch torch reference manual