torch.triangular_solve
- torch.triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None)
Solves a system of equations with a square upper or lower triangular invertible matrix and multiple right-hand sides .
In symbols, it solves and assumes is square upper-triangular
(or lower-triangular if upper= False) and does not have zeros on the diagonal.
torch.triangular_solve(b, A) can take in 2D inputs b, A or inputs that are batches of 2D matrices. If the inputs are batches, then returns batched outputs X
If the diagonal of A contains zeros or elements that are very close to zero and
unitriangular= False (default) or if the input matrix is badly conditioned,
the result may contain NaN s.
Supports input of float, double, cfloat and cdouble data types.
Examples:
>>> A = torch.randn(2, 2).triu()
>>> A
tensor([[ 1.1527, -1.0753],
[ 0.0000, 0.7986]])
>>> b = torch.randn(2, 3)
>>> b
tensor([[-0.0210, 2.3513, -1.5492],
[ 1.5429, 0.7403, -1.0243]])
>>> torch
X = torch.linalg.solve_triangular(A, B)
upper (bool, optional) – whether is upper or lower triangular. Default: True.
transpose (bool, optional) – solves op(A)X = b where op(A) = A^T if this flag is True,
and op(A) = A if it is False. Default: False.
unitriangular (bool, optional) – whether is unit triangular.
If True, the diagonal elements of are assumed to be
1 and not referenced from . Default: False.
out ((Tensor, Tensor), optional) – tuple of two tensors to write the output to. Ignored if None. Default: None.
A namedtuple (solution, cloned_coefficient) where cloned_coefficient is a clone of and solution is the solution to (or whatever variant of the system of equations, depending on the keyword arguments.)