Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
10f381d6
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
10f381d6
编写于
8月 25, 2020
作者:
P
peixu_ren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modify the name of parameters in uniform
上级
f3fd7a55
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
64 addition
and
64 deletion
+64
-64
mindspore/nn/probability/bnn_layers/conv_variational.py
mindspore/nn/probability/bnn_layers/conv_variational.py
+4
-4
mindspore/ops/composite/random_ops.py
mindspore/ops/composite/random_ops.py
+19
-19
mindspore/ops/operations/random_ops.py
mindspore/ops/operations/random_ops.py
+15
-15
tests/st/ops/ascend/test_aicpu_ops/test_uniform_int.py
tests/st/ops/ascend/test_aicpu_ops/test_uniform_int.py
+10
-10
tests/st/ops/ascend/test_compoite_random_ops/test_uniform.py
tests/st/ops/ascend/test_compoite_random_ops/test_uniform.py
+10
-10
tests/st/ops/gpu/test_uniform_real.py
tests/st/ops/gpu/test_uniform_real.py
+6
-6
未找到文件。
mindspore/nn/probability/bnn_layers/conv_variational.py
浏览文件 @
10f381d6
...
...
@@ -250,10 +250,10 @@ class ConvReparam(_ConvVariational):
Tensor of shape :math:`(N, C_{out}, H_{out}, W_{out})`.
Examples:
>>> net = ConvReparam(120, 240, 4, has_bias=False)
>>> input = Tensor(np.ones([1, 120, 1024, 640]), mindspore.float32)
>>> net(input).shape
(1, 240, 1024, 640)
>>> net = ConvReparam(120, 240, 4, has_bias=False)
>>> input = Tensor(np.ones([1, 120, 1024, 640]), mindspore.float32)
>>> net(input).shape
(1, 240, 1024, 640)
"""
def
__init__
(
...
...
mindspore/ops/composite/random_ops.py
浏览文件 @
10f381d6
...
...
@@ -92,55 +92,55 @@ def normal(shape, mean, stddev, seed=0):
value
=
random_normal
*
stddev
+
mean
return
value
def
uniform
(
shape
,
a
,
b
,
seed
=
0
,
dtype
=
mstype
.
float32
):
def
uniform
(
shape
,
minval
,
maxval
,
seed
=
0
,
dtype
=
mstype
.
float32
):
"""
Generates random numbers according to the Uniform random number distribution.
Note:
The number in tensor
a should be strictly less than b
at any position after broadcasting.
The number in tensor
minval should be strictly less than maxval
at any position after broadcasting.
Args:
shape (tuple): The shape of random tensor to be generated.
a
(Tensor): The a distribution parameter.
minval
(Tensor): The a distribution parameter.
It defines the minimum possibly generated value. With int32 or float32 data type.
If dtype is int32, only one number is allowed.
b
(Tensor): The b distribution parameter.
maxval
(Tensor): The b distribution parameter.
It defines the maximum possibly generated value. With int32 or float32 data type.
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.
Must be non-negative. Default: 0.
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
minval and maxval
.
The dtype is designated as the input `dtype`.
Examples:
>>> For discrete uniform distribution, only one number is allowed for both
a and b
:
>>> For discrete uniform distribution, only one number is allowed for both
minval and maxval
:
>>> shape = (4, 2)
>>>
a
= Tensor(1, mstype.int32)
>>>
b
= Tensor(2, mstype.int32)
>>> output = C.uniform(shape,
a, b
, seed=5)
>>>
minval
= Tensor(1, mstype.int32)
>>>
maxval
= Tensor(2, mstype.int32)
>>> output = C.uniform(shape,
minval, maxval
, seed=5)
>>>
>>> For continuous uniform distribution,
a and b
can be multi-dimentional:
>>> For continuous uniform distribution,
minval and maxval
can be multi-dimentional:
>>> shape = (4, 2)
>>>
a
= Tensor([1.0, 2.0], mstype.float32)
>>>
b
= Tensor([4.0, 5.0], mstype.float32)
>>> output = C.uniform(shape,
a, b
, seed=5)
>>>
minval
= Tensor([1.0, 2.0], mstype.float32)
>>>
maxval
= Tensor([4.0, 5.0], mstype.float32)
>>> output = C.uniform(shape,
minval, maxval
, seed=5)
"""
a_dtype
=
F
.
dtype
(
a
)
b_dtype
=
F
.
dtype
(
b
)
const_utils
.
check_tensors_dtype_same
(
a
_dtype
,
dtype
,
"uniform"
)
const_utils
.
check_tensors_dtype_same
(
b
_dtype
,
dtype
,
"uniform"
)
minval_dtype
=
F
.
dtype
(
minval
)
maxval_dtype
=
F
.
dtype
(
maxval
)
const_utils
.
check_tensors_dtype_same
(
minval
_dtype
,
dtype
,
"uniform"
)
const_utils
.
check_tensors_dtype_same
(
maxval
_dtype
,
dtype
,
"uniform"
)
const_utils
.
check_non_negative
(
"seed"
,
seed
,
"uniform"
)
seed1
=
get_seed
()
seed2
=
seed
if
const_utils
.
is_same_type
(
dtype
,
mstype
.
int32
):
random_uniform
=
P
.
UniformInt
(
seed1
,
seed2
)
value
=
random_uniform
(
shape
,
a
,
b
)
value
=
random_uniform
(
shape
,
minval
,
maxval
)
else
:
uniform_real
=
P
.
UniformReal
(
seed1
,
seed2
)
random_uniform
=
uniform_real
(
shape
)
value
=
random_uniform
*
(
b
-
a
)
+
a
value
=
random_uniform
*
(
maxval
-
minval
)
+
minval
return
value
def
gamma
(
shape
,
alpha
,
beta
,
seed
=
0
):
...
...
mindspore/ops/operations/random_ops.py
浏览文件 @
10f381d6
...
...
@@ -224,14 +224,14 @@ class Poisson(PrimitiveWithInfer):
class
UniformInt
(
PrimitiveWithInfer
):
r
"""
Produces random integer values i, uniformly distributed on the closed interval [
a, b
), that is,
Produces random integer values i, uniformly distributed on the closed interval [
minval, maxval
), that is,
distributed according to the discrete probability function:
.. math::
\text{P}(i|a,b) = \frac{1}{b-a+1},
Note:
The number in tensor
a should be strictly less than b
at any position after broadcasting.
The number in tensor
minval should be strictly less than maxval
at any position after broadcasting.
Args:
seed (int): Random seed. Must be non-negative. Default: 0.
...
...
@@ -239,9 +239,9 @@ class UniformInt(PrimitiveWithInfer):
Inputs:
- **shape** (tuple) - The shape of random tensor to be generated. Only constant value is allowed.
- **
a
** (Tensor) - The a distribution parameter.
- **
minval
** (Tensor) - The a distribution parameter.
It defines the minimum possibly generated value. With int32 data type. Only one number is supported.
- **
b
** (Tensor) - The b distribution parameter.
- **
maxval
** (Tensor) - The b distribution parameter.
It defines the maximum possibly generated value. With int32 data type. Only one number is supported.
Outputs:
...
...
@@ -249,32 +249,32 @@ class UniformInt(PrimitiveWithInfer):
Examples:
>>> shape = (4, 16)
>>>
a
= Tensor(1, mstype.int32)
>>>
b
= Tensor(5, mstype.int32)
>>>
minval
= Tensor(1, mstype.int32)
>>>
maxval
= Tensor(5, mstype.int32)
>>> uniform_int = P.UniformInt(seed=10)
>>> output = uniform_int(shape,
a, b
)
>>> output = uniform_int(shape,
minval, maxval
)
"""
@
prim_attr_register
def
__init__
(
self
,
seed
=
0
,
seed2
=
0
):
"""Init UniformInt"""
self
.
init_prim_io_names
(
inputs
=
[
'shape'
,
'
a'
,
'b
'
],
outputs
=
[
'output'
])
self
.
init_prim_io_names
(
inputs
=
[
'shape'
,
'
minval'
,
'maxval
'
],
outputs
=
[
'output'
])
validator
.
check_integer
(
"seed"
,
seed
,
0
,
Rel
.
GE
,
self
.
name
)
validator
.
check_integer
(
"seed2"
,
seed2
,
0
,
Rel
.
GE
,
self
.
name
)
def
__infer__
(
self
,
shape
,
a
,
b
):
def
__infer__
(
self
,
shape
,
minval
,
maxval
):
shape_v
=
shape
[
"value"
]
if
shape_v
is
None
:
raise
ValueError
(
f
"For
{
self
.
name
}
, shape must be const."
)
validator
.
check_value_type
(
"shape"
,
shape_v
,
[
tuple
],
self
.
name
)
for
i
,
shape_i
in
enumerate
(
shape_v
):
validator
.
check_integer
(
"shape[%d]"
%
i
,
shape_i
,
0
,
Rel
.
GT
,
self
.
name
)
validator
.
check_tensor_type_same
({
"
a"
:
a
[
"dtype"
]},
[
mstype
.
int32
],
self
.
name
)
validator
.
check_tensor_type_same
({
"
b"
:
b
[
"dtype"
]},
[
mstype
.
int32
],
self
.
name
)
a_shape
=
a
[
'shape'
]
b_shape
=
b
[
'shape'
]
validator
.
check
(
"dim of
a"
,
len
(
a
_shape
),
'0(scalar)'
,
0
,
Rel
.
EQ
,
self
.
name
)
validator
.
check
(
"dim of
b"
,
len
(
b
_shape
),
'0(scalar)'
,
0
,
Rel
.
EQ
,
self
.
name
)
validator
.
check_tensor_type_same
({
"
minval"
:
minval
[
"dtype"
]},
[
mstype
.
int32
],
self
.
name
)
validator
.
check_tensor_type_same
({
"
maxval"
:
maxval
[
"dtype"
]},
[
mstype
.
int32
],
self
.
name
)
minval_shape
=
minval
[
'shape'
]
maxval_shape
=
maxval
[
'shape'
]
validator
.
check
(
"dim of
minval"
,
len
(
minval
_shape
),
'0(scalar)'
,
0
,
Rel
.
EQ
,
self
.
name
)
validator
.
check
(
"dim of
maxval"
,
len
(
maxval
_shape
),
'0(scalar)'
,
0
,
Rel
.
EQ
,
self
.
name
)
out
=
{
'shape'
:
shape_v
,
'dtype'
:
mstype
.
int32
,
...
...
tests/st/ops/ascend/test_aicpu_ops/test_uniform_int.py
浏览文件 @
10f381d6
...
...
@@ -28,28 +28,28 @@ class Net(nn.Cell):
self
.
uniformint
=
P
.
UniformInt
(
seed
=
seed
)
self
.
shape
=
shape
def
construct
(
self
,
a
,
b
):
return
self
.
uniformint
(
self
.
shape
,
a
,
b
)
def
construct
(
self
,
minval
,
maxval
):
return
self
.
uniformint
(
self
.
shape
,
minval
,
maxval
)
def
test_net_1D
():
seed
=
10
shape
=
(
3
,
2
,
4
)
a
=
1
b
=
5
minval
=
1
maxval
=
5
net
=
Net
(
shape
,
seed
=
seed
)
t
a
,
tb
=
Tensor
(
a
,
mstype
.
int32
),
Tensor
(
b
,
mstype
.
int32
)
output
=
net
(
t
a
,
tb
)
t
minval
,
tmaxval
=
Tensor
(
minval
,
mstype
.
int32
),
Tensor
(
maxval
,
mstype
.
int32
)
output
=
net
(
t
minval
,
tmaxval
)
assert
output
.
shape
==
(
3
,
2
,
4
)
def
test_net_ND
():
seed
=
10
shape
=
(
3
,
2
,
1
)
a
=
np
.
array
([[[
1
,
2
]],
[[
3
,
4
]],
[[
5
,
6
]]]).
astype
(
np
.
int32
)
b
=
np
.
array
([
10
]).
astype
(
np
.
int32
)
minval
=
np
.
array
([[[
1
,
2
]],
[[
3
,
4
]],
[[
5
,
6
]]]).
astype
(
np
.
int32
)
maxval
=
np
.
array
([
10
]).
astype
(
np
.
int32
)
net
=
Net
(
shape
,
seed
)
t
a
,
tb
=
Tensor
(
a
),
Tensor
(
b
)
output
=
net
(
t
a
,
tb
)
t
minval
,
tmaxval
=
Tensor
(
minval
),
Tensor
(
maxval
)
output
=
net
(
t
minval
,
tmaxval
)
print
(
output
.
asnumpy
())
assert
output
.
shape
==
(
3
,
2
,
2
)
tests/st/ops/ascend/test_compoite_random_ops/test_uniform.py
浏览文件 @
10f381d6
...
...
@@ -29,28 +29,28 @@ class Net(nn.Cell):
self
.
shape
=
shape
self
.
seed
=
seed
def
construct
(
self
,
a
,
b
):
def
construct
(
self
,
minval
,
maxval
):
C
.
set_seed
(
20
)
return
C
.
uniform
(
self
.
shape
,
a
,
b
,
self
.
seed
)
return
C
.
uniform
(
self
.
shape
,
minval
,
maxval
,
self
.
seed
)
def
test_net_1D
():
seed
=
10
shape
=
(
3
,
2
,
4
)
a
=
1.0
b
=
6.0
minval
=
1.0
maxval
=
6.0
net
=
Net
(
shape
,
seed
)
t
a
,
tb
=
Tensor
(
a
,
mstype
.
float32
),
Tensor
(
b
,
mstype
.
float32
)
output
=
net
(
t
a
,
tb
)
t
minval
,
tmaxval
=
Tensor
(
minval
,
mstype
.
float32
),
Tensor
(
maxval
,
mstype
.
float32
)
output
=
net
(
t
minval
,
tmaxval
)
assert
output
.
shape
==
(
3
,
2
,
4
)
def
test_net_ND
():
seed
=
10
shape
=
(
3
,
1
,
2
)
a
=
np
.
array
([[[
1
],
[
2
]],
[[
3
],
[
4
]],
[[
5
],
[
6
]]]).
astype
(
np
.
float32
)
b
=
np
.
array
([
1.0
]).
astype
(
np
.
float32
)
minval
=
np
.
array
([[[
1
],
[
2
]],
[[
3
],
[
4
]],
[[
5
],
[
6
]]]).
astype
(
np
.
float32
)
maxval
=
np
.
array
([
1.0
]).
astype
(
np
.
float32
)
net
=
Net
(
shape
,
seed
)
t
a
,
tb
=
Tensor
(
a
,
mstype
.
float32
),
Tensor
(
b
,
mstype
.
float32
)
output
=
net
(
t
a
,
tb
)
t
minval
,
tmaxval
=
Tensor
(
minval
,
mstype
.
float32
),
Tensor
(
maxval
,
mstype
.
float32
)
output
=
net
(
t
minval
,
tmaxval
)
assert
output
.
shape
==
(
3
,
2
,
2
)
tests/st/ops/gpu/test_uniform_real.py
浏览文件 @
10f381d6
...
...
@@ -27,17 +27,17 @@ class Net(nn.Cell):
self
.
uniformreal
=
P
.
UniformReal
(
seed
=
seed
)
self
.
shape
=
shape
def
construct
(
self
,
a
,
b
):
return
self
.
uniformreal
(
self
.
shape
,
a
,
b
)
def
construct
(
self
,
minval
,
maxval
):
return
self
.
uniformreal
(
self
.
shape
,
minval
,
maxval
)
def
test_net_1D
():
seed
=
10
shape
=
(
3
,
2
,
4
)
a
=
0.0
b
=
1.0
minval
=
0.0
maxval
=
1.0
net
=
Net
(
shape
,
seed
)
t
a
,
tb
=
Tensor
(
a
,
mstype
.
float32
),
Tensor
(
b
,
mstype
.
float32
)
output
=
net
(
t
a
,
tb
)
t
minval
,
tmaxval
=
Tensor
(
minval
,
mstype
.
float32
),
Tensor
(
maxval
,
mstype
.
float32
)
output
=
net
(
t
minval
,
tmaxval
)
print
(
output
.
asnumpy
())
assert
output
.
shape
==
(
3
,
2
,
4
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录