paddle.linalg. triangular_solve ( x, y, upper=True, transpose=False, unitriangular=False, name=None ) [source]

Computes the solution of a system of equations with a triangular coefficient matrix x and multiple right-hand sides y .

Input x and y is 2D matrices or batches of 2D matrices. If the inputs are batches, the outputs is also batches.

  • x (Tensor) – The input triangular coefficient matrix. Its shape should be [*, M, M], where * is zero or more batch dimensions. Its data type should be float32 or float64.

  • y (Tensor) – Multiple right-hand sides of system of equations. Its shape should be [*, M, K], where * is zero or more batch dimensions. Its data type should be float32 or float64.

  • 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 x should be transposed before calculation. Default: False.

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

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.


The solution of the system of equations. Its data type should be the same as that of x.

Return type


Examples: .. code-block:: python

# a square system of linear equations: # x1 + x2 + x3 = 0 # 2*x2 + x3 = -9 # -x3 = 5

import paddle import numpy as np

x = paddle.to_tensor([[1, 1, 1],

[0, 2, 1], [0, 0,-1]], dtype=”float64”)

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/tensor/ of paddle.tensor.linalg.triangular_solve, line 42)

Definition list ends without a blank line; unexpected unindent.

y = paddle.to_tensor([[0], [-9], [5]], dtype=”float64”) out = paddle.linalg.triangular_solve(x, y, upper=True)

print(out) # [7, -2, -5]