On this page
torch.linalg.solve_triangular
torch.linalg.solve_triangular(A, B, *, upper, left=True, unitriangular=False, out=None) → Tensor-
Computes the solution of a triangular system of linear equations with a unique solution.
Letting be or , this function computes the solution of the linear system associated to the triangular matrix without zeros on the diagonal (that is, it is invertible) and the rectangular matrix , , which is defined as
The argument
uppersignals whether is upper or lower triangular.If
left= False, this function returns the matrix that solves the systemIf
upper= True(resp.False) just the upper (resp. lower) triangular half ofAwill be accessed. The elements below the main diagonal will be considered to be zero and will not be accessed.If
unitriangular= True, the diagonal ofAis assumed to be ones and will not be accessed.The result may contain
NaNs if the diagonal ofAcontains zeros or elements that are very close to zero andunitriangular= False(default) or if the input matrix has very small eigenvalues.Supports inputs of float, double, cfloat and cdouble dtypes. Also supports batches of matrices, and if the inputs are batches of matrices then the output has the same batch dimensions.
See also
torch.linalg.solve()computes the solution of a general square system of linear equations with a unique solution.- Parameters
- Keyword Arguments
-
- upper (bool) – whether
Ais an upper or lower triangular matrix. - left (bool, optional) – whether to solve the system
or
. Default:
True. - unitriangular (bool, optional) – if
True, the diagonal elements ofAare assumed to be all equal to1. Default:False. - out (Tensor, optional) – output tensor.
Bmay be passed asoutand the result is computed in-place onB. Ignored ifNone. Default:None.
- upper (bool) – whether
Examples:
>>> A = torch.randn(3, 3).triu_() >>> b = torch.randn(3, 4) >>> X = torch.linalg.solve_triangular(A, B, upper=True) >>> torch.allclose(A @ X, B) True >>> A = torch.randn(2, 3, 3).tril_() >>> B = torch.randn(2, 3, 4) >>> X = torch.linalg.solve_triangular(A, B, upper=False) >>> torch.allclose(A @ X, B) True >>> A = torch.randn(2, 4, 4).tril_() >>> B = torch.randn(2, 3, 4) >>> X = torch.linalg.solve_triangular(A, B, upper=False, left=False) >>> torch.allclose(X @ A, B) True
© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.linalg.solve_triangular.html