latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.lu_unpack
- tensorplay.functional.lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None)[source]
Unpacks the LU decomposition returned by
lu_factor()into the P, L, U matrices.See also
lu()returns the matrices from the LU decomposition. Its gradient formula is more efficient than that of doinglu_factor()followed bylu_unpack().- Parameters:
LU_data (Tensor) – the packed LU factorization data
LU_pivots (Tensor) – the packed LU factorization pivots
unpack_data (bool) – flag indicating if the data should be unpacked. If
False, then the returnedLandUare empty tensors. Default:Trueunpack_pivots (bool) – flag indicating if the pivots should be unpacked into a permutation matrix
P. IfFalse, then the returnedPis an empty tensor. Default:True
- Keyword Arguments:
out (tuple, optional) – output tuple of three tensors. Ignored if None.
- Returns:
A namedtuple
(P, L, U)
Examples:
>>> A = tensorplay.randn(2, 3, 3) >>> LU, pivots = tensorplay.linalg.lu_factor(A) >>> P, L, U = tensorplay.lu_unpack(LU, pivots) >>> # We can recover A from the factorization >>> A_ = P @ L @ U >>> tensorplay.allclose(A, A_) True >>> # LU factorization of a rectangular matrix: >>> A = tensorplay.randn(2, 3, 2) >>> LU, pivots = tensorplay.linalg.lu_factor(A) >>> P, L, U = tensorplay.lu_unpack(LU, pivots) >>> # P, L, U are the same as returned by linalg.lu >>> P_, L_, U_ = tensorplay.linalg.lu(A) >>> tensorplay.allclose(P, P_) and tensorplay.allclose(L, L_) and tensorplay.allclose(U, U_) True
Help improve this page
Found an error, an unclear step, or a missing example?

