modifg_ops_note

pull/8922/head
lilei 4 years ago
parent 497d3a42ca
commit 43c0092d7f

@ -18,17 +18,7 @@ Operators can be used in the construct function of Cell.
Examples: Examples:
>>> from mindspore.ops import operations as P
>>> from mindspore.ops import composite as C
>>> from mindspore.ops import functional as F
>>> import mindspore.ops as ops >>> import mindspore.ops as ops
Note:
- The Primitive operators in operations need to be instantiated before being used.
- The composite operators are the pre-defined combination of operators.
- The functional operators are the pre-instantiated Primitive operators, which can be used directly as a function.
- For functional operators usage, please refer to
https://gitee.com/mindspore/mindspore/blob/master/mindspore/ops/functional.py
""" """
from .primitive import Primitive, PrimitiveWithInfer, prim_attr_register from .primitive import Primitive, PrimitiveWithInfer, prim_attr_register

@ -94,7 +94,7 @@ class SearchCacheIdx(PrimitiveWithInfer):
[21, 9, -5, 1]], np.int32)), name="hashmap") [21, 9, -5, 1]], np.int32)), name="hashmap")
>>> indices = Tensor(np.array([10, 2, 25, 5, 3], np.int32)) >>> indices = Tensor(np.array([10, 2, 25, 5, 3], np.int32))
>>> step = 0, emb_max_num = 25, cache_max_num = 10 >>> step = 0, emb_max_num = 25, cache_max_num = 10
>>> ops = P.SearchCacheIdx() >>> ops = ops.SearchCacheIdx()
>>> cache_idx, miss_idx, miss_emb_idx = ops(hashmap, indices, step, emb_max_num, cache_max_num) >>> cache_idx, miss_idx, miss_emb_idx = ops(hashmap, indices, step, emb_max_num, cache_max_num)
cache_idx : [5, 1, 10, -1, 3] cache_idx : [5, 1, 10, -1, 3]
miss_idx : [-1, -1, -1, 3, -1] miss_idx : [-1, -1, -1, 3, -1]

@ -496,7 +496,7 @@ class DropoutGrad(PrimitiveWithInfer):
Tensor, the value of generated mask for input shape. Tensor, the value of generated mask for input shape.
Examples: Examples:
>>> dropout_grad = P.DropoutGrad(keep_prob=0.5) >>> dropout_grad = ops.DropoutGrad(keep_prob=0.5)
>>> in = Tensor((20, 16, 50, 50)) >>> in = Tensor((20, 16, 50, 50))
>>> out = dropout_grad(in) >>> out = dropout_grad(in)
""" """

