Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
6a09b8f1
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6a09b8f1
编写于
9月 03, 2020
作者:
Z
zhupengyang
提交者:
GitHub
9月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
erase Raises and refine doce of random functions (#26901)
上级
559d9f2b
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
100 addition
and
141 deletion
+100
-141
python/paddle/fluid/data_feeder.py
python/paddle/fluid/data_feeder.py
+22
-0
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+4
-4
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+2
-2
python/paddle/fluid/layers/utils.py
python/paddle/fluid/layers/utils.py
+2
-2
python/paddle/fluid/tests/unittests/test_gaussian_random_op.py
...n/paddle/fluid/tests/unittests/test_gaussian_random_op.py
+3
-3
python/paddle/fluid/tests/unittests/test_randint_op.py
python/paddle/fluid/tests/unittests/test_randint_op.py
+5
-0
python/paddle/tensor/random.py
python/paddle/tensor/random.py
+62
-130
未找到文件。
python/paddle/fluid/data_feeder.py
浏览文件 @
6a09b8f1
...
...
@@ -132,6 +132,28 @@ def check_dtype(input_dtype,
extra_message
))
def
check_shape
(
shape
,
op_name
,
expected_shape_type
=
(
list
,
tuple
,
Variable
),
expected_element_type
=
(
int
,
Variable
),
expected_tensor_dtype
=
(
'int32'
,
'int64'
)):
# See NOTE [ Why skip dynamic graph check ]
if
in_dygraph_mode
():
return
check_type
(
shape
,
'shape'
,
expected_shape_type
,
op_name
)
if
expected_element_type
is
not
None
and
not
isinstance
(
shape
,
Variable
):
for
item
in
shape
:
check_type
(
item
,
'element of shape'
,
expected_element_type
,
op_name
)
if
expected_tensor_dtype
is
not
None
and
isinstance
(
item
,
Variable
):
check_dtype
(
item
.
dtype
,
'element of shape'
,
expected_tensor_dtype
,
op_name
,
'If element of shape is Tensor, its data type should be {}'
.
format
(
', '
.
join
(
expected_tensor_dtype
)))
if
expected_tensor_dtype
is
not
None
and
isinstance
(
shape
,
Variable
):
check_dtype
(
shape
.
dtype
,
'shape'
,
expected_tensor_dtype
,
op_name
)
class
DataToLoDTensorConverter
(
object
):
def
__init__
(
self
,
place
,
lod_level
,
shape
,
dtype
):
self
.
place
=
place
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
6a09b8f1
...
...
@@ -10610,7 +10610,7 @@ def gaussian_random(shape,
dtype = convert_np_dtype_to_dtype_(dtype)
if in_dygraph_mode():
shape = utils.
_
convert_shape_to_list(shape)
shape = utils.convert_shape_to_list(shape)
return core.ops.gaussian_random('shape', shape, 'mean',
float(mean), 'std',
float(std), 'seed', seed, 'dtype',
...
...
@@ -10627,7 +10627,7 @@ def gaussian_random(shape,
'dtype': dtype,
'use_mkldnn': False
}
utils.
_
get_shape_tensor_inputs(
utils.get_shape_tensor_inputs(
inputs=inputs,
attrs=attrs,
shape=shape,
...
...
@@ -15116,7 +15116,7 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0,
dtype = convert_np_dtype_to_dtype_(dtype)
if in_dygraph_mode():
shape = utils.
_
convert_shape_to_list(shape)
shape = utils.convert_shape_to_list(shape)
return core.ops.uniform_random('shape', shape, 'min',
float(min), 'max',
float(max), 'seed', seed, 'dtype', dtype)
...
...
@@ -15126,7 +15126,7 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0,
inputs = dict()
attrs = {'seed': seed, 'min': min, 'max': max, 'dtype': dtype}
utils.
_
get_shape_tensor_inputs(
utils.get_shape_tensor_inputs(
inputs=inputs, attrs=attrs, shape=shape, op_type='uniform_random/rand')
helper = LayerHelper("uniform_random", **locals())
...
...
python/paddle/fluid/layers/tensor.py
浏览文件 @
6a09b8f1
...
...
@@ -694,7 +694,7 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None, name=None):
attrs
[
'str_value'
]
=
str
(
float
(
value
))
if
in_dygraph_mode
():
shape
=
utils
.
_
convert_shape_to_list
(
shape
)
shape
=
utils
.
convert_shape_to_list
(
shape
)
if
out
is
None
:
out
=
_varbase_creator
(
dtype
=
dtype
)
...
...
@@ -731,7 +731,7 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None, name=None):
'fill_constant'
)
helper
=
LayerHelper
(
"fill_constant"
,
**
locals
())
utils
.
_
get_shape_tensor_inputs
(
utils
.
get_shape_tensor_inputs
(
inputs
=
inputs
,
attrs
=
attrs
,
shape
=
shape
,
op_type
=
'fill_constant'
)
if
out
is
None
:
...
...
python/paddle/fluid/layers/utils.py
浏览文件 @
6a09b8f1
...
...
@@ -282,7 +282,7 @@ def _contain_var(list_or_tuple):
return
False
def
_
get_shape_tensor_inputs
(
inputs
,
attrs
,
shape
,
op_type
):
def
get_shape_tensor_inputs
(
inputs
,
attrs
,
shape
,
op_type
):
from
.tensor
import
fill_constant
,
cast
def
_get_attr_shape
(
list_shape
):
...
...
@@ -347,7 +347,7 @@ def _convert_to_tensor_list(old_list, dtype="int32"):
return
new_list_tensor
def
_
convert_shape_to_list
(
shape
):
def
convert_shape_to_list
(
shape
):
"""
Convert shape(list, tuple, variable) to list in imperative mode
"""
...
...
python/paddle/fluid/tests/unittests/test_gaussian_random_op.py
浏览文件 @
6a09b8f1
...
...
@@ -241,18 +241,18 @@ class TestGaussianRandomAPI(unittest.TestCase):
def
test_default_fp_16
():
paddle
.
framework
.
set_default_dtype
(
'float16'
)
paddle
.
tensor
.
random
.
gaussian
_random
([
2
,
3
])
paddle
.
tensor
.
random
.
gaussian
([
2
,
3
])
self
.
assertRaises
(
TypeError
,
test_default_fp_16
)
def
test_default_fp_32
():
paddle
.
framework
.
set_default_dtype
(
'float32'
)
out
=
paddle
.
tensor
.
random
.
gaussian
_random
([
2
,
3
])
out
=
paddle
.
tensor
.
random
.
gaussian
([
2
,
3
])
self
.
assertEqual
(
out
.
dtype
,
fluid
.
core
.
VarDesc
.
VarType
.
FP32
)
def
test_default_fp_64
():
paddle
.
framework
.
set_default_dtype
(
'float64'
)
out
=
paddle
.
tensor
.
random
.
gaussian
_random
([
2
,
3
])
out
=
paddle
.
tensor
.
random
.
gaussian
([
2
,
3
])
self
.
assertEqual
(
out
.
dtype
,
fluid
.
core
.
VarDesc
.
VarType
.
FP64
)
test_default_fp_64
()
...
...
python/paddle/fluid/tests/unittests/test_randint_op.py
浏览文件 @
6a09b8f1
...
...
@@ -58,6 +58,11 @@ class TestRandintOpError(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
paddle
.
randint
,
5
,
dtype
=
'float32'
)
self
.
assertRaises
(
ValueError
,
paddle
.
randint
,
5
,
5
)
self
.
assertRaises
(
ValueError
,
paddle
.
randint
,
-
5
)
self
.
assertRaises
(
TypeError
,
paddle
.
randint
,
5
,
shape
=
[
'2'
])
shape_tensor
=
paddle
.
static
.
data
(
'X'
,
[
1
])
self
.
assertRaises
(
TypeError
,
paddle
.
randint
,
5
,
shape
=
shape_tensor
)
self
.
assertRaises
(
TypeError
,
paddle
.
randint
,
5
,
shape
=
[
shape_tensor
])
class
TestRandintOp_attr_tensorlist
(
OpTest
):
...
...
python/paddle/tensor/random.py
浏览文件 @
6a09b8f1
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录