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 matrixand 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 inputsb, A or inputs that arebatches of 2D matrices. If the inputs are batches, then returnsbatched outputsX
If the diagonal of
Acontains zeros or elements that are very close to zero andunitriangular= False (default) or if the input matrix is badly conditioned,the result may containNaN s.Supports input of float, double, cfloat and cdouble data types.
Warning
torch.triangular_solve()is deprecated in favor oftorch.linalg.solve_triangular()and will be removed in a future PyTorch release.torch.linalg.solve_triangular()has its arguments reversed and does not return acopy of one of the inputs.X=torch.triangular_solve(B,A).solutionshould be replaced withX=torch.linalg.solve_triangular(A,B)
- Parameters
b (Tensor) – multiple right-hand sides of size where is zero of more batch dimensions
A (Tensor) – the input triangular coefficient matrix of sizewhere is zero or more batch dimensions
upper (bool,optional) – whether is upper or lower triangular. Default:
True.transpose (bool,optional) – solvesop(A)X = b whereop(A) = A^T if this flag is
True,andop(A) = A if it isFalse. Default:False.unitriangular (bool,optional) – whether is unit triangular.If True, the diagonal elements of are assumed to be1 and not referenced from. Default:
False.
- Keyword Arguments
out ((Tensor,Tensor),optional) – tuple of two tensors to writethe output to. Ignored ifNone. Default:None.
- Returns
A namedtuple(solution, cloned_coefficient) wherecloned_coefficientis a clone of andsolution is the solution to(or whatever variant of the system of equations, depending on the keyword arguments.)
Examples:
>>>A=torch.randn(2,2).triu()>>>Atensor([[ 1.1527, -1.0753], [ 0.0000, 0.7986]])>>>b=torch.randn(2,3)>>>btensor([[-0.0210, 2.3513, -1.5492], [ 1.5429, 0.7403, -1.0243]])>>>torch.triangular_solve(b,A)torch.return_types.triangular_solve(solution=tensor([[ 1.7841, 2.9046, -2.5405], [ 1.9320, 0.9270, -1.2826]]),cloned_coefficient=tensor([[ 1.1527, -1.0753], [ 0.0000, 0.7986]]))