@ -130,7 +130,7 @@ class Range(PrimitiveWithInfer):
Tensor, has the same shape and dtype as `input_x`. Tensor, has the same shape and dtype as `input_x`.
Examples: Examples:
>>> range = P.Range(1.0, 8.0, 2.0) >>> range = ops.Range(1.0, 8.0, 2.0)
>>> x = Tensor(np.array([1, 2, 3, 2]), mindspore.int32) >>> x = Tensor(np.array([1, 2, 3, 2]), mindspore.int32)
>>> output = range(x) >>> output = range(x)
>>> print(output) >>> print(output)
@ -199,7 +199,7 @@ class Quant(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor([100.0, 150.0], mstype.float32) >>> input_x = Tensor([100.0, 150.0], mstype.float32)
>>> quant = P.Quant(80.0, 0.0, False, "Round") >>> quant = ops.Quant(80.0, 0.0, False, "Round")
>>> y = quant(input_x) >>> y = quant(input_x)
""" """
@ -253,7 +253,7 @@ class Dequant(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor([100.0, 150.0], mstype.float32) >>> input_x = Tensor([100.0, 150.0], mstype.float32)
>>> dequant = P.Dequant(False, False) >>> dequant = ops.Dequant(False, False)
>>> y = dequant(input_x) >>> y = dequant(input_x)
""" """
@ -289,7 +289,7 @@ class LinSpace(PrimitiveWithInfer):
Tensor, has the same shape as `assist`. Tensor, has the same shape as `assist`.
Examples: Examples:
>>> linspace = P.LinSpace() >>> linspace = ops.LinSpace()
>>> assist = Tensor([5, 5.5], mindspore.float32) >>> assist = Tensor([5, 5.5], mindspore.float32)
>>> start = Tensor(1, mindspore.float32) >>> start = Tensor(1, mindspore.float32)
>>> stop = Tensor(10, mindspore.float32) >>> stop = Tensor(10, mindspore.float32)
@ -329,7 +329,7 @@ class MatrixDiag(PrimitiveWithInfer):
Examples: Examples:
>>> x = Tensor(np.array([1, -1]), mstype.float32) >>> x = Tensor(np.array([1, -1]), mstype.float32)
>>> assist = Tensor(np.arange(-12, 0).reshape(3, 2, 2), mindspore.float32) >>> assist = Tensor(np.arange(-12, 0).reshape(3, 2, 2), mindspore.float32)
>>> matrix_diag = P.MatrixDiag() >>> matrix_diag = ops.MatrixDiag()
>>> result = matrix_diag(x, assist) >>> result = matrix_diag(x, assist)
>>> print(result) >>> print(result)
[[[-12. 11.] [[[-12. 11.]
@ -383,7 +383,7 @@ class MatrixDiagPart(PrimitiveWithInfer):
Examples: Examples:
>>> x = Tensor([[[-1, 0], [0, 1]], [[-1, 0], [0, 1]], [[-1, 0], [0, 1]]], mindspore.float32) >>> x = Tensor([[[-1, 0], [0, 1]], [[-1, 0], [0, 1]], [[-1, 0], [0, 1]]], mindspore.float32)
>>> assist = Tensor(np.arange(-12, 0).reshape(3, 2, 2), mindspore.float32) >>> assist = Tensor(np.arange(-12, 0).reshape(3, 2, 2), mindspore.float32)
>>> matrix_diag_part = P.MatrixDiagPart() >>> matrix_diag_part = ops.MatrixDiagPart()
>>> result = matrix_diag_part(x, assist) >>> result = matrix_diag_part(x, assist)
>>> print(result) >>> print(result)
[[12., -9.], [8., -5.], [4., -1.]] [[12., -9.], [8., -5.], [4., -1.]]
@ -426,7 +426,7 @@ class MatrixSetDiag(PrimitiveWithInfer):
Examples: Examples:
>>> x = Tensor([[[-1, 0], [0, 1]], [[-1, 0], [0, 1]], [[-1, 0], [0, 1]]], mindspore.float32) >>> x = Tensor([[[-1, 0], [0, 1]], [[-1, 0], [0, 1]], [[-1, 0], [0, 1]]], mindspore.float32)
>>> diagonal = Tensor([[-1., 2.], [-1., 1.], [-1., 1.]], mindspore.float32) >>> diagonal = Tensor([[-1., 2.], [-1., 1.], [-1., 1.]], mindspore.float32)
>>> matrix_set_diag = P.MatrixSetDiag() >>> matrix_set_diag = ops.MatrixSetDiag()
>>> result = matrix_set_diag(x, diagonal) >>> result = matrix_set_diag(x, diagonal)
>>> print(result) >>> print(result)
[[[-1, 0], [0, 2]], [[-1, 0], [0, 1]], [[-1, 0], [0, 1]]] [[[-1, 0], [0, 2]], [[-1, 0], [0, 1]], [[-1, 0], [0, 1]]]
@ -523,7 +523,7 @@ class DynamicGRUV2(PrimitiveWithInfer):
>>> bias_i = Tensor(np.random.rand(48).astype(np.float16)) >>> bias_i = Tensor(np.random.rand(48).astype(np.float16))
>>> bias_h = Tensor(np.random.rand(48).astype(np.float16)) >>> bias_h = Tensor(np.random.rand(48).astype(np.float16))
>>> init_h = Tensor(np.random.rand(8, 16).astype(np.float16)) >>> init_h = Tensor(np.random.rand(8, 16).astype(np.float16))
>>> dynamic_gru_v2 = P.DynamicGRUV2() >>> dynamic_gru_v2 = ops.DynamicGRUV2()
>>> output = dynamic_gru_v2(x, weight_i, weight_h, bias_i, bias_h, None, init_h) >>> output = dynamic_gru_v2(x, weight_i, weight_h, bias_i, bias_h, None, init_h)
>>> result = output[0].shape >>> result = output[0].shape
>>> print(result) >>> print(result)
@ -640,7 +640,7 @@ class ConfusionMulGrad(PrimitiveWithInfer):
the shape of output is :math:`(x_1,x_4,...x_R)`. the shape of output is :math:`(x_1,x_4,...x_R)`.
Examples: Examples:
>>> confusion_mul_grad = P.ConfusionMulGrad() >>> confusion_mul_grad = ops.ConfusionMulGrad()
>>> input_0 = Tensor(np.random.randint(-2, 2, (2, 3)), mindspore.float32) >>> input_0 = Tensor(np.random.randint(-2, 2, (2, 3)), mindspore.float32)
>>> input_1 = Tensor(np.random.randint(0, 4, (2, 3)), mindspore.float32) >>> input_1 = Tensor(np.random.randint(0, 4, (2, 3)), mindspore.float32)
>>> input_2 = Tensor(np.random.randint(-4, 0, (2, 3)), mindspore.float32) >>> input_2 = Tensor(np.random.randint(-4, 0, (2, 3)), mindspore.float32)

@ -752,7 +752,7 @@ class BatchNormFoldGrad(PrimitiveWithInfer):
Performs grad of BatchNormFold operation. Performs grad of BatchNormFold operation.
Examples: Examples:
>>> batch_norm_fold_grad = P.BatchNormFoldGrad() >>> batch_norm_fold_grad = ops.BatchNormFoldGrad()
>>> d_batch_mean = Tensor(np.random.randint(-2., 2., (1, 2, 2, 3)), mindspore.float32) >>> d_batch_mean = Tensor(np.random.randint(-2., 2., (1, 2, 2, 3)), mindspore.float32)
>>> d_batch_std = Tensor(np.random.randn(1, 2, 2, 3), mindspore.float32) >>> d_batch_std = Tensor(np.random.randn(1, 2, 2, 3), mindspore.float32)
>>> input_x = Tensor(np.random.randint(0, 256, (4, 1, 4, 6)), mindspore.float32) >>> input_x = Tensor(np.random.randint(0, 256, (4, 1, 4, 6)), mindspore.float32)
@ -809,7 +809,7 @@ class CorrectionMul(PrimitiveWithInfer):
- **out** (Tensor) - Tensor has the same shape as x. - **out** (Tensor) - Tensor has the same shape as x.
Examples: Examples:
>>> correction_mul = P.CorrectionMul() >>> correction_mul = ops.CorrectionMul()
>>> input_x = Tensor(np.random.randint(-8, 12, (3, 4)), mindspore.float32) >>> input_x = Tensor(np.random.randint(-8, 12, (3, 4)), mindspore.float32)
>>> batch_std = Tensor(np.array([1.5, 3, 2]), mindspore.float32) >>> batch_std = Tensor(np.array([1.5, 3, 2]), mindspore.float32)
>>> running_std = Tensor(np.array([2, 1.2, 0.5]), mindspore.float32) >>> running_std = Tensor(np.array([2, 1.2, 0.5]), mindspore.float32)
@ -842,7 +842,7 @@ class CorrectionMulGrad(PrimitiveWithInfer):
Performs grad of CorrectionMul operation. Performs grad of CorrectionMul operation.
Examples: Examples:
>>> correction_mul_grad = P.CorrectionMulGrad() >>> correction_mul_grad = ops.CorrectionMulGrad()
>>> dout = Tensor(np.array([1.5, -2.2, 0.7, -3, 1.6, 2.8]).reshape(2, 1, 1, 3), mindspore.float32) >>> dout = Tensor(np.array([1.5, -2.2, 0.7, -3, 1.6, 2.8]).reshape(2, 1, 1, 3), mindspore.float32)
>>> input_x = Tensor(np.random.randint(0, 256, (2, 1, 1, 3)), mindspore.float32) >>> input_x = Tensor(np.random.randint(0, 256, (2, 1, 1, 3)), mindspore.float32)
>>> gamma = Tensor(np.array([0.2, -0.2, 2.5, -1.]).reshape(2, 1, 2), mindspore.float32) >>> gamma = Tensor(np.array([0.2, -0.2, 2.5, -1.]).reshape(2, 1, 2), mindspore.float32)
@ -882,7 +882,7 @@ class CorrectionMulGradReduce(PrimitiveWithInfer):
Performs grad reduce of CorrectionMul operation. Performs grad reduce of CorrectionMul operation.
Examples: Examples:
>>> correction_mul_grad_rd = P.CorrectionMulGradReduce() >>> correction_mul_grad_rd = ops.CorrectionMulGradReduce()
>>> dout = Tensor(np.array([1.5, -2.2, 0.7, -3, 1.6, 2.8]).reshape(2, 1, 1, 3), mindspore.float32) >>> dout = Tensor(np.array([1.5, -2.2, 0.7, -3, 1.6, 2.8]).reshape(2, 1, 1, 3), mindspore.float32)
>>> input_x = Tensor(np.random.randint(0, 256, (2, 1, 1, 3)), mindspore.float32) >>> input_x = Tensor(np.random.randint(0, 256, (2, 1, 1, 3)), mindspore.float32)
>>> gamma = Tensor(np.array([0.2, -0.2, 2.5, -1.]).reshape(2, 1, 2), mindspore.float32) >>> gamma = Tensor(np.array([0.2, -0.2, 2.5, -1.]).reshape(2, 1, 2), mindspore.float32)
@ -926,7 +926,7 @@ class BatchNormFold2(PrimitiveWithInfer):
- **y** (Tensor) - Tensor has the same shape as x. - **y** (Tensor) - Tensor has the same shape as x.
Examples: Examples:
>>> batch_norm_fold2 = P.BatchNormFold2() >>> batch_norm_fold2 = ops.BatchNormFold2()
>>> input_x = Tensor(np.random.randint(-6, 6, (4, 3)), mindspore.float32) >>> input_x = Tensor(np.random.randint(-6, 6, (4, 3)), mindspore.float32)
>>> beta = Tensor(np.array([0.2, -0.1, 0.25]), mindspore.float32) >>> beta = Tensor(np.array([0.2, -0.1, 0.25]), mindspore.float32)
>>> gamma = Tensor(np.array([-0.1, -0.25, 0.1]), mindspore.float32) >>> gamma = Tensor(np.array([-0.1, -0.25, 0.1]), mindspore.float32)
@ -974,7 +974,7 @@ class BatchNormFold2Grad(PrimitiveWithInfer):
Performs grad of CorrectionAddGrad operation. Performs grad of CorrectionAddGrad operation.
Examples: Examples:
>>> bnf2_grad = P.BatchNormFold2Grad() >>> bnf2_grad = ops.BatchNormFold2Grad()
>>> input_x = Tensor(np.arange(3*3*12*12).reshape(6, 3, 6, 12), mindspore.float32) >>> input_x = Tensor(np.arange(3*3*12*12).reshape(6, 3, 6, 12), mindspore.float32)
>>> dout = Tensor(np.random.randint(-32, 32, (6, 3, 6, 12)), mindspore.float32) >>> dout = Tensor(np.random.randint(-32, 32, (6, 3, 6, 12)), mindspore.float32)
>>> gamma = Tensor(np.random.randint(-4, 4, (3, 1, 1, 2)), mindspore.float32) >>> gamma = Tensor(np.random.randint(-4, 4, (3, 1, 1, 2)), mindspore.float32)

@ -82,7 +82,7 @@ class CusBatchMatMul(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[2, 128, 128]), mindspore.float32) >>> input_x = Tensor(np.ones(shape=[2, 128, 128]), mindspore.float32)
>>> input_y = Tensor(np.ones(shape=[2, 128, 128]), mindspore.float32) >>> input_y = Tensor(np.ones(shape=[2, 128, 128]), mindspore.float32)
>>> cus_batch_matmul = P.CusBatchMatMul() >>> cus_batch_matmul = ops.CusBatchMatMul()
>>> output = cus_batch_matmul(input_x, input_y) >>> output = cus_batch_matmul(input_x, input_y)
""" """
@ -115,7 +115,7 @@ class CusCholeskyTrsm(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[256, 256]), mindspore.float32) >>> input_x = Tensor(np.ones(shape=[256, 256]), mindspore.float32)
>>> cus_choleskytrsm = P.CusCholeskyTrsm() >>> cus_choleskytrsm = ops.CusCholeskyTrsm()
>>> output = matmul(input_x) >>> output = matmul(input_x)
""" """
@ -151,7 +151,7 @@ class CusFusedAbsMax1(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[1, 3]), mindspore.float32) >>> input_x = Tensor(np.ones(shape=[1, 3]), mindspore.float32)
>>> cus_fused_abs_max1 = P.CusFusedAbsMax1() >>> cus_fused_abs_max1 = ops.CusFusedAbsMax1()
>>> output = cus_fused_abs_max1(input_x) >>> output = cus_fused_abs_max1(input_x)
""" """
@ -187,7 +187,7 @@ class CusImg2Col(PrimitiveWithInfer):
Tensor, the shape of the output tensor is :math:`(N * H_O * W_O, C1 * K_W * K_H * C0)`. Tensor, the shape of the output tensor is :math:`(N * H_O * W_O, C1 * K_W * K_H * C0)`.
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[32, 3, 224, 224]), mindspore.float16) >>> input_x = Tensor(np.ones(shape=[32, 3, 224, 224]), mindspore.float16)
>>> cusimg2col = P.CusImg2Col() >>> cusimg2col = ops.CusImg2Col()
>>> output = cusimg2col(input_x) >>> output = cusimg2col(input_x)
""" """
@ -233,7 +233,7 @@ class CusMatMulCubeDenseLeft(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16) >>> input_x = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16)
>>> input_y = Tensor(np.ones(shape=[256, 256]), mindspore.float16) >>> input_y = Tensor(np.ones(shape=[256, 256]), mindspore.float16)
>>> matmulcubedenseleft = P.CusMatMulCubeDenseLeft() >>> matmulcubedenseleft = ops.CusMatMulCubeDenseLeft()
>>> output = matmulcubedenseleft(input_x, input_y) >>> output = matmulcubedenseleft(input_x, input_y)
""" """
@ -268,7 +268,7 @@ class CusMatMulCubeFraczRightMul(PrimitiveWithInfer):
>>> input_x1 = Tensor(np.ones(shape=[256, 256]), mindspore.float16) >>> input_x1 = Tensor(np.ones(shape=[256, 256]), mindspore.float16)
>>> input_x2 = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16) >>> input_x2 = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16)
>>> input_x3 = Tensor(np.ones(shape=[1, ]), mindspore.float16) >>> input_x3 = Tensor(np.ones(shape=[1, ]), mindspore.float16)
>>> cusmatmulfraczrightmul = P.CusMatMulCubeFraczRightMul() >>> cusmatmulfraczrightmul = ops.CusMatMulCubeFraczRightMul()
>>> output = cusmatmulfraczrightmul(input_x1, input_x2, input_x3) >>> output = cusmatmulfraczrightmul(input_x1, input_x2, input_x3)
""" """
@ -307,7 +307,7 @@ class CusMatMulCube(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[256, 256]), mindspore.float16) >>> input_x = Tensor(np.ones(shape=[256, 256]), mindspore.float16)
>>> input_y = Tensor(np.ones(shape=[256, 256]), mindspore.float16) >>> input_y = Tensor(np.ones(shape=[256, 256]), mindspore.float16)
>>> cusmatmulcube = P.CusMatMulCube() >>> cusmatmulcube = ops.CusMatMulCube()
>>> output = matmul(input_x, input_y) >>> output = matmul(input_x, input_y)
""" """
@ -349,7 +349,7 @@ class CusMatrixCombine(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[2, 128, 128]), mindspore.float32) >>> input_x = Tensor(np.ones(shape=[2, 128, 128]), mindspore.float32)
>>> cusmatrixcombine = P.CusMatrixCombine() >>> cusmatrixcombine = ops.CusMatrixCombine()
>>> output = cusmatrixcombine(input_x) >>> output = cusmatrixcombine(input_x)
""" """
@ -383,7 +383,7 @@ class CusTranspose02314(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[32, 1, 224, 224, 16]), mindspore.float16) >>> input_x = Tensor(np.ones(shape=[32, 1, 224, 224, 16]), mindspore.float16)
>>> custranspose02314 = P.CusTranspose02314() >>> custranspose02314 = ops.CusTranspose02314()
>>> output = custranspose02314(input_x) >>> output = custranspose02314(input_x)
""" """
@ -429,7 +429,7 @@ class CusMatMulCubeDenseRight(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[256, 256]), mindspore.float16) >>> input_x = Tensor(np.ones(shape=[256, 256]), mindspore.float16)
>>> input_y = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16) >>> input_y = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16)
>>> cusmatmulcubedenseright = P.CusMatMulCubeDenseRight() >>> cusmatmulcubedenseright = ops.CusMatMulCubeDenseRight()
>>> output = cusmatmulcubedenseright(input_x, input_y) >>> output = cusmatmulcubedenseright(input_x, input_y)
""" """
@ -464,7 +464,7 @@ class CusMatMulCubeFraczLeftCast(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16) >>> input_x = Tensor(np.ones(shape=[16, 16, 16, 16]), mindspore.float16)
>>> input_y = Tensor(np.ones(shape=[256, 256]), mindspore.float16) >>> input_y = Tensor(np.ones(shape=[256, 256]), mindspore.float16)
>>> cusmatmulcubefraczleftcast = P.CusMatMulCubeFraczLeftCast() >>> cusmatmulcubefraczleftcast = ops.CusMatMulCubeFraczLeftCast()
>>> output = cusmatmulcubefraczleftcast(input_x, input_y) >>> output = cusmatmulcubefraczleftcast(input_x, input_y)
""" """
@ -494,7 +494,7 @@ class Im2Col(PrimitiveWithInfer):
Tensor. Tensor.
Examples: Examples:
>>> input_x = Tensor(np.random.rand(32, 3, 224, 224).astype(np.float16)) >>> input_x = Tensor(np.random.rand(32, 3, 224, 224).astype(np.float16))
>>> img2col = P.CusMatMulCubeDenseLeft(kernel_size=7, pad=3, stride=2) >>> img2col = ops.CusMatMulCubeDenseLeft(kernel_size=7, pad=3, stride=2)
>>> output = img2col(input_x) >>> output = img2col(input_x)
""" """
@ -587,7 +587,7 @@ class UpdateThorGradient(PrimitiveWithInfer):
>>> for i in range(16): >>> for i in range(16):
... input_x3[i,:,:,:] = temp_x3 ... input_x3[i,:,:,:] = temp_x3
>>> input_x3 = Tensor(input_x3) >>> input_x3 = Tensor(input_x3)
>>> update_thor_gradient = P.UpdateThorGradient(split_dim=128) >>> update_thor_gradient = ops.UpdateThorGradient(split_dim=128)
>>> output = update_thor_gradient(input_x1, input_x2, input_x3) >>> output = update_thor_gradient(input_x1, input_x2, input_x3)
""" """

