Shortcuts

torch.triangular_solve

torch.triangular_solve(input, A, upper=True, transpose=False, unitriangular=False)

Solves a system of equations with a triangular coefficient matrix AA and multiple right-hand sides bb .

In particular, solves AX=bAX = b and assumes AA is upper-triangular with the default keyword arguments.

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

Supports real-valued and complex-valued inputs.

Parameters
  • input (Tensor) – multiple right-hand sides of size (,m,k)(*, m, k) where * is zero of more batch dimensions (bb )

  • A (Tensor) – the input triangular coefficient matrix of size (,m,m)(*, m, m) where * is zero or more batch dimensions

  • upper (bool, optional) – whether to solve the upper-triangular system of equations (default) or the lower-triangular system of equations. Default: True.

  • transpose (bool, optional) – whether AA should be transposed before being sent into the solver. Default: False.

  • unitriangular (bool, optional) – whether AA is unit triangular. If True, the diagonal elements of AA are assumed to be 1 and not referenced from AA . Default: False.

Returns

A namedtuple (solution, cloned_coefficient) where cloned_coefficient is a clone of AA and solution is the solution XX to AX=bAX = b (or whatever variant of the system of equations, depending on the keyword arguments.)

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.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]]))

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources