lu_unpack

paddle.linalg. lu_unpack ( x, y, unpack_ludata=True, unpack_pivots=True, name=None ) [source]

Unpack L U and P to single matrix tensor . unpack L and U matrix from LU, unpack permutation matrix P from Pivtos .

P mat can be get by pivots:

ones = eye(rows) #eye matrix of rank rows
for i in range(cols):
    swap(ones[i], ones[pivots[i]])
Parameters
  • x (Tensor) – The LU tensor get from paddle.linalg.lu, which is combined by L and U.

  • y (Tensor) – Pivots get from paddle.linalg.lu.

  • unpack_ludata (bool, optional) – whether to unpack L and U from x. Default: True.

  • unpack_pivots (bool, optional) – whether to unpack permutation matrix P from Pivtos. Default: True.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

P (Tensor), Permutation matrix P of lu factorization.

L (Tensor), The lower triangular matrix tensor of lu factorization.

U (Tensor), The upper triangular matrix tensor of lu factorization.

Examples

>>> import paddle

>>> x = paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]).astype('float64')
>>> lu,p,info = paddle.linalg.lu(x, get_infos=True)

>>> print(lu)
Tensor(shape=[3, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
[[5.        , 6.        ],
 [0.20000000, 0.80000000],
 [0.60000000, 0.50000000]])
>>> print(p)
Tensor(shape=[2], dtype=int32, place=Place(cpu), stop_gradient=True,
[3, 3])
>>> print(info)
Tensor(shape=[1], dtype=int32, place=Place(cpu), stop_gradient=True,
[0])

>>> P,L,U = paddle.linalg.lu_unpack(lu,p)

>>> print(P)
Tensor(shape=[3, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
[[0., 1., 0.],
 [0., 0., 1.],
 [1., 0., 0.]])
>>> print(L)
Tensor(shape=[3, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
[[1.        , 0.        ],
 [0.20000000, 1.        ],
 [0.60000000, 0.50000000]])
>>> print(U)
Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
[[5.        , 6.        ],
 [0.        , 0.80000000]])

>>> # one can verify : X = P @ L @ U ;