Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
517929f1
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
517929f1
编写于
4月 10, 2020
作者:
G
GaoWei8
提交者:
GitHub
4月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Op (reorder_lod_tensor_by_rank) error message enhancement (#23552)
上级
28f04c6a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
3 deletion
+35
-3
paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc
paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc
+3
-1
python/paddle/fluid/layers/control_flow.py
python/paddle/fluid/layers/control_flow.py
+7
-2
python/paddle/fluid/tests/unittests/test_reorder_lod_tensor.py
...n/paddle/fluid/tests/unittests/test_reorder_lod_tensor.py
+25
-0
未找到文件。
paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc
浏览文件 @
517929f1
...
...
@@ -188,7 +188,9 @@ class ReorderLoDTensorByRankTableOp : public ReorderLoDTensorByRankTableBase {
size_t
out_offset
=
0
;
out
->
mutable_lod
()
->
clear
();
for
(
auto
&
item
:
rank_table
.
items
())
{
PADDLE_ENFORCE_LT
(
item
.
index
,
absolute_table
.
size
());
PADDLE_ENFORCE_LT
(
item
.
index
,
absolute_table
.
size
(),
platform
::
errors
::
OutOfRange
(
"The value of rank_table is out of range."
));
out_offset
=
CopyTensorAndLod
(
place
,
absolute_table
[
item
.
index
],
x
,
out
,
out_offset
);
}
...
...
python/paddle/fluid/layers/control_flow.py
浏览文件 @
517929f1
...
...
@@ -3476,9 +3476,14 @@ def reorder_lod_tensor_by_rank(x, rank_table):
x=data, rank_table=table)
"""
check_type
(
x
,
'x'
,
(
Variable
),
'reorder_lod_tensor_by_rank'
)
check_type
(
rank_table
,
'rank_table'
,
(
Variable
),
'reorder_lod_tensor_by_rank'
)
if
rank_table
.
type
!=
core
.
VarDesc
.
VarType
.
LOD_RANK_TABLE
:
raise
TypeError
(
"The type of rank_table should be LOD_RANK_TABLE."
)
helper
=
LayerHelper
(
'reorder_lod_tensor_by_rank'
,
**
locals
())
helper
.
is_instance
(
'x'
,
Variable
)
helper
.
is_instance
(
'rank_table'
,
Variable
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
helper
.
append_op
(
...
...
python/paddle/fluid/tests/unittests/test_reorder_lod_tensor.py
浏览文件 @
517929f1
...
...
@@ -18,6 +18,7 @@ import unittest
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
from
paddle.fluid.layers.control_flow
import
lod_rank_table
from
paddle.fluid
import
Program
,
program_guard
import
numpy
import
functools
...
...
@@ -209,5 +210,29 @@ class TestReorderLoDTensor(unittest.TestCase):
numpy
.
array
(
actual_output
),
expect_output
,
atol
=
0.001
))
class
TestReorderLoDTensorError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
()):
def
test_Variable
():
# The input must be Variable.
x1
=
numpy
.
array
([
0.9383
,
0.1983
,
3.2
,
1.2
]).
astype
(
"float64"
)
table1
=
numpy
.
array
(
[
0.9383
,
0.1983
,
3.2
,
1.2
]).
astype
(
"float64"
)
new_dat
=
fluid
.
layers
.
reorder_lod_tensor_by_rank
(
x
=
x1
,
rank_table
=
table1
)
self
.
assertRaises
(
TypeError
,
test_Variable
)
def
test_type
():
x2
=
fluid
.
layers
.
data
(
name
=
'x1'
,
shape
=
[
4
],
dtype
=
'float32'
)
table2
=
fluid
.
layers
.
data
(
name
=
'table2'
,
shape
=
[
4
],
dtype
=
'int32'
)
new_dat2
=
fluid
.
layers
.
reorder_lod_tensor_by_rank
(
x
=
x2
,
rank_table
=
table2
)
self
.
assertRaises
(
TypeError
,
test_type
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录