File diff suppressed because it is too large Load Diff

@ -78,13 +78,13 @@ class AllReduce(PrimitiveWithInfer):
>>> from mindspore import Tensor >>> from mindspore import Tensor
>>> from mindspore.ops.operations.comm_ops import ReduceOp >>> from mindspore.ops.operations.comm_ops import ReduceOp
>>> import mindspore.nn as nn >>> import mindspore.nn as nn
>>> import mindspore.ops.operations as P >>> import mindspore.ops.operations as ops
>>> >>>
>>> init() >>> init()
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.allreduce_sum = P.AllReduce(ReduceOp.SUM, group="nccl_world_group") ... self.allreduce_sum = ops.AllReduce(ReduceOp.SUM, group="nccl_world_group")
... ...
... def construct(self, x): ... def construct(self, x):
... return self.allreduce_sum(x) ... return self.allreduce_sum(x)
@ -134,7 +134,7 @@ class Send(PrimitiveWithInfer):
- **input_x** (Tensor) - The shape of tensor is :math:`(x_1, x_2, ..., x_R)`. - **input_x** (Tensor) - The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
Examples: Examples:
>>> import mindspore.ops.operations as P >>> import mindspore.ops.operations as ops
>>> import mindspore.nn as nn >>> import mindspore.nn as nn
>>> from mindspore.communication import init >>> from mindspore.communication import init
>>> from mindspore import Tensor >>> from mindspore import Tensor
@ -144,8 +144,8 @@ class Send(PrimitiveWithInfer):
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
>>> def __init__(self): >>> def __init__(self):
>>> super(Net, self).__init__() >>> super(Net, self).__init__()
>>> self.depend = P.Depend() >>> self.depend = ops.Depend()
>>> self.send = P.Send(st_tag=0, dest_rank=8, group="hccl_world_group") >>> self.send = ops.Send(st_tag=0, dest_rank=8, group="hccl_world_group")
>>> >>>
>>> def construct(self, x): >>> def construct(self, x):
>>> out = self.depend(x, self.send(x)) >>> out = self.depend(x, self.send(x))
@ -191,7 +191,7 @@ class Receive(PrimitiveWithInfer):
- **input_x** (Tensor) - The shape of tensor is :math:`(x_1, x_2, ..., x_R)`. - **input_x** (Tensor) - The shape of tensor is :math:`(x_1, x_2, ..., x_R)`.
Examples: Examples:
>>> import mindspore.ops.operations as P >>> import mindspore.ops.operations as ops
>>> import mindspore.nn as nn >>> import mindspore.nn as nn
>>> from mindspore.communication import init >>> from mindspore.communication import init
>>> from mindspore import Tensor >>> from mindspore import Tensor
@ -201,7 +201,7 @@ class Receive(PrimitiveWithInfer):
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
>>> def __init__(self): >>> def __init__(self):
>>> super(Net, self).__init__() >>> super(Net, self).__init__()
>>> self.recv = P.Receive(st_tag=0, src_rank=0, shape=[2, 8], dtype=np.float32, >>> self.recv = ops.Receive(st_tag=0, src_rank=0, shape=[2, 8], dtype=np.float32,
>>> group="hccl_world_group") >>> group="hccl_world_group")
>>> >>>
>>> def construct(self, x): >>> def construct(self, x):
@ -253,7 +253,7 @@ class AllGather(PrimitiveWithInfer):
``Ascend`` ``GPU`` ``Ascend`` ``GPU``
Examples: Examples:
>>> import mindspore.ops.operations as P >>> import mindspore.ops.operations as ops
>>> import mindspore.nn as nn >>> import mindspore.nn as nn
>>> from mindspore.communication import init >>> from mindspore.communication import init
>>> from mindspore import Tensor >>> from mindspore import Tensor
@ -262,7 +262,7 @@ class AllGather(PrimitiveWithInfer):
... class Net(nn.Cell): ... class Net(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.allgather = P.AllGather(group="nccl_world_group") ... self.allgather = ops.AllGather(group="nccl_world_group")
... ...
... def construct(self, x): ... def construct(self, x):
... return self.allgather(x) ... return self.allgather(x)
@ -373,14 +373,14 @@ class ReduceScatter(PrimitiveWithInfer):
>>> from mindspore.communication import init >>> from mindspore.communication import init
>>> from mindspore.ops.operations.comm_ops import ReduceOp >>> from mindspore.ops.operations.comm_ops import ReduceOp
>>> import mindspore.nn as nn >>> import mindspore.nn as nn
>>> import mindspore.ops.operations as P >>> import mindspore.ops.operations as ops
>>> import numpy as np >>> import numpy as np
>>> >>>
>>> init() >>> init()
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.reducescatter = P.ReduceScatter(ReduceOp.SUM) ... self.reducescatter = ops.ReduceScatter(ReduceOp.SUM)
... ...
... def construct(self, x): ... def construct(self, x):
... return self.reducescatter(x) ... return self.reducescatter(x)
@ -493,14 +493,14 @@ class Broadcast(PrimitiveWithInfer):
>>> from mindspore import Tensor >>> from mindspore import Tensor
>>> from mindspore.communication import init >>> from mindspore.communication import init
>>> import mindspore.nn as nn >>> import mindspore.nn as nn
>>> import mindspore.ops.operations as P >>> import mindspore.ops.operations as ops
>>> import numpy as np >>> import numpy as np
>>> >>>
>>> init() >>> init()
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.broadcast = P.Broadcast(1) ... self.broadcast = ops.Broadcast(1)
... ...
... def construct(self, x): ... def construct(self, x):
... return self.broadcast((x,)) ... return self.broadcast((x,))

@ -57,7 +57,7 @@ class ControlDepend(Primitive):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.control_depend = P.ControlDepend() ... self.control_depend = P.ControlDepend()
... self.softmax = P.Softmax() ... self.softmax = ops.Softmax()
... ...
... def construct(self, x, y): ... def construct(self, x, y):
... mul = x * y ... mul = x * y
@ -104,12 +104,12 @@ class GeSwitch(PrimitiveWithInfer):
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.square = P.Square() ... self.square = ops.Square()
... self.add = P.TensorAdd() ... self.add = ops.TensorAdd()
... self.value = Tensor(np.full((1), 3), mindspore.float32) ... self.value = Tensor(np.full((1), 3), mindspore.float32)
... self.switch = P.GeSwitch() ... self.switch = ops.GeSwitch()
... self.merge = P.Merge() ... self.merge = ops.Merge()
... self.less = P.Less() ... self.less = ops.Less()
... ...
... def construct(self, x, y): ... def construct(self, x, y):
... cond = self.less(x, y) ... cond = self.less(x, y)
@ -159,7 +159,7 @@ class Merge(PrimitiveWithInfer):
tuple. Output is tuple(`data`, `output_index`). The `data` has the same shape of `inputs` element. tuple. Output is tuple(`data`, `output_index`). The `data` has the same shape of `inputs` element.
Examples: Examples:
>>> merge = P.Merge() >>> merge = ops.Merge()
>>> input_x = Tensor(np.linspace(0, 8, 8).reshape(2, 4), mindspore.float32) >>> input_x = Tensor(np.linspace(0, 8, 8).reshape(2, 4), mindspore.float32)
>>> input_y = Tensor(np.random.randint(-4, 4, (2, 4)), mindspore.float32) >>> input_y = Tensor(np.random.randint(-4, 4, (2, 4)), mindspore.float32)
>>> result = merge((input_x, input_y)) >>> result = merge((input_x, input_y))

@ -55,8 +55,8 @@ class ScalarSummary(PrimitiveWithInfer):
>>> class SummaryDemo(nn.Cell): >>> class SummaryDemo(nn.Cell):
... def __init__(self,): ... def __init__(self,):
... super(SummaryDemo, self).__init__() ... super(SummaryDemo, self).__init__()
... self.summary = P.ScalarSummary() ... self.summary = ops.ScalarSummary()
... self.add = P.TensorAdd() ... self.add = ops.TensorAdd()
... ...
... def construct(self, x, y): ... def construct(self, x, y):
... name = "x" ... name = "x"
@ -97,7 +97,7 @@ class ImageSummary(PrimitiveWithInfer):
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.summary = P.ImageSummary() ... self.summary = ops.ImageSummary()
... ...
... def construct(self, x): ... def construct(self, x):
... name = "image" ... name = "image"
@ -138,8 +138,8 @@ class TensorSummary(PrimitiveWithInfer):
>>> class SummaryDemo(nn.Cell): >>> class SummaryDemo(nn.Cell):
... def __init__(self,): ... def __init__(self,):
... super(SummaryDemo, self).__init__() ... super(SummaryDemo, self).__init__()
... self.summary = P.TensorSummary() ... self.summary = ops.TensorSummary()
... self.add = P.TensorAdd() ... self.add = ops.TensorAdd()
... ...
... def construct(self, x, y): ... def construct(self, x, y):
... x = self.add(x, y) ... x = self.add(x, y)
@ -180,8 +180,8 @@ class HistogramSummary(PrimitiveWithInfer):
>>> class SummaryDemo(nn.Cell): >>> class SummaryDemo(nn.Cell):
... def __init__(self,): ... def __init__(self,):
... super(SummaryDemo, self).__init__() ... super(SummaryDemo, self).__init__()
... self.summary = P.HistogramSummary() ... self.summary = ops.HistogramSummary()
... self.add = P.TensorAdd() ... self.add = ops.TensorAdd()
... ...
... def construct(self, x, y): ... def construct(self, x, y):
... x = self.add(x, y) ... x = self.add(x, y)
@ -234,8 +234,8 @@ class InsertGradientOf(PrimitiveWithInfer):
... ...
... return ret ... return ret
... ...
>>> clip = P.InsertGradientOf(clip_gradient) >>> clip = ops.InsertGradientOf(clip_gradient)
>>> grad_all = C.GradOperation(get_all=True) >>> grad_all = ops.GradOperation(get_all=True)
>>> def InsertGradientOfClipDemo(): >>> def InsertGradientOfClipDemo():
... def clip_test(x, y): ... def clip_test(x, y):
... x = clip(x) ... x = clip(x)
@ -289,7 +289,7 @@ class HookBackward(PrimitiveWithInfer):
... print(grad_out) ... print(grad_out)
... ...
>>> grad_all = GradOperation(get_all=True) >>> grad_all = GradOperation(get_all=True)
>>> hook = P.HookBackward(hook_fn) >>> hook = ops.HookBackward(hook_fn)
>>> def hook_test(x, y): >>> def hook_test(x, y):
... z = x * y ... z = x * y
... z = hook(z) ... z = hook(z)
@ -341,7 +341,7 @@ class Print(PrimitiveWithInfer):
>>> class PrintDemo(nn.Cell): >>> class PrintDemo(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(PrintDemo, self).__init__() ... super(PrintDemo, self).__init__()
... self.print = P.Print() ... self.print = ops.Print()
... ...
... def construct(self, x, y): ... def construct(self, x, y):
... self.print('Print Tensor x and Tensor y:', x, y) ... self.print('Print Tensor x and Tensor y:', x, y)
@ -382,8 +382,8 @@ class Assert(PrimitiveWithInfer):
>>> class AssertDemo(nn.Cell): >>> class AssertDemo(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(AssertDemo, self).__init__() ... super(AssertDemo, self).__init__()
... self.assert1 = P.Assert(summarize=10) ... self.assert1 = ops.Assert(summarize=10)
... self.add = P.TensorAdd() ... self.add = ops.TensorAdd()
... ...
... def construct(self, x, y): ... def construct(self, x, y):
... data = self.add(x, y) ... data = self.add(x, y)

@ -60,7 +60,7 @@ class CropAndResize(PrimitiveWithInfer):
>>> class CropAndResizeNet(nn.Cell): >>> class CropAndResizeNet(nn.Cell):
... def __init__(self, crop_size): ... def __init__(self, crop_size):
... super(CropAndResizeNet, self).__init__() ... super(CropAndResizeNet, self).__init__()
... self.crop_and_resize = P.CropAndResize() ... self.crop_and_resize = ops.CropAndResize()
... self.crop_size = crop_size ... self.crop_size = crop_size
... ...
... def construct(self, x, boxes, box_index): ... def construct(self, x, boxes, box_index):

@ -36,7 +36,7 @@ class ScalarCast(PrimitiveWithInfer):
``Ascend`` ``GPU`` ``CPU`` ``Ascend`` ``GPU`` ``CPU``
Examples: Examples:
>>> scalar_cast = P.ScalarCast() >>> scalar_cast = ops.ScalarCast()
>>> output = scalar_cast(255.0, mindspore.int32) >>> output = scalar_cast(255.0, mindspore.int32)
>>> print(output) >>> print(output)
255 255

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -47,7 +47,7 @@ class Assign(PrimitiveWithCheck):
... self.y = mindspore.Parameter(Tensor([1.0], mindspore.float32), name="y") ... self.y = mindspore.Parameter(Tensor([1.0], mindspore.float32), name="y")
... ...
... def construct(self, x): ... def construct(self, x):
... P.Assign()(self.y, x) ... ops.Assign()(self.y, x)
... return self.y ... return self.y
... ...
>>> x = Tensor([2.0], mindspore.float32) >>> x = Tensor([2.0], mindspore.float32)
@ -85,7 +85,7 @@ class InplaceAssign(PrimitiveWithInfer):
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.inplace_assign = P.InplaceAssign() ... self.inplace_assign = ops.InplaceAssign()
... ...
... def construct(self, x): ... def construct(self, x):
... val = x - 1.0 ... val = x - 1.0
@ -129,7 +129,7 @@ class BoundingBoxEncode(PrimitiveWithInfer):
Examples: Examples:
>>> anchor_box = Tensor([[4,1,2,1],[2,2,2,3]],mindspore.float32) >>> anchor_box = Tensor([[4,1,2,1],[2,2,2,3]],mindspore.float32)
>>> groundtruth_box = Tensor([[3,1,2,2],[1,2,1,4]],mindspore.float32) >>> groundtruth_box = Tensor([[3,1,2,2],[1,2,1,4]],mindspore.float32)
>>> boundingbox_encode = P.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)) >>> boundingbox_encode = ops.BoundingBoxEncode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0))
>>> output = boundingbox_encode(anchor_box, groundtruth_box) >>> output = boundingbox_encode(anchor_box, groundtruth_box)
>>> print(output) >>> print(output)
[[ 5.0000000e-01 5.0000000e-01 -6.5504000e+04 6.9335938e-01] [[ 5.0000000e-01 5.0000000e-01 -6.5504000e+04 6.9335938e-01]
@ -185,7 +185,7 @@ class BoundingBoxDecode(PrimitiveWithInfer):
Examples: Examples:
>>> anchor_box = Tensor([[4,1,2,1],[2,2,2,3]],mindspore.float32) >>> anchor_box = Tensor([[4,1,2,1],[2,2,2,3]],mindspore.float32)
>>> deltas = Tensor([[3,1,2,2],[1,2,1,4]],mindspore.float32) >>> deltas = Tensor([[3,1,2,2],[1,2,1,4]],mindspore.float32)
>>> boundingbox_decode = P.BoundingBoxDecode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0), >>> boundingbox_decode = ops.BoundingBoxDecode(means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0),
... max_shape=(768, 1280), wh_ratio_clip=0.016) ... max_shape=(768, 1280), wh_ratio_clip=0.016)
>>> output = boundingbox_decode(anchor_box, deltas) >>> output = boundingbox_decode(anchor_box, deltas)
>>> print(output) >>> print(output)
@ -245,11 +245,11 @@ class CheckValid(PrimitiveWithInfer):
>>> import mindspore.nn as nn >>> import mindspore.nn as nn
>>> import numpy as np >>> import numpy as np
>>> from mindspore import Tensor >>> from mindspore import Tensor
>>> from mindspore.ops import operations as P >>> from mindspore.ops import operations as ops
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.check_valid = P.CheckValid() ... self.check_valid = ops.CheckValid()
... def construct(self, x, y): ... def construct(self, x, y):
... valid_result = self.check_valid(x, y) ... valid_result = self.check_valid(x, y)
... return valid_result ... return valid_result
@ -313,7 +313,7 @@ class IOU(PrimitiveWithInfer):
``Ascend`` ``GPU`` ``Ascend`` ``GPU``
Examples: Examples:
>>> iou = P.IOU() >>> iou = ops.IOU()
>>> anchor_boxes = Tensor(np.random.randint(1.0, 5.0, [3, 4]), mindspore.float16) >>> anchor_boxes = Tensor(np.random.randint(1.0, 5.0, [3, 4]), mindspore.float16)
>>> gt_boxes = Tensor(np.random.randint(1.0, 5.0, [3, 4]), mindspore.float16) >>> gt_boxes = Tensor(np.random.randint(1.0, 5.0, [3, 4]), mindspore.float16)
>>> output = iou(anchor_boxes, gt_boxes) >>> output = iou(anchor_boxes, gt_boxes)
@ -363,16 +363,16 @@ class MakeRefKey(Primitive):
``Ascend`` ``GPU`` ``CPU`` ``Ascend`` ``GPU`` ``CPU``
Examples: Examples:
>>> from mindspore.ops import functional as F >>> from mindspore.ops import functional as ops
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
... def __init__(self): ... def __init__(self):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.y = mindspore.Parameter(Tensor(np.ones([6, 8, 10]), mindspore.int32), name="y") ... self.y = mindspore.Parameter(Tensor(np.ones([6, 8, 10]), mindspore.int32), name="y")
... self.make_ref_key = P.MakeRefKey("y") ... self.make_ref_key = ops.MakeRefKey("y")
... ...
... def construct(self, x): ... def construct(self, x):
... key = self.make_ref_key() ... key = self.make_ref_key()
... ref = F.make_ref(key, x, self.y) ... ref = ops.make_ref(key, x, self.y)
... return ref * x ... return ref * x
... ...
>>> x = Tensor(np.ones([3, 4, 5]), mindspore.int32) >>> x = Tensor(np.ones([3, 4, 5]), mindspore.int32)
@ -451,7 +451,7 @@ class CheckBprop(PrimitiveWithInfer):
Examples: Examples:
>>> input_x = (Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32),) >>> input_x = (Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32),)
>>> input_y = (Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32),) >>> input_y = (Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32),)
>>> out = P.CheckBprop()(input_x, input_y) >>> out = ops.CheckBprop()(input_x, input_y)
""" """
@prim_attr_register @prim_attr_register
@ -519,7 +519,7 @@ class ConfusionMatrix(PrimitiveWithInfer):
Tensor, the confusion matrix, with shape (`num_classes`, `num_classes`). Tensor, the confusion matrix, with shape (`num_classes`, `num_classes`).
Examples: Examples:
>>> confusion_matrix = P.ConfusionMatrix(4) >>> confusion_matrix = ops.ConfusionMatrix(4)
>>> labels = Tensor([0, 1, 1, 3], mindspore.int32) >>> labels = Tensor([0, 1, 1, 3], mindspore.int32)
>>> predictions = Tensor([1, 2, 1, 3], mindspore.int32) >>> predictions = Tensor([1, 2, 1, 3], mindspore.int32)
>>> output = confusion_matrix(labels, predictions) >>> output = confusion_matrix(labels, predictions)
@ -567,7 +567,7 @@ class PopulationCount(PrimitiveWithInfer):
``Ascend`` ``Ascend``
Examples: Examples:
>>> population_count = P.PopulationCount() >>> population_count = ops.PopulationCount()
>>> x_input = Tensor([0, 1, 3], mindspore.int16) >>> x_input = Tensor([0, 1, 3], mindspore.int16)
>>> output = population_count(x_input) >>> output = population_count(x_input)
>>> print(output) >>> print(output)

