lu_solve¶
- paddle.linalg. lu_solve ( b: Tensor, lu: Tensor, pivots: Tensor, trans: Literal[N, T, C] = 'N', name: str | None = None ) [source]
-
Computes the solution x to the system of linear equations Ax=b , given LU decomposition A and column vector b.
- Parameters
-
b (Tensor) – Column vector b in the above equation. It has shape (∗,m,k), where ∗ is batch dimensions, with data type float32, float64.
lu (Tensor) – LU decomposition. It has shape (∗,m,m), where ∗ is batch dimensions, that can be decomposed into an upper triangular matrix U and a lower triangular matrix L, with data type float32, float64.
pivots (Tensor) – Permutation matrix P of LU decomposition. It has shape (∗,m), where ∗ is batch dimensions, that can be converted to a permutation matrix P, with data type int32.
trans (str, optional) – The transpose of the matrix A. It can be “N” , “T” or “C”, “N” means Ax=b, “T” means ATx=b, “C” means AHx=b, default is “N”.
name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
Tensor, the same data type as the b and lu.
Examples
>>> import paddle >>> import numpy as np
>>> A = paddle.to_tensor([[3, 1], [1, 2]], dtype="float64") >>> b = paddle.to_tensor([[9, 8], [9, 8]], dtype="float64") >>> lu, p = paddle.linalg.lu(A) >>> x = paddle.lu_solve(b, lu, p) >>> paddle.allclose(A @ x, b)
>>> print(x) Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True, [[1.80000000, 1.60000000], [3.60000000, 3.20000000]])