YouTip LogoYouTip

Pytorch Torch Linalg Cholesky

# PyTorch torch.linalg.cholesky Function * * PyTorch torch Reference](#) `torch.linalg.cholesky` is a function in PyTorch's linear algebra module (linalg) for computing the Cholesky decomposition of symmetric positive-definite matrices. It is the recommended replacement for `torch.cholesky`. ### Function Definition torch.linalg.cholesky(A, upper=False, out=None) **Parameters**: * `A` (Tensor): Input symmetric positive-definite matrix. * `upper` (bool, optional): If True, returns upper triangular matrix; otherwise returns lower triangular matrix. Default: False. * `out` (Tensor, optional): Output tensor. **Returns**: * `torch.Tensor`: Returns the triangular matrix from Cholesky decomposition. * * * ## Usage Example ## 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("nVerification: L @ L.T = ") print(L @ L.T) Output: Original matrix A: tensor([[4., 2., 2.], [2., 5., 3.], [2., 3., 6.]], dtype=torch.float64)Cholesky decomposition (Lower triangular matrix L): tensor([[2.0000, 0.0000, 0.0000], [1.0000, 2.0000, 0.0000], [1.0000, 1.0000, 2.0000]], dtype=torch.float64)Verification: L @ L.T = tensor([[4., 2., 2.], [2., 5., 3.], [2., 3., 6.]], dtype=torch.float64) * * PyTorch torch Reference](#)
← Pytorch Torch Linalg EigPytorch Torch Less_Equal β†’