现实题材力作抢滩春季荧屏 火热之外更有冷思考

paddle.linalg. triangular_solve ( x: Tensor, y: Tensor, upper: bool = True, transpose: bool = False, unitriangular: bool = False, name: str | None = None ) Tensor [source]
百度 包飞现场表演一段蒙古舞蹈,田学明随手瞬间变出三大盆鲜花,令观众鼓掌称绝。

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

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

Equations can be described as:

\[x * Out = y\]

Solution of Equations is:

\[Out = x ^ {-1} * y\]
Parameters
  • 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, float64, complex64, complex128.

  • 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, float64, complex64, complex128.

  • 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|None, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

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

Return type

Tensor

Examples

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

>>> import paddle
>>> x = paddle.to_tensor([[1, 1, 1],
...                       [0, 2, 1],
...                       [0, 0,-1]], dtype="float64")
>>> y = paddle.to_tensor([[0], [-9], [5]], dtype="float64")
>>> out = paddle.linalg.triangular_solve(x, y, upper=True)

>>> print(out)
Tensor(shape=[3, 1], dtype=float64, place=Place(cpu), stop_gradient=True,
[[ 7.],
 [-2.],
 [-5.]])