!4712 Fix bugs in random ops

Merge pull request !4712 from peixu_ren/custom_pp_ops
This commit is contained in:
mindspore-ci-bot 2020-08-19 10:54:52 +08:00 committed by Gitee
commit 3259dafa7e
2 changed files with 17 additions and 23 deletions

View File

@ -35,12 +35,12 @@ def set_seed(seed):
random seed. random seed.
Args: Args:
seed(Int): the graph-level seed value that to be set. seed(Int): the graph-level seed value that to be set. Must be non-negative.
Examples: Examples:
>>> C.set_seed(10) >>> C.set_seed(10)
""" """
const_utils.check_int_positive("seed", seed, "set_seed") const_utils.check_non_negative("seed", seed, "set_seed")
global _GRAPH_SEED global _GRAPH_SEED
_GRAPH_SEED = seed _GRAPH_SEED = seed
@ -56,7 +56,7 @@ def get_seed():
Interger. The current graph-level seed. Interger. The current graph-level seed.
Examples: Examples:
>>> C.get_seed(10) >>> C.get_seed()
""" """
return _GRAPH_SEED return _GRAPH_SEED
@ -70,7 +70,7 @@ def normal(shape, mean, stddev, seed=0):
With float32 data type. With float32 data type.
stddev (Tensor): The deviation σ distribution parameter. With float32 data type. stddev (Tensor): The deviation σ distribution parameter. With float32 data type.
seed (int): Seed is used as entropy source for Random number engines generating pseudo-random numbers. seed (int): Seed is used as entropy source for Random number engines generating pseudo-random numbers.
Default: 0. Must be non-negative. Default: 0.
Returns: Returns:
Tensor. The shape should be the broadcasted shape of Input "shape" and shapes of mean and stddev. Tensor. The shape should be the broadcasted shape of Input "shape" and shapes of mean and stddev.
@ -107,7 +107,7 @@ def uniform(shape, a, b, seed=0, dtype=mstype.float32):
It defines the maximum possibly generated value. With int32 or float32 data type. It defines the maximum possibly generated value. With int32 or float32 data type.
If dtype is int32, only one number is allowed. If dtype is int32, only one number is allowed.
seed (int): Seed is used as entropy source for Random number engines generating pseudo-random numbers. seed (int): Seed is used as entropy source for Random number engines generating pseudo-random numbers.
Default: 0. Must be non-negative. Default: 0.
Returns: Returns:
Tensor. The shape should be the broadcasted shape of Input "shape" and shapes of a and b. Tensor. The shape should be the broadcasted shape of Input "shape" and shapes of a and b.
@ -151,7 +151,7 @@ def gamma(shape, alpha, beta, seed=0):
alpha (Tensor): The alpha α distribution parameter. With float32 data type. alpha (Tensor): The alpha α distribution parameter. With float32 data type.
beta (Tensor): The beta β distribution parameter. With float32 data type. beta (Tensor): The beta β distribution parameter. With float32 data type.
seed (int): Seed is used as entropy source for Random number engines generating pseudo-random numbers. seed (int): Seed is used as entropy source for Random number engines generating pseudo-random numbers.
Default: 0. Must be non-negative. Default: 0.
Returns: Returns:
Tensor. The shape should be the broadcasted shape of Input "shape" and shapes of alpha and beta. Tensor. The shape should be the broadcasted shape of Input "shape" and shapes of alpha and beta.
@ -163,10 +163,6 @@ def gamma(shape, alpha, beta, seed=0):
>>> beta = Tensor(1.0, mstype.float32) >>> beta = Tensor(1.0, mstype.float32)
>>> output = C.gamma(shape, alpha, beta, seed=5) >>> output = C.gamma(shape, alpha, beta, seed=5)
""" """
alpha_dtype = F.dtype(alpha)
beta_dtype = F.dtype(beta)
const_utils.check_tensors_dtype_same(alpha_dtype, mstype.float32, "gamma")
const_utils.check_tensors_dtype_same(beta_dtype, mstype.float32, "gamma")
const_utils.check_non_negative("seed", seed, "gamma") const_utils.check_non_negative("seed", seed, "gamma")
seed1 = get_seed() seed1 = get_seed()
seed2 = seed seed2 = seed
@ -182,7 +178,7 @@ def poisson(shape, mean, seed=0):
shape (tuple): The shape of random tensor to be generated. shape (tuple): The shape of random tensor to be generated.
mean (Tensor): The mean μ distribution parameter. With float32 data type. mean (Tensor): The mean μ distribution parameter. With float32 data type.
seed (int): Seed is used as entropy source for Random number engines generating pseudo-random numbers. seed (int): Seed is used as entropy source for Random number engines generating pseudo-random numbers.
Default: 0. Must be non-negative. Default: 0.
Returns: Returns:
Tensor. The shape should be the broadcasted shape of Input "shape" and shapes of mean. Tensor. The shape should be the broadcasted shape of Input "shape" and shapes of mean.
@ -193,8 +189,6 @@ def poisson(shape, mean, seed=0):
>>> mean = Tensor(1.0, mstype.float32) >>> mean = Tensor(1.0, mstype.float32)
>>> output = C.poisson(shape, mean, seed=5) >>> output = C.poisson(shape, mean, seed=5)
""" """
mean_dtype = F.dtype(mean)
const_utils.check_tensors_dtype_same(mean_dtype, mstype.float32, "poisson")
const_utils.check_non_negative("seed", seed, "poisson") const_utils.check_non_negative("seed", seed, "poisson")
seed1 = get_seed() seed1 = get_seed()
seed2 = seed seed2 = seed

