Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
fc4dedc0
MegEngine
项目概览
MegEngine 天元
/
MegEngine
接近 2 年 前同步成功
通知
414
Star
4708
Fork
583
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
fc4dedc0
编写于
4月 16, 2020
作者:
M
Megvii Engine Team
提交者:
Xinran Xu
5月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mge/random): add lower bound and higher bound for uniform sampling
GitOrigin-RevId: 2a2c56fd17ea53b805a4a13906a9f9dd8ab0e133
上级
712b87c8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
49 addition
and
1 deletion
+49
-1
python_module/megengine/random/distribution.py
python_module/megengine/random/distribution.py
+5
-1
python_module/test/unit/random/test_random.py
python_module/test/unit/random/test_random.py
+44
-0
未找到文件。
python_module/megengine/random/distribution.py
浏览文件 @
fc4dedc0
...
...
@@ -62,12 +62,16 @@ def gaussian(
@
wrap_io_tensor
def
uniform
(
shape
:
Iterable
[
int
],
low
:
float
=
0
,
high
:
float
=
1
,
comp_node
:
Optional
[
CompNode
]
=
None
,
comp_graph
:
Optional
[
CompGraph
]
=
None
,
)
->
Tensor
:
r
"""Random variable with uniform distribution $U(0, 1)$
:param shape: Output tensor shape
:param low: Lower range
:param high: Upper range
:param comp_node: The comp node output on, default to None
:param comp_graph: The graph in which output is, default to None
:return: The output tensor
...
...
@@ -91,6 +95,6 @@ def uniform(
"""
comp_node
,
comp_graph
=
_use_default_if_none
(
comp_node
,
comp_graph
)
seed
=
_random_seed_generator
().
__next__
()
return
mgb
.
opr
.
uniform_rng
(
return
low
+
(
high
-
low
)
*
mgb
.
opr
.
uniform_rng
(
shape
,
seed
=
seed
,
comp_node
=
comp_node
,
comp_graph
=
comp_graph
)
python_module/test/unit/random/test_random.py
浏览文件 @
fc4dedc0
...
...
@@ -59,6 +59,50 @@ def test_random_dynamic_same_result():
assert
np
.
all
(
a
.
numpy
()
==
b
.
numpy
())
def
test_range_uniform_static_diff_result
():
@
jit
.
trace
(
symbolic
=
True
)
def
graph_a
():
return
R
.
uniform
(
5
,
low
=-
2
,
high
=
2
)
@
jit
.
trace
(
symbolic
=
True
)
def
graph_b
():
return
R
.
uniform
(
5
,
low
=-
2
,
high
=
2
)
a
=
graph_a
()
b
=
graph_b
()
assert
np
.
any
(
a
.
numpy
()
!=
b
.
numpy
())
def
test_range_uniform_static_same_result
():
@
jit
.
trace
(
symbolic
=
True
)
def
graph_a
():
R
.
manual_seed
(
731
)
return
R
.
uniform
(
5
,
low
=-
2
,
high
=
2
)
@
jit
.
trace
(
symbolic
=
True
)
def
graph_b
():
R
.
manual_seed
(
731
)
return
R
.
uniform
(
5
,
low
=-
2
,
high
=
2
)
a
=
graph_a
()
b
=
graph_b
()
assert
np
.
all
(
a
.
numpy
()
==
b
.
numpy
())
def
test_range_uniform_dynamic_diff_result
():
a
=
R
.
uniform
(
5
,
low
=-
2
,
high
=
2
)
b
=
R
.
uniform
(
5
,
low
=-
2
,
high
=
2
)
assert
np
.
any
(
a
.
numpy
()
!=
b
.
numpy
())
def
test_range_uniform_dynamic_same_result
():
R
.
manual_seed
(
0
)
a
=
R
.
uniform
(
5
,
low
=-
2
,
high
=
2
)
R
.
manual_seed
(
0
)
b
=
R
.
uniform
(
5
,
low
=-
2
,
high
=
2
)
assert
np
.
all
(
a
.
numpy
()
==
b
.
numpy
())
def
test_dropout_dynamic_diff_result
():
x
=
mge
.
ones
(
10
)
a
=
F
.
dropout
(
x
,
0.5
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录