From bc2a361823437d9f55d0939d2879daa6f4f41c6b Mon Sep 17 00:00:00 2001 From: fan-jibin Date: Tue, 27 Sep 2022 10:42:38 +0800 Subject: [PATCH] \add random_shuffle docs --- docs/api/api_python/mindspore.ops.function.rst | 1 + .../ops/mindspore.ops.func_shuffle.rst | 16 ++++++++++++++++ .../api/api_python_en/mindspore.ops.function.rst | 1 + .../python/mindspore/ops/function/random_func.py | 7 ++++--- .../mindspore/ops/operations/random_ops.py | 9 +++++---- 5 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 docs/api/api_python/ops/mindspore.ops.func_shuffle.rst diff --git a/docs/api/api_python/mindspore.ops.function.rst b/docs/api/api_python/mindspore.ops.function.rst index b2a0f44a30d..847fef3e841 100644 --- a/docs/api/api_python/mindspore.ops.function.rst +++ b/docs/api/api_python/mindspore.ops.function.rst @@ -282,6 +282,7 @@ Tensor创建 mindspore.ops.random_poisson mindspore.ops.random_categorical mindspore.ops.random_gamma + mindspore.ops.shuffle mindspore.ops.standard_laplace mindspore.ops.standard_normal mindspore.ops.uniform diff --git a/docs/api/api_python/ops/mindspore.ops.func_shuffle.rst b/docs/api/api_python/ops/mindspore.ops.func_shuffle.rst new file mode 100644 index 00000000000..2bb0f0cb253 --- /dev/null +++ b/docs/api/api_python/ops/mindspore.ops.func_shuffle.rst @@ -0,0 +1,16 @@ +mindspore.ops.shuffle +===================== + +.. py:function:: mindspore.ops.shuffle(x, seed=None) + + 沿着Tensor第一维随机打乱数据。 + + 参数: + - **x** (Tensor) - 需要随机打乱的Tensor。 + - **seed** (int) - 随机数种子,用于生成随机数,必须为非负数。如果 `seed` 为0,则替换为随机生成的值。默认值是None, 表示使用0作为随机数种子。 + + 返回: + Tensor,与输入相同的shape和类型。 + + 异常: + - **TypeError** - 如果 `seed` 不是None或非负整数。 diff --git a/docs/api/api_python_en/mindspore.ops.function.rst b/docs/api/api_python_en/mindspore.ops.function.rst index 4f09c897310..c9844591bf9 100644 --- a/docs/api/api_python_en/mindspore.ops.function.rst +++ b/docs/api/api_python_en/mindspore.ops.function.rst @@ -281,6 +281,7 @@ Randomly Generating Functions mindspore.ops.random_poisson mindspore.ops.random_categorical mindspore.ops.random_gamma + mindspore.ops.shuffle mindspore.ops.standard_laplace mindspore.ops.standard_normal mindspore.ops.uniform diff --git a/mindspore/python/mindspore/ops/function/random_func.py b/mindspore/python/mindspore/ops/function/random_func.py index 918e5221899..243741f39fb 100755 --- a/mindspore/python/mindspore/ops/function/random_func.py +++ b/mindspore/python/mindspore/ops/function/random_func.py @@ -397,16 +397,17 @@ def shuffle(x, seed=None): Args: x (Tensor): The Tensor need be shuffled. - seed (int): The operator-level random seed, used to generate random numbers, must be non-negative. Default: 0. + seed (int): Random seed used for random number generation, must be non-negative. If `seed` is 0, which will be + replaced with a randomly generated value. Default: None, which will be treated as 0. Returns: Tensor. The shape and type are the same as the input `x`. Raises: - TypeError: If data type of `seed` or `seed2` is not int. + TypeError: If data type of `seed` is not None or non-negative int. Supported Platforms: - ``CPU`` ``GPU`` + ``Ascend`` ``GPU`` ``CPU`` Examples: >>> x = Tensor(np.array([1, 2, 3, 4]), mstype.float32) diff --git a/mindspore/python/mindspore/ops/operations/random_ops.py b/mindspore/python/mindspore/ops/operations/random_ops.py index bde810f92b4..0c884302a7f 100755 --- a/mindspore/python/mindspore/ops/operations/random_ops.py +++ b/mindspore/python/mindspore/ops/operations/random_ops.py @@ -905,9 +905,10 @@ class RandomShuffle(Primitive): Randomly shuffles a Tensor along its first dimension. Args: - seed (int): The operator-level random seed, used to generate random numbers, must be non-negative. Default: 0. - seed2 (int): The global random seed and it will combile with the operator-level random seed to determine the - final generated random number, must be non-negative. Default: 0. + seed (int): Random seed. If `seed` or `seed2` is set to non-zero, the random number generator will be seeded + by the given seed. Otherwise, it will be seeded randomly. The seed must be non-negative. Default: 0. + seed2 (int): Random seed2, a second seed to avoid seed collision. If `seed` is 0, the `seed2` will be used as + the seed of the random generator. It must be non-negative. Default: 0. Inputs: - **x** (Tensor) - The Tensor need be shuffled. @@ -919,7 +920,7 @@ class RandomShuffle(Primitive): TypeError: If data type of `seed` or `seed2` is not int. Supported Platforms: - ``CPU`` ``GPU`` + ``Ascend`` ``GPU`` ``CPU`` Examples: >>> x = Tensor(np.array([1, 2, 3, 4]), mstype.float32)