Fonction torch.lu de PyTorch


Pytorch torch 参考手册Manuel de référence Pytorch torch

torch.luC'est une fonction de PyTorch utilisée pour calculer la décomposition LU d'une matrice. La décomposition LU décompose la matrice A en A = P * L * U, où L est une matrice triangulaire inférieure, U est une matrice triangulaire supérieure, et P est une matrice de permutation.

Définition de fonction

torch.lu(A, pivot=True, get_infos=False, out=None)

Parameters:

  • A(Tensor): matrice d'entrée.
  • pivot(bool, optional) : Indique s'il faut effectuer la décomposition LU avec pivotage des colonnes. Valeur par défaut : True.
  • get_infos(bool, optional) : Si True, renvoyer les informations. Valeur par défaut : False.
  • out(tuple, facultatif) : Tuple de sortie.

Valeur de retour:

  • tuple: Renvoie le tuple (pivot, L, U).

Exemples d'utilisation

Exemple

import torch

# Créer une matrice
A = torch.tensor([[1.0, 2.0, 3.0],
                  [4.0, 5.0, 6.0],
                  [7.0, 8.0, 9.0]])

# Décomposition LU
LU, pivots = torch.lu(A, pivot=True)

print("Matrice A :")
print(A)
print("\nmatrice LU :")
print(LU)
print("\nIndices des pivots :")
print(pivots)

Le résultat de sortie est:

矩阵 A:
tensor([[1., 2., 3.],
        [4., 5., 6.],
        [7., 8., 9.]])
LU 矩阵:
tensor([[7., 8., 9.],
        [0.2, 0.4, 0.6],
        [0.6, 0.8, 0.0]])
主元索引:
tensor([3, 3, 3], dtype=torch.int32)

Exemple - Utilisation de get_infos

import torch

A = torch.tensor([[1.0, 2.0, 3.0],
                  [4.0, 5.0, 6.0],
                  [7.0, 8.0, 9.0]])

# Décomposition LU, y compris les informations
LU, pivots, info = torch.lu(A, pivot=True, get_infos=True)

print("Informations :", info)

Pytorch torch 参考手册Manuel de référence Pytorch torch

Autres extensions