Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
57b062e1
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
57b062e1
编写于
4月 26, 2020
作者:
H
HappyAngel
提交者:
GitHub
4月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Cherry-Pick] [2.0-beta] error enhancement (#24169)
上级
514dd097
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
0 deletion
+50
-0
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+5
-0
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+5
-0
python/paddle/fluid/tests/unittests/test_get_tensor_from_selected_rows_op.py
.../tests/unittests/test_get_tensor_from_selected_rows_op.py
+21
-0
python/paddle/fluid/tests/unittests/test_tensor_array_to_tensor.py
...ddle/fluid/tests/unittests/test_tensor_array_to_tensor.py
+19
-0
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
57b062e1
...
...
@@ -12553,6 +12553,11 @@ def get_tensor_from_selected_rows(x, name=None):
out = fluid.layers.get_tensor_from_selected_rows(input)
"""
check_type(x, 'x', Variable, 'get_tensor_from_selected_rows')
if x.type != core.VarDesc.VarType.SELECTED_ROWS:
raise TypeError(
"The type of 'x' in get_tensor_from_selected_rows must be SELECTED_ROWS."
)
helper = LayerHelper('get_tensor_from_selected_rows', **locals())
out = helper.create_variable_for_type_inference(dtype=x.dtype)
helper.append_op(
...
...
python/paddle/fluid/layers/tensor.py
浏览文件 @
57b062e1
...
...
@@ -461,6 +461,11 @@ def tensor_array_to_tensor(input, axis=1, name=None, use_stack=False):
numpy
.
array
(
list
(
map
(
lambda
x
:
int
(
x
.
shape
[
axis
]),
input
))))
return
res
,
sizes
check_type
(
input
,
'input'
,
(
list
,
Variable
),
'tensor_array_to_tensor'
)
if
isinstance
(
input
,
list
):
for
i
,
input_x
in
enumerate
(
input
):
check_type
(
input_x
,
'input['
+
str
(
i
)
+
']'
,
Variable
,
'tensor_array_to_tensor'
)
helper
=
LayerHelper
(
'tensor_array_to_tensor'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
helper
.
input_dtype
())
out_index
=
helper
.
create_variable_for_type_inference
(
dtype
=
"int32"
)
...
...
python/paddle/fluid/tests/unittests/test_get_tensor_from_selected_rows_op.py
浏览文件 @
57b062e1
...
...
@@ -17,7 +17,28 @@ from __future__ import print_function
import
unittest
import
paddle.fluid.core
as
core
import
numpy
as
np
import
paddle.fluid
as
fluid
from
paddle.fluid.op
import
Operator
from
paddle.fluid
import
Program
,
program_guard
class
TestGetTensorFromSelectedRowsError
(
unittest
.
TestCase
):
"""get_tensor_from_selected_rows error message enhance"""
def
test_errors
(
self
):
with
program_guard
(
Program
()):
x_var
=
fluid
.
data
(
'X'
,
[
2
,
3
])
x_data
=
np
.
random
.
random
((
2
,
4
)).
astype
(
"float32"
)
def
test_Variable
():
fluid
.
layers
.
get_tensor_from_selected_rows
(
x
=
x_data
)
self
.
assertRaises
(
TypeError
,
test_Variable
)
def
test_SELECTED_ROWS
():
fluid
.
layers
.
get_tensor_from_selected_rows
(
x
=
x_var
)
self
.
assertRaises
(
TypeError
,
test_SELECTED_ROWS
)
class
TestGetTensorFromSelectedRows
(
unittest
.
TestCase
):
...
...
python/paddle/fluid/tests/unittests/test_tensor_array_to_tensor.py
浏览文件 @
57b062e1
...
...
@@ -20,6 +20,25 @@ import paddle.fluid as fluid
import
paddle.fluid.core
as
core
from
paddle.fluid.op
import
Operator
from
paddle.fluid.executor
import
Executor
from
paddle.fluid
import
Program
,
program_guard
class
TestTensorArrayToTensorError
(
unittest
.
TestCase
):
"""Tensor_array_to_tensor error message enhance"""
def
test_errors
(
self
):
with
program_guard
(
Program
()):
input_data
=
numpy
.
random
.
random
((
2
,
4
)).
astype
(
"float32"
)
def
test_Variable
():
fluid
.
layers
.
tensor_array_to_tensor
(
input
=
input_data
)
self
.
assertRaises
(
TypeError
,
test_Variable
)
def
test_list_Variable
():
fluid
.
layers
.
tensor_array_to_tensor
(
input
=
[
input_data
])
self
.
assertRaises
(
TypeError
,
test_list_Variable
)
class
TestLoDTensorArrayConcat
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录