From: @yuyiyang_3418 Reviewed-by: @liangchenghui,@wuxuejian Signed-off-by: @liangchenghuipull/13845/MERGE
| @@ -935,7 +935,7 @@ class MatrixDiag(Cell): | |||||
| ``Ascend`` | ``Ascend`` | ||||
| Examples: | Examples: | ||||
| >>> x = Tensor(np.array([1, -1]), mstype.float32) | |||||
| >>> x = Tensor(np.array([1, -1]), mindspore.float32) | |||||
| >>> matrix_diag = nn.MatrixDiag() | >>> matrix_diag = nn.MatrixDiag() | ||||
| >>> output = matrix_diag(x) | >>> output = matrix_diag(x) | ||||
| >>> print(output) | >>> print(output) | ||||
| @@ -3558,15 +3558,25 @@ class ScatterNdUpdate(_ScatterNdOp): | |||||
| ``Ascend`` ``CPU`` | ``Ascend`` ``CPU`` | ||||
| Examples: | Examples: | ||||
| >>> np_x = np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]) | |||||
| >>> input_x = mindspore.Parameter(Tensor(np_x, mindspore.float32), name="x") | |||||
| >>> indices = Tensor(np.array([[0, 0], [1, 1]]), mindspore.int32) | |||||
| >>> updates = Tensor(np.array([1.0, 2.2]), mindspore.float32) | |||||
| >>> op = ops.ScatterNdUpdate() | |||||
| >>> output = op(input_x, indices, updates) | |||||
| >>> # Example 1: Scatter [9, 0, 7, 3] by indices [3, 4, 1, 8] in a 1-D tensor | |||||
| >>> op = ops.ScatterNd() | |||||
| >>> indices = Tensor(np.array([3, 4, 1, 8]), mindspore.int32) | |||||
| >>> updates = Tensor(np.array([8, 9, 7, 3]), mindspore.int32) | |||||
| >>> shape = (10, ) | |||||
| >>> output = op(indices, updates, shape) | |||||
| >>> print(output) | >>> print(output) | ||||
| [[ 1. 0.3 3.6] | |||||
| [ 0.4 2.2 -3.2]] | |||||
| [0 7 0 8 9 0 0 0 3 0] | |||||
| >>> # Example 2: Scatter [3.2, 1.1] by indices [[0, 1], [1, 1]] in a 2-D tensor | |||||
| >>> op = ops.ScatterNd() | |||||
| >>> indices = Tensor(np.array([[0, 1], [1, 1]]), mindspore.int32) | |||||
| >>> updates = Tensor(np.array([3.2, 1.1]), mindspore.float32) | |||||
| >>> shape = (3, 3) | |||||
| >>> output = op(indices, updates, shape) | |||||
| >>> print(output) | |||||
| [[0. 3.2 0. ] | |||||
| [0. 1.1 0. ] | |||||
| [0. 0. 0. ]] | |||||
| """ | """ | ||||
| @prim_attr_register | @prim_attr_register | ||||
| @@ -3791,15 +3791,16 @@ class NMSWithMask(PrimitiveWithInfer): | |||||
| ``Ascend`` ``GPU`` | ``Ascend`` ``GPU`` | ||||
| Examples: | Examples: | ||||
| >>> bbox = np.array([[0.4, 0.2, 0.4, 0.3, 0.1], [0.4, 0.3, 0.6, 0.8, 0.7]]) | |||||
| >>> bbox = np.array([[100.0, 100.0, 50.0, 68.0, 0.63], [150.0, 75.0, 165.0, 115.0, 0.55], | |||||
| [12.0, 190.0, 288.0, 200.0, 0.9], [28.0, 130.0, 106.0, 172.0, 0.3]]) | |||||
| >>> bbox[:, 2] += bbox[:, 0] | >>> bbox[:, 2] += bbox[:, 0] | ||||
| >>> bbox[:, 3] += bbox[:, 1] | >>> bbox[:, 3] += bbox[:, 1] | ||||
| >>> inputs = Tensor(bbox, mindspore.float32) | >>> inputs = Tensor(bbox, mindspore.float32) | ||||
| >>> nms = ops.NMSWithMask(0.5) | |||||
| >>> nms = ops.NMSWithMask(0.1) | |||||
| >>> output_boxes, indices, mask = nms(inputs) | >>> output_boxes, indices, mask = nms(inputs) | ||||
| >>> indices_np = indices.asnumpy() | >>> indices_np = indices.asnumpy() | ||||
| >>> print(indices_np[mask.asnumpy()]) | >>> print(indices_np[mask.asnumpy()]) | ||||
| [0 1] | |||||
| [0 1 2] | |||||
| """ | """ | ||||
| @prim_attr_register | @prim_attr_register | ||||