mindspore.ops.lu_solve
- mindspore.ops.lu_solve(b, LU_data, LU_pivots)[source]
Computes the solution y to the system of linear equations \(Ay = b\) , given LU decomposition \(A\) and column vector \(b\).
LU decomposition of a matrix can be generated from
mindspore.scipy.linalg.lu_factor()
.Warning
This is an experimental API that is subject to change or deletion.
- Parameters
b (Tensor) – Column vector b in the above equation. It has shape \((*, m, k)\), where \(*\) is batch dimensions, with data type float32, float16.
LU_data (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, float16.
LU_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.
- Returns
Tensor, the same data type as the b and LU_data.
- Raises
TypeError – If dtype of b or LU_data is not one of: float32, float16.
TypeError – If dtype of LU_pivots is not: int32.
TypeError – If b, LU_data or LU_pivots is not Tensor.
TypeError – If dtype of b is not same as dtype of LU_data.
ValueError – If the batch dimensions of LU_pivots does not match the batch dimensions of LU_data.
ValueError – If b dimension less than 2, LU_data dimension less than 2 or LU_pivots dimension less than 1.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> b = Tensor(np.array([[1], [3], [3]]), mindspore.float32) >>> LU_data = Tensor(np.array([[2, 1, 1], [0.5, 1, 1.5], [0.5, 0, 2.5]]), mindspore.float32) >>> LU_pivots = Tensor(np.array([2, 2, 3]), mindspore.int32) >>> y = ops.lu_solve(b, LU_data, LU_pivots) >>> print(y) [[ 1.9000002] [-1.4000001] [ 0.6 ]]