mindspore.ops.lu_unpack

mindspore.ops.lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True)[源代码]

LU_dataLU_pivots 还原为P, L, U矩阵,其中P为置换矩阵,L为下三角矩阵,U为上三角矩阵。通常情况下, LU_dataLU_pivots 是矩阵通过LU分解生成的。

参数:
  • LU_data (Tensor) - 打包的LU分解数据,shape为 \((*, M, N)\) ,其中 \(*\) 为batch维度, LU_data 的维度必须等于或大于2。

  • LU_pivots (Tensor) - 打包的LU分枢轴,shape为 \((*, min(M, N))\) ,其中 \(*\) 为batch维度,其中 * 是batch 维度,数据类型为int8、uint8、int16、int32或int64。

  • unpack_data (bool,可选) - 是否解压缩 LU_data 。如果为False,则返回的L和U为None。默认值:True。

  • unpack_pivots (bool,可选) - 是否将 LU_pivots 解压缩为置换矩阵P。如果为False,则返回的P为None。默认值:True。

返回:
  • pivots (Tensor) - LU分解的置换矩阵,shape为 \((*, M, M)\) ,数据类型与 LU_data 相同。

  • L (Tensor) - LU分解的L矩阵,数据类型与 LU_data 相同。

  • U (Tensor) - LU分解的U矩阵,数据类型与 LU_data 相同。

异常:
  • TypeError - 若 LU_data 的数据类型不是int、uint或float。

  • TypeError - 若 LU_pivots 的数据类型不是以下之一:int8、uint8、int16、int32、int64。

  • ValueError - 若 LU_data 的维度小于2。

  • ValueError - 若 LU_pivots 的维度小于1。

  • ValueError - 若 LU_pivots 最后一维的大小不等于 LU_data 的最后两维的较小者。

  • ValueError - 若 LU_dataLU_pivots 的batch维度不匹配。

  • ValueError - 在CPU平台上,若 LU_pivots 的值不在 \([1, LU\_data.shape[-2])\) 范围内。

  • RuntimeError - 在Ascend平台上,若 LU_pivots 的值不在 \([1, LU\_data.shape[-2])\) 范围内。

支持平台:

GPU CPU

样例:

>>> LU_data = Tensor(np.array([[[-0.3806, -0.4872,  0.5536],
...                             [-0.1287,  0.6508, -0.2396],
...                             [ 0.2583,  0.5239,  0.6902]],
...                            [[ 0.6706, -1.1782,  0.4574],
...                             [-0.6401, -0.4779,  0.6701],
...                             [ 0.1015, -0.5363,  0.6165]]]), mstype.float64)
>>> LU_pivots = Tensor(np.array([[1, 3, 3],
...                              [2, 3, 3]]), mstype.int32)
>>> pivots, L, U = ops.lu_unpack(LU_data, LU_pivots)
>>> print(pivots)
[[[1. 0. 0.]
  [0. 0. 1.]
  [0. 1. 0.]]
 [[0. 0. 1.]
  [1. 0. 0.]
  [0. 1. 0.]]]
>>> print(L)
[[[ 1.       0.       0.]
  [-0.1287   1.       0.]
  [ 0.2583   0.5239   1.]]
 [[ 1.0000   0.       0.]
  [-0.6401   1.       0.]
  [ 0.1015  -0.5363   1.]]]
>>> print(U)
[[[-0.3806  -0.4872   0.5536]
  [ 0.       0.6508  -0.2396]
  [ 0.       0.       0.6902]]
 [[ 0.6706  -1.1782   0.4574]
  [ 0.      -0.4779   0.6701]
  [ 0.       0.       0.6165]]]