@ -39,7 +39,7 @@ class StandardNormal(PrimitiveWithInfer):
Examples: Examples:
>>> shape = (4, 16) >>> shape = (4, 16)
>>> stdnormal = P.StandardNormal(seed=2) >>> stdnormal = ops.StandardNormal(seed=2)
>>> output = stdnormal(shape) >>> output = stdnormal(shape)
>>> result = output.shape >>> result = output.shape
>>> print(result) >>> print(result)
@ -90,7 +90,7 @@ class StandardLaplace(PrimitiveWithInfer):
Examples: Examples:
>>> shape = (4, 16) >>> shape = (4, 16)
>>> stdlaplace = P.StandardLaplace(seed=2) >>> stdlaplace = ops.StandardLaplace(seed=2)
>>> output = stdlaplace(shape) >>> output = stdlaplace(shape)
>>> result = output.shape >>> result = output.shape
>>> print(result) >>> print(result)
@ -148,7 +148,7 @@ class Gamma(PrimitiveWithInfer):
>>> shape = (2, 2) >>> shape = (2, 2)
>>> alpha = Tensor(1.0, mstype.float32) >>> alpha = Tensor(1.0, mstype.float32)
>>> beta = Tensor(1.0, mstype.float32) >>> beta = Tensor(1.0, mstype.float32)
>>> gamma = P.Gamma(seed=3) >>> gamma = ops.Gamma(seed=3)
>>> output = gamma(shape, alpha, beta) >>> output = gamma(shape, alpha, beta)
>>> print(output) >>> print(output)
[[0.21962446 0.33740655] [[0.21962446 0.33740655]
@ -206,7 +206,7 @@ class Poisson(PrimitiveWithInfer):
Examples: Examples:
>>> shape = (4, 16) >>> shape = (4, 16)
>>> mean = Tensor(5.0, mstype.float32) >>> mean = Tensor(5.0, mstype.float32)
>>> poisson = P.Poisson(seed=5) >>> poisson = ops.Poisson(seed=5)
>>> output = poisson(shape, mean) >>> output = poisson(shape, mean)
""" """
@ -265,7 +265,7 @@ class UniformInt(PrimitiveWithInfer):
>>> shape = (2, 4) >>> shape = (2, 4)
>>> minval = Tensor(1, mstype.int32) >>> minval = Tensor(1, mstype.int32)
>>> maxval = Tensor(5, mstype.int32) >>> maxval = Tensor(5, mstype.int32)
>>> uniform_int = P.UniformInt(seed=10) >>> uniform_int = ops.UniformInt(seed=10)
>>> output = uniform_int(shape, minval, maxval) >>> output = uniform_int(shape, minval, maxval)
>>> print(output) >>> print(output)
[[4 2 1 3] [[4 2 1 3]
@ -318,7 +318,7 @@ class UniformReal(PrimitiveWithInfer):
Examples: Examples:
>>> shape = (2, 2) >>> shape = (2, 2)
>>> uniformreal = P.UniformReal(seed=2) >>> uniformreal = ops.UniformReal(seed=2)
>>> output = uniformreal(shape) >>> output = uniformreal(shape)
>>> print(output) >>> print(output)
[[0.4359949 0.18508208] [[0.4359949 0.18508208]
@ -374,7 +374,7 @@ class RandomChoiceWithMask(PrimitiveWithInfer):
``Ascend`` ``GPU`` ``Ascend`` ``GPU``
Examples: Examples:
>>> rnd_choice_mask = P.RandomChoiceWithMask() >>> rnd_choice_mask = ops.RandomChoiceWithMask()
>>> input_x = Tensor(np.ones(shape=[240000, 4]).astype(np.bool)) >>> input_x = Tensor(np.ones(shape=[240000, 4]).astype(np.bool))
>>> output_y, output_mask = rnd_choice_mask(input_x) >>> output_y, output_mask = rnd_choice_mask(input_x)
>>> result = output_y.shape >>> result = output_y.shape
@ -426,7 +426,7 @@ class RandomCategorical(PrimitiveWithInfer):
>>> class Net(nn.Cell): >>> class Net(nn.Cell):
... def __init__(self, num_sample): ... def __init__(self, num_sample):
... super(Net, self).__init__() ... super(Net, self).__init__()
... self.random_categorical = P.RandomCategorical(mindspore.int64) ... self.random_categorical = ops.RandomCategorical(mindspore.int64)
... self.num_sample = num_sample ... self.num_sample = num_sample
... def construct(self, logits, seed=0): ... def construct(self, logits, seed=0):
... return self.random_categorical(logits, self.num_sample, seed) ... return self.random_categorical(logits, self.num_sample, seed)
@ -502,7 +502,7 @@ class Multinomial(PrimitiveWithInfer):
Examples: Examples:
>>> input = Tensor([0., 9., 4., 0.], mstype.float32) >>> input = Tensor([0., 9., 4., 0.], mstype.float32)
>>> multinomial = P.Multinomial(seed=10) >>> multinomial = ops.Multinomial(seed=10)
>>> output = multinomial(input, 2) >>> output = multinomial(input, 2)
""" """
@ -561,7 +561,7 @@ class UniformCandidateSampler(PrimitiveWithInfer):
each of sampled_candidates. Shape: (num_sampled, ). each of sampled_candidates. Shape: (num_sampled, ).
Examples: Examples:
>>> sampler = P.UniformCandidateSampler(1, 3, False, 4) >>> sampler = ops.UniformCandidateSampler(1, 3, False, 4)
>>> output1, output2, output3 = sampler(Tensor(np.array([[1],[3],[4],[6],[3]], dtype=np.int32))) >>> output1, output2, output3 = sampler(Tensor(np.array([[1],[3],[4],[6],[3]], dtype=np.int32)))
>>> print(output1, output2, output3) >>> print(output1, output2, output3)
[1, 1, 3], [[0.75], [0.75], [0.75], [0.75], [0.75]], [0.75, 0.75, 0.75] [1, 1, 3], [[0.75], [0.75], [0.75], [0.75], [0.75]], [0.75, 0.75, 0.75]

@ -38,7 +38,7 @@ class SparseToDense(PrimitiveWithInfer):
>>> indices = Tensor([[0, 1], [1, 2]]) >>> indices = Tensor([[0, 1], [1, 2]])
>>> values = Tensor([1, 2], dtype=ms.float32) >>> values = Tensor([1, 2], dtype=ms.float32)
>>> dense_shape = (3, 4) >>> dense_shape = (3, 4)
>>> out = P.SparseToDense()(indices, values, dense_shape) >>> out = ops.SparseToDense()(indices, values, dense_shape)
""" """
@prim_attr_register @prim_attr_register

Loading…
Cancel
Save