torch.lu_unpack¶
- torch.lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None)¶
将
lu_factor()
返回的 LU 分解解包到 P, L, U 矩阵中。另请参阅
lu()
返回 LU 分解中的矩阵。其梯度公式比执行lu_factor()
后再执行lu_unpack()
更有效。- 参数
- 关键字参数
out (tuple, 可选) – 三个张量的输出元组。如果为 None,则忽略。
- 返回值
命名元组
(P, L, U)
示例
>>> A = torch.randn(2, 3, 3) >>> LU, pivots = torch.linalg.lu_factor(A) >>> P, L, U = torch.lu_unpack(LU, pivots) >>> # We can recover A from the factorization >>> A_ = P @ L @ U >>> torch.allclose(A, A_) True >>> # LU factorization of a rectangular matrix: >>> A = torch.randn(2, 3, 2) >>> LU, pivots = torch.linalg.lu_factor(A) >>> P, L, U = torch.lu_unpack(LU, pivots) >>> # P, L, U are the same as returned by linalg.lu >>> P_, L_, U_ = torch.linalg.lu(A) >>> torch.allclose(P, P_) and torch.allclose(L, L_) and torch.allclose(U, U_) True