View File

@ -27,8 +27,8 @@ class StandardNormal(PrimitiveWithInfer):
Generates random numbers according to the standard Normal (or Gaussian) random number distribution. Generates random numbers according to the standard Normal (or Gaussian) random number distribution.
Args: Args:
seed (int): Random seed. Default: 0. seed (int): Random seed. Must be non-negative. Default: 0.
seed2 (int): Random seed2. Default: 0. seed2 (int): Random seed2. Must be non-negative. Default: 0.
Inputs: Inputs:
- **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed. - **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed.
@ -125,8 +125,8 @@ class Gamma(PrimitiveWithInfer):
\text{P}(x|α,β) = \frac{\exp(-x/β)}{{β^α}\cdot{\Gamma(α)}}\cdot{x^{α-1}}, \text{P}(x|α,β) = \frac{\exp(-x/β)}{{β^α}\cdot{\Gamma(α)}}\cdot{x^{α-1}},
Args: Args:
seed (int): Random seed. Default: 0. seed (int): Random seed. Must be non-negative. Default: 0.
seed2 (int): Random seed2. Default: 0. seed2 (int): Random seed2. Must be non-negative. Default: 0.
Inputs: Inputs:
- **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed. - **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed.
@ -180,8 +180,8 @@ class Poisson(PrimitiveWithInfer):
\text{P}(i|μ) = \frac{\exp(-μ)μ^{i}}{i!}, \text{P}(i|μ) = \frac{\exp(-μ)μ^{i}}{i!},
Args: Args:
seed (int): Random seed. Default: 0. seed (int): Random seed. Must be non-negative. Default: 0.
seed2 (int): Random seed2. Default: 0. seed2 (int): Random seed2. Must be non-negative. Default: 0.
Inputs: Inputs:
- **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed. - **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed.
@ -234,8 +234,8 @@ class UniformInt(PrimitiveWithInfer):
The number in tensor a should be strictly less than b at any position after broadcasting. The number in tensor a should be strictly less than b at any position after broadcasting.
Args: Args:
seed (int): Random seed. Default: 0. seed (int): Random seed. Must be non-negative. Default: 0.
seed2 (int): Random seed2. Default: 0. seed2 (int): Random seed2. Must be non-negative. Default: 0.
Inputs: Inputs:
- **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed. - **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed.
@ -287,8 +287,8 @@ class UniformReal(PrimitiveWithInfer):
Produces random floating-point values i, uniformly distributed on the interval [0, 1). Produces random floating-point values i, uniformly distributed on the interval [0, 1).
Args: Args:
seed (int): Random seed. Default: 0. seed (int): Random seed. Must be non-negative. Default: 0.
seed2 (int): Random seed2. Default: 0. seed2 (int): Random seed2. Must be non-negative. Default: 0.
Inputs: Inputs:
- **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed. - **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed.