|
|
|
@@ -147,6 +147,7 @@ class ExpandDims(PrimitiveWithInfer): |
|
|
|
>>> input_tensor = Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32) |
|
|
|
>>> expand_dims = P.ExpandDims() |
|
|
|
>>> output = expand_dims(input_tensor, 0) |
|
|
|
>>> print(output) |
|
|
|
[[[2.0, 2.0], |
|
|
|
[2.0, 2.0]]] |
|
|
|
""" |
|
|
|
@@ -230,6 +231,7 @@ class SameTypeShape(PrimitiveWithInfer): |
|
|
|
>>> input_x = Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32) |
|
|
|
>>> input_y = Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32) |
|
|
|
>>> out = P.SameTypeShape()(input_x, input_y) |
|
|
|
>>> print(out) |
|
|
|
[[2. 2.] |
|
|
|
[2. 2.]] |
|
|
|
""" |
|
|
|
@@ -341,6 +343,7 @@ class IsSubClass(PrimitiveWithInfer): |
|
|
|
|
|
|
|
Examples: |
|
|
|
>>> result = P.IsSubClass()(mindspore.int32, mindspore.intc) |
|
|
|
>>> print(result) |
|
|
|
True |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -377,6 +380,7 @@ class IsInstance(PrimitiveWithInfer): |
|
|
|
Examples: |
|
|
|
>>> a = 1 |
|
|
|
>>> result = P.IsInstance()(a, mindspore.int32) |
|
|
|
>>> print(result) |
|
|
|
True |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -424,6 +428,7 @@ class Reshape(PrimitiveWithInfer): |
|
|
|
>>> input_tensor = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mindspore.float32) |
|
|
|
>>> reshape = P.Reshape() |
|
|
|
>>> output = reshape(input_tensor, (3, 2)) |
|
|
|
>>> print(output) |
|
|
|
[[-0.1 0.3] |
|
|
|
[3.6 0.4 ] |
|
|
|
[0.5 -3.2]] |
|
|
|
@@ -490,6 +495,7 @@ class Shape(PrimitiveWithInfer): |
|
|
|
>>> input_tensor = Tensor(np.ones(shape=[3, 2, 1]), mindspore.float32) |
|
|
|
>>> shape = P.Shape() |
|
|
|
>>> output = shape(input_tensor) |
|
|
|
>>> print(output) |
|
|
|
(3, 2, 1) |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -554,6 +560,7 @@ class Squeeze(PrimitiveWithInfer): |
|
|
|
>>> input_tensor = Tensor(np.ones(shape=[3, 2, 1]), mindspore.float32) |
|
|
|
>>> squeeze = P.Squeeze(2) |
|
|
|
>>> output = squeeze(input_tensor) |
|
|
|
>>> print(output) |
|
|
|
[[1. 1.] |
|
|
|
[1. 1.] |
|
|
|
[1. 1.]] |
|
|
|
@@ -609,6 +616,7 @@ class Transpose(PrimitiveWithCheck): |
|
|
|
>>> perm = (0, 2, 1) |
|
|
|
>>> transpose = P.Transpose() |
|
|
|
>>> output = transpose(input_tensor, perm) |
|
|
|
>>> print(output) |
|
|
|
[[[1. 4.] |
|
|
|
[2. 5.] |
|
|
|
[3. 6.]] |
|
|
|
@@ -673,6 +681,7 @@ class GatherV2(PrimitiveWithCheck): |
|
|
|
>>> input_indices = Tensor(np.array([1, 2]), mindspore.int32) |
|
|
|
>>> axis = 1 |
|
|
|
>>> out = P.GatherV2()(input_params, input_indices, axis) |
|
|
|
>>> print(out) |
|
|
|
[[2.0, 7.0], |
|
|
|
[4.0, 54.0], |
|
|
|
[2.0, 55.0]] |
|
|
|
@@ -746,6 +755,7 @@ class Padding(PrimitiveWithInfer): |
|
|
|
>>> x = Tensor(np.array([[8], [10]]), mindspore.float32) |
|
|
|
>>> pad_dim_size = 4 |
|
|
|
>>> out = P.Padding(pad_dim_size)(x) |
|
|
|
>>> print(out) |
|
|
|
[[8, 0, 0, 0], [10, 0, 0, 0]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -786,6 +796,7 @@ class UniqueWithPad(PrimitiveWithInfer): |
|
|
|
>>> x = Tensor(np.array([1, 1, 5, 5, 4, 4, 3, 3, 2, 2,]), mindspore.int32) |
|
|
|
>>> pad_num = 8 |
|
|
|
>>> out = P.UniqueWithPad()(x, pad_num) |
|
|
|
>>> print(out) |
|
|
|
([1, 5, 4, 3, 2, 8, 8, 8, 8, 8], [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]) |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -829,6 +840,7 @@ class Split(PrimitiveWithInfer): |
|
|
|
>>> split = P.Split(1, 2) |
|
|
|
>>> x = Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]])) |
|
|
|
>>> output = split(x) |
|
|
|
>>> print(output) |
|
|
|
([[1, 1], |
|
|
|
[2, 2]], |
|
|
|
[[1, 1], |
|
|
|
@@ -884,7 +896,8 @@ class Rank(PrimitiveWithInfer): |
|
|
|
Examples: |
|
|
|
>>> input_tensor = Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32) |
|
|
|
>>> rank = P.Rank() |
|
|
|
>>> rank(input_tensor) |
|
|
|
>>> output = rank(input_tensor) |
|
|
|
>>> print(output) |
|
|
|
2 |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -956,6 +969,7 @@ class Size(PrimitiveWithInfer): |
|
|
|
>>> input_tensor = Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32) |
|
|
|
>>> size = P.Size() |
|
|
|
>>> output = size(input_tensor) |
|
|
|
>>> print(output) |
|
|
|
4 |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -993,7 +1007,8 @@ class Fill(PrimitiveWithInfer): |
|
|
|
|
|
|
|
Examples: |
|
|
|
>>> fill = P.Fill() |
|
|
|
>>> fill(mindspore.float32, (2, 2), 1) |
|
|
|
>>> output = fill(mindspore.float32, (2, 2), 1) |
|
|
|
>>> print(output) |
|
|
|
[[1.0, 1.0], |
|
|
|
[1.0, 1.0]] |
|
|
|
""" |
|
|
|
@@ -1124,6 +1139,7 @@ class OnesLike(PrimitiveWithInfer): |
|
|
|
>>> oneslike = P.OnesLike() |
|
|
|
>>> x = Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)) |
|
|
|
>>> output = oneslike(x) |
|
|
|
>>> print(output) |
|
|
|
[[1, 1], |
|
|
|
[1, 1]] |
|
|
|
""" |
|
|
|
@@ -1156,6 +1172,7 @@ class ZerosLike(PrimitiveWithCheck): |
|
|
|
>>> zeroslike = P.ZerosLike() |
|
|
|
>>> x = Tensor(np.array([[0, 1], [2, 1]]).astype(np.float32)) |
|
|
|
>>> output = zeroslike(x) |
|
|
|
>>> print(output) |
|
|
|
[[0.0, 0.0], |
|
|
|
[0.0, 0.0]] |
|
|
|
""" |
|
|
|
@@ -1184,6 +1201,7 @@ class TupleToArray(PrimitiveWithInfer): |
|
|
|
|
|
|
|
Examples: |
|
|
|
>>> type = P.TupleToArray()((1,2,3)) |
|
|
|
>>> print(type) |
|
|
|
[1 2 3] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -1228,6 +1246,7 @@ class ScalarToArray(PrimitiveWithInfer): |
|
|
|
>>> op = P.ScalarToArray() |
|
|
|
>>> data = 1.0 |
|
|
|
>>> output = op(data) |
|
|
|
>>> print(output) |
|
|
|
1.0 |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -1260,6 +1279,7 @@ class ScalarToTensor(PrimitiveWithInfer): |
|
|
|
>>> op = P.ScalarToTensor() |
|
|
|
>>> data = 1 |
|
|
|
>>> output = op(data, mindspore.float32) |
|
|
|
>>> print(output) |
|
|
|
1.0 |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -1365,6 +1385,7 @@ class Argmax(PrimitiveWithInfer): |
|
|
|
Examples: |
|
|
|
>>> input_x = Tensor(np.array([2.0, 3.1, 1.2]), mindspore.float32) |
|
|
|
>>> index = P.Argmax(output_type=mindspore.int32)(input_x) |
|
|
|
>>> print(index) |
|
|
|
1 |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -1523,6 +1544,7 @@ class ArgMinWithValue(PrimitiveWithInfer): |
|
|
|
Examples: |
|
|
|
>>> input_x = Tensor(np.random.rand(5), mindspore.float32) |
|
|
|
>>> index, output = P.ArgMinWithValue()(input_x) |
|
|
|
>>> print((index, output)) |
|
|
|
0 0.0496291 |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -1579,6 +1601,7 @@ class Tile(PrimitiveWithInfer): |
|
|
|
>>> input_x = Tensor(np.array([[1, 2], [3, 4]]), mindspore.float32) |
|
|
|
>>> multiples = (2, 3) |
|
|
|
>>> result = tile(input_x, multiples) |
|
|
|
>>> print(result) |
|
|
|
[[1. 2. 1. 2. 1. 2.] |
|
|
|
[3. 4. 3. 4. 3. 4.] |
|
|
|
[1. 2. 1. 2. 1. 2.] |
|
|
|
@@ -1884,6 +1907,7 @@ class Concat(PrimitiveWithInfer): |
|
|
|
>>> data2 = Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)) |
|
|
|
>>> op = P.Concat() |
|
|
|
>>> output = op((data1, data2)) |
|
|
|
>>> print(output) |
|
|
|
[[0, 1], |
|
|
|
[2, 1], |
|
|
|
[0, 1], |
|
|
|
@@ -1931,6 +1955,7 @@ class ParallelConcat(PrimitiveWithInfer): |
|
|
|
>>> data2 = Tensor(np.array([[2, 1]]).astype(np.int32)) |
|
|
|
>>> op = P.ParallelConcat() |
|
|
|
>>> output = op((data1, data2)) |
|
|
|
>>> print(output) |
|
|
|
[[0, 1], [2, 1]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -2013,6 +2038,7 @@ class Pack(PrimitiveWithInfer): |
|
|
|
>>> data2 = Tensor(np.array([2, 3]).astype(np.float32)) |
|
|
|
>>> pack = P.Pack() |
|
|
|
>>> output = pack([data1, data2]) |
|
|
|
>>> print(output) |
|
|
|
[[0, 1], [2, 3]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -2062,6 +2088,7 @@ class Unpack(PrimitiveWithInfer): |
|
|
|
>>> unpack = P.Unpack() |
|
|
|
>>> input_x = Tensor(np.array([[1, 1, 1, 1], [2, 2, 2, 2]])) |
|
|
|
>>> output = unpack(input_x) |
|
|
|
>>> print(output) |
|
|
|
([1, 1, 1, 1], [2, 2, 2, 2]) |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -2113,9 +2140,10 @@ class Slice(PrimitiveWithInfer): |
|
|
|
|
|
|
|
Examples: |
|
|
|
>>> data = Tensor(np.array([[[1, 1, 1], [2, 2, 2]], |
|
|
|
>>> [[3, 3, 3], [4, 4, 4]], |
|
|
|
>>> [[5, 5, 5], [6, 6, 6]]]).astype(np.int32)) |
|
|
|
... [[3, 3, 3], [4, 4, 4]], |
|
|
|
... [[5, 5, 5], [6, 6, 6]]]).astype(np.int32)) |
|
|
|
>>> type = P.Slice()(data, (1, 0, 0), (1, 1, 3)) |
|
|
|
>>> print(type) |
|
|
|
[[[3 3 3]]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -2164,6 +2192,7 @@ class ReverseV2(PrimitiveWithInfer): |
|
|
|
>>> input_x = Tensor(np.array([[1, 2, 3, 4], [5, 6, 7, 8]]), mindspore.int32) |
|
|
|
>>> op = P.ReverseV2(axis=[1]) |
|
|
|
>>> output = op(input_x) |
|
|
|
>>> print(output) |
|
|
|
[[4, 3, 2, 1], [8, 7, 6, 5]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -2201,6 +2230,7 @@ class Rint(PrimitiveWithInfer): |
|
|
|
>>> input_x = Tensor(np.array([-1.6, -0.1, 1.5, 2.0]), mindspore.float32) |
|
|
|
>>> op = P.Rint() |
|
|
|
>>> output = op(input_x) |
|
|
|
>>> print(output) |
|
|
|
[-2., 0., 2., 2.] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -2391,7 +2421,7 @@ class StridedSlice(PrimitiveWithInfer): |
|
|
|
|
|
|
|
Examples |
|
|
|
>>> input_x = Tensor([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]], |
|
|
|
>>> [[5, 5, 5], [6, 6, 6]]], mindspore.float32) |
|
|
|
... [[5, 5, 5], [6, 6, 6]]], mindspore.float32) |
|
|
|
>>> slice = P.StridedSlice() |
|
|
|
>>> output = slice(input_x, (1, 0, 0), (2, 1, 3), (1, 1, 1)) |
|
|
|
>>> output.shape |
|
|
|
@@ -2643,6 +2673,7 @@ class Eye(PrimitiveWithInfer): |
|
|
|
Examples: |
|
|
|
>>> eye = P.Eye() |
|
|
|
>>> out_tensor = eye(2, 2, mindspore.int32) |
|
|
|
>>> print(out_tensor) |
|
|
|
[[1, 0], |
|
|
|
[0, 1]] |
|
|
|
""" |
|
|
|
@@ -2681,6 +2712,7 @@ class ScatterNd(PrimitiveWithInfer): |
|
|
|
>>> update = Tensor(np.array([3.2, 1.1]), mindspore.float32) |
|
|
|
>>> shape = (3, 3) |
|
|
|
>>> output = op(indices, update, shape) |
|
|
|
>>> print(output) |
|
|
|
[[0. 3.2 0.] |
|
|
|
[0. 1.1 0.] |
|
|
|
[0. 0. 0. ]] |
|
|
|
@@ -2731,6 +2763,7 @@ class ResizeNearestNeighbor(PrimitiveWithInfer): |
|
|
|
>>> input_tensor = Tensor(np.array([[[[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]]]), mindspore.float32) |
|
|
|
>>> resize = P.ResizeNearestNeighbor((2, 2)) |
|
|
|
>>> output = resize(input_tensor) |
|
|
|
>>> print(output) |
|
|
|
[[[[-0.1 0.3] |
|
|
|
[0.4 0.5 ]]]] |
|
|
|
""" |
|
|
|
@@ -2772,6 +2805,7 @@ class GatherNd(PrimitiveWithInfer): |
|
|
|
>>> indices = Tensor(np.array([[0, 0], [1, 1]]), mindspore.int32) |
|
|
|
>>> op = P.GatherNd() |
|
|
|
>>> output = op(input_x, indices) |
|
|
|
>>> print(output) |
|
|
|
[-0.1, 0.5] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -2863,6 +2897,7 @@ class ScatterUpdate(_ScatterOp_Dynamic): |
|
|
|
>>> updates = Tensor(np_updates, mindspore.float32) |
|
|
|
>>> op = P.ScatterUpdate() |
|
|
|
>>> output = op(input_x, indices, updates) |
|
|
|
>>> print(output) |
|
|
|
[[2.0, 1.2, 1.0], |
|
|
|
[3.0, 1.2, 1.0]] |
|
|
|
""" |
|
|
|
@@ -2901,6 +2936,7 @@ class ScatterNdUpdate(_ScatterNdOp): |
|
|
|
>>> update = Tensor(np.array([1.0, 2.2]), mindspore.float32) |
|
|
|
>>> op = P.ScatterNdUpdate() |
|
|
|
>>> output = op(input_x, indices, update) |
|
|
|
>>> print(output) |
|
|
|
[[1. 0.3 3.6] |
|
|
|
[0.4 2.2 -3.2]] |
|
|
|
""" |
|
|
|
@@ -2948,6 +2984,7 @@ class ScatterMax(_ScatterOp): |
|
|
|
>>> update = Tensor(np.ones([2, 2, 3]) * 88, mindspore.float32) |
|
|
|
>>> scatter_max = P.ScatterMax() |
|
|
|
>>> output = scatter_max(input_x, indices, update) |
|
|
|
>>> print(output) |
|
|
|
[[88.0, 88.0, 88.0], [88.0, 88.0, 88.0]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -2988,6 +3025,7 @@ class ScatterMin(_ScatterOp): |
|
|
|
>>> update = Tensor(np.ones([2, 2, 3]), mindspore.float32) |
|
|
|
>>> scatter_min = P.ScatterMin() |
|
|
|
>>> output = scatter_min(input_x, indices, update) |
|
|
|
>>> print(output) |
|
|
|
[[0.0, 1.0, 1.0], [0.0, 0.0, 0.0]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -3022,6 +3060,7 @@ class ScatterAdd(_ScatterOp_Dynamic): |
|
|
|
>>> updates = Tensor(np.ones([2, 2, 3]), mindspore.float32) |
|
|
|
>>> scatter_add = P.ScatterAdd() |
|
|
|
>>> output = scatter_add(input_x, indices, updates) |
|
|
|
>>> print(output) |
|
|
|
[[1.0, 1.0, 1.0], [3.0, 3.0, 3.0]] |
|
|
|
""" |
|
|
|
@prim_attr_register |
|
|
|
@@ -3062,6 +3101,7 @@ class ScatterSub(_ScatterOp): |
|
|
|
>>> updates = Tensor(np.array([[[1.0, 1.0, 1.0], [2.0, 2.0, 2.0]]]), mindspore.float32) |
|
|
|
>>> scatter_sub = P.ScatterSub() |
|
|
|
>>> output = scatter_sub(input_x, indices, updates) |
|
|
|
>>> print(output) |
|
|
|
[[-1.0, -1.0, -1.0], [-1.0, -1.0, -1.0]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -3096,6 +3136,7 @@ class ScatterMul(_ScatterOp): |
|
|
|
>>> updates = Tensor(np.array([[2.0, 2.0, 2.0], [2.0, 2.0, 2.0]]), mindspore.float32) |
|
|
|
>>> scatter_mul = P.ScatterMul() |
|
|
|
>>> output = scatter_mul(input_x, indices, updates) |
|
|
|
>>> print(output) |
|
|
|
[[2.0, 2.0, 2.0], [4.0, 4.0, 4.0]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -3130,6 +3171,7 @@ class ScatterDiv(_ScatterOp): |
|
|
|
>>> updates = Tensor(np.array([[2.0, 2.0, 2.0], [2.0, 2.0, 2.0]]), mindspore.float32) |
|
|
|
>>> scatter_div = P.ScatterDiv() |
|
|
|
>>> output = scatter_div(input_x, indices, updates) |
|
|
|
>>> print(output) |
|
|
|
[[3.0, 3.0, 3.0], [1.0, 1.0, 1.0]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -3164,6 +3206,7 @@ class ScatterNdAdd(_ScatterNdOp): |
|
|
|
>>> updates = Tensor(np.array([6, 7, 8, 9]), mindspore.float32) |
|
|
|
>>> scatter_nd_add = P.ScatterNdAdd() |
|
|
|
>>> output = scatter_nd_add(input_x, indices, updates) |
|
|
|
>>> print(output) |
|
|
|
[1, 10, 9, 4, 12, 6, 7, 17] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -3198,6 +3241,7 @@ class ScatterNdSub(_ScatterNdOp): |
|
|
|
>>> updates = Tensor(np.array([6, 7, 8, 9]), mindspore.float32) |
|
|
|
>>> scatter_nd_sub = P.ScatterNdSub() |
|
|
|
>>> output = scatter_nd_sub(input_x, indices, updates) |
|
|
|
>>> print(output) |
|
|
|
[1, -6, -3, 4, -2, 6, 7, -1] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -3229,6 +3273,7 @@ class ScatterNonAliasingAdd(_ScatterNdOp): |
|
|
|
>>> updates = Tensor(np.array([6, 7, 8, 9]), mindspore.float32) |
|
|
|
>>> scatter_non_aliasing_add = P.ScatterNonAliasingAdd() |
|
|
|
>>> output = scatter_non_aliasing_add(input_x, indices, updates) |
|
|
|
>>> print(output) |
|
|
|
[1, 10, 9, 4, 12, 6, 7, 17] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -3466,6 +3511,7 @@ class BatchToSpace(PrimitiveWithInfer): |
|
|
|
>>> op = P.BatchToSpace(block_size, crops) |
|
|
|
>>> input_x = Tensor(np.array([[[[1]]], [[[2]]], [[[3]]], [[[4]]]]), mindspore.float32) |
|
|
|
>>> output = op(input_x) |
|
|
|
>>> print(output) |
|
|
|
[[[[1., 2.], [3., 4.]]]] |
|
|
|
|
|
|
|
""" |
|
|
|
@@ -3635,6 +3681,7 @@ class BatchToSpaceND(PrimitiveWithInfer): |
|
|
|
>>> batch_to_space_nd = P.BatchToSpaceND(block_shape, crops) |
|
|
|
>>> input_x = Tensor(np.array([[[[1]]], [[[2]]], [[[3]]], [[[4]]]]), mindspore.float32) |
|
|
|
>>> output = batch_to_space_nd(input_x) |
|
|
|
>>> print(output) |
|
|
|
[[[[1., 2.], [3., 4.]]]] |
|
|
|
|
|
|
|
""" |
|
|
|
@@ -3860,6 +3907,7 @@ class InplaceUpdate(PrimitiveWithInfer): |
|
|
|
>>> v = Tensor(np.array([[0.5, 1.0], [1.0, 1.5]]), mindspore.float32) |
|
|
|
>>> inplace_update = P.InplaceUpdate(indices) |
|
|
|
>>> result = inplace_update(x, v) |
|
|
|
>>> print(result) |
|
|
|
[[0.5, 1.0], |
|
|
|
[1.0, 1.5], |
|
|
|
[5.0, 6.0]] |
|
|
|
@@ -3915,6 +3963,7 @@ class ReverseSequence(PrimitiveWithInfer): |
|
|
|
>>> seq_lengths = Tensor(np.array([1, 2, 3])) |
|
|
|
>>> reverse_sequence = P.ReverseSequence(seq_dim=1) |
|
|
|
>>> output = reverse_sequence(x, seq_lengths) |
|
|
|
>>> print(output) |
|
|
|
[[1 2 3] |
|
|
|
[5 4 6] |
|
|
|
[9 8 7]] |
|
|
|
@@ -3993,6 +4042,7 @@ class EditDistance(PrimitiveWithInfer): |
|
|
|
>>> truth_shape = Tensor(np.array([2, 2, 2]).astype(np.int64)) |
|
|
|
>>> edit_distance = EditDistance(hypothesis_shape, truth_shape) |
|
|
|
>>> out = edit_distance(hypothesis_indices, hypothesis_values, truth_indices, truth_values) |
|
|
|
>>> print(out) |
|
|
|
>>> [[1.0, 1.0], [1.0, 1.0]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -4126,6 +4176,7 @@ class EmbeddingLookup(PrimitiveWithInfer): |
|
|
|
>>> input_indices = Tensor(np.array([[5, 2], [8, 5]]), mindspore.int32) |
|
|
|
>>> offset = 4 |
|
|
|
>>> out = P.EmbeddingLookup()(input_params, input_indices, offset) |
|
|
|
>>> print(out) |
|
|
|
[[[10, 11], [0 ,0]], [[0, 0], [10, 11]]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -4168,6 +4219,7 @@ class GatherD(PrimitiveWithInfer): |
|
|
|
>>> index = Tensor(np.array([[0, 0], [1, 0]]), mindspore.int32) |
|
|
|
>>> dim = 1 |
|
|
|
>>> out = P.GatherD()(x, dim, index) |
|
|
|
>>> print(out) |
|
|
|
[[1, 1], [4, 3]] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -4212,6 +4264,7 @@ class Identity(PrimitiveWithInfer): |
|
|
|
Examples: |
|
|
|
>>> x = Tensor(np.array([1, 2, 3, 4]), mindspore.int64) |
|
|
|
>>> y = P.Identity()(x) |
|
|
|
>>> print(y) |
|
|
|
[1, 2, 3, 4] |
|
|
|
""" |
|
|
|
|
|
|
|
@@ -4246,6 +4299,7 @@ class RepeatElements(PrimitiveWithInfer): |
|
|
|
>>> x = Tensor(np.array([[0, 1, 2], [3, 4, 5]]), mindspore.int32) |
|
|
|
>>> repeat_elements = P.RepeatElements(rep = 2, axis = 0) |
|
|
|
>>> output = repeat_elements(x) |
|
|
|
>>> print(output) |
|
|
|
[[0, 1, 2], |
|
|
|
[0, 1, 2], |
|
|
|
[3, 4, 5], |
|
|
|
|