torch.lu
- torch.lu(*args, **kwargs)
Computes the LU factorization of a matrix or batches of matrices
A. Returns a tuple containing the LU factorization and pivots ofA. Pivoting is done ifpivotis set to.
Computes the LU factorization of a matrix or batches of matrices
A. Returns a tuple containing the LU factorization and
pivots of A. Pivoting is done if pivot is set to
.
A (Tensor) – the tensor to factor of size
pivot (bool, optional) – Whether to compute the LU decomposition with partial pivoting, or the regular LU
decomposition. pivot= False not supported on CPU. Default: True.
get_infos (bool, optional) – if set to True, returns an info IntTensor.
Default: False
out (tuple, optional) – optional output tuple. If get_infos is True,
then the elements in the tuple are Tensor, IntTensor,
and IntTensor. If get_infos is False, then the
elements in the tuple are Tensor, IntTensor. Default: None
A tuple of tensors containing
factorization (Tensor): the factorization of size
pivots (IntTensor): the pivots of size .
stores all the intermediate transpositions of rows. The final permutation could be reconstructed by applying for , where is initially the identity permutation of elements (essentially this is what is doing).
(Tensor, IntTensor, IntTensor (optional))
Example:
>>> A = torch.randn(2, 3, 3)
>>> A_LU, pivots = torch.lu(A)
>>> A_LU
tensor([[[ 1.3506, 2.5558, -0.0816],
[ 0.1684, 1.1551, 0.1940],
[ 0.1193, 0.6189, -0.5497]],
[[ 0.4526, 1.2526, -0.3285],
[-0.7988, 0.7175, -0.9701],
[ 0.2634, -0.9255, -0.3459]]])
>>> pivots
tensor([[ 3, 3, 3],
[ 3, 3, 3]], dtype=torch.int32)
>>> A_LU, pivots, info = torch.lu(A, get_infos=True)
>>> if info.nonzero().size(0) == 0:
... print('LU factorization succeeded for all samples!')
LU factorization succeeded for all samples!
permswap(perm[i], perm[pivots[i] - 1])i = 0, ..., pivots.size(-1) - 1perminfos (IntTensor, optional): if get_infos is True, this is a tensor of
size where non-zero values indicate whether factorization for the matrix or
each minibatch has succeeded or failed