Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
cc8ca8ce
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
cc8ca8ce
编写于
3月 25, 2020
作者:
A
Aurelius84
提交者:
GitHub
3月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish error Info in while_loop (#23183)
* Polish error Info in while_loop test=develop
上级
a486a739
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
47 addition
and
2 deletion
+47
-2
python/paddle/fluid/layers/control_flow.py
python/paddle/fluid/layers/control_flow.py
+5
-2
python/paddle/fluid/tests/unittests/test_while_loop_op.py
python/paddle/fluid/tests/unittests/test_while_loop_op.py
+42
-0
未找到文件。
python/paddle/fluid/layers/control_flow.py
浏览文件 @
cc8ca8ce
...
@@ -1031,9 +1031,12 @@ def while_loop(cond, body, loop_vars, is_test=False, name=None):
...
@@ -1031,9 +1031,12 @@ def while_loop(cond, body, loop_vars, is_test=False, name=None):
output_vars
=
body
(
*
loop_vars
)
output_vars
=
body
(
*
loop_vars
)
if
not
isinstance
(
output_vars
,
(
list
,
tuple
)):
if
not
isinstance
(
output_vars
,
(
list
,
tuple
)):
output_vars
=
[
output_vars
]
output_vars
=
[
output_vars
]
if
len
(
output_vars
)
!=
len
(
loop_vars
):
try
:
assert_same_structure
(
output_vars
,
loop_vars
,
check_types
=
False
)
except
ValueError
as
e
:
raise
ValueError
(
"body in while_loop should return the same arity "
raise
ValueError
(
"body in while_loop should return the same arity "
"(length and structure) and types as loop_vars"
)
"(length and structure) as loop_vars: {0}"
.
format
(
e
))
now_cond
=
cond
(
*
output_vars
)
now_cond
=
cond
(
*
output_vars
)
map_structure
(
assign
,
output_vars
,
loop_vars
)
map_structure
(
assign
,
output_vars
,
loop_vars
)
assign
(
now_cond
,
pre_cond
)
assign
(
now_cond
,
pre_cond
)
...
...
python/paddle/fluid/tests/unittests/test_while_loop_op.py
浏览文件 @
cc8ca8ce
...
@@ -384,6 +384,23 @@ class TestApiWhileLoop_Error(unittest.TestCase):
...
@@ -384,6 +384,23 @@ class TestApiWhileLoop_Error(unittest.TestCase):
def
body_returns_error_type
(
i
,
ten
):
def
body_returns_error_type
(
i
,
ten
):
return
layers
.
increment
(
i
)
return
layers
.
increment
(
i
)
def
cond_returns_with_mutable_dict
(
i
,
test_dict
):
return
i
>
0
def
body_returns_with_mutable_dict
(
i
,
test_dict
):
test_dict
[
'new_key'
]
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
1
)
return
layers
.
increment
(
i
),
test_dict
def
cond_returns_with_mutable_list
(
i
,
test_list
):
return
i
>
0
def
body_returns_with_mutable_list
(
i
,
test_list
):
test_list
.
append
(
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
1
))
return
layers
.
increment
(
i
),
test_list
main_program
=
Program
()
main_program
=
Program
()
startup_program
=
Program
()
startup_program
=
Program
()
with
program_guard
(
main_program
,
startup_program
):
with
program_guard
(
main_program
,
startup_program
):
...
@@ -451,6 +468,31 @@ class TestApiWhileLoop_Error(unittest.TestCase):
...
@@ -451,6 +468,31 @@ class TestApiWhileLoop_Error(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
value_error_body_returns_error_type
)
self
.
assertRaises
(
ValueError
,
value_error_body_returns_error_type
)
# The length of `output_vars` with mutable value should keep same with `loop_vars`
def
value_error_body_returns_with_mutable_dict
():
test_dict
=
{
"int_constant"
:
layers
.
fill_constant
(
shape
=
[
2
,
2
],
dtype
=
'int64'
,
value
=
1
)
}
out
=
layers
.
while_loop
(
cond_returns_with_mutable_dict
,
body_returns_with_mutable_dict
,
[
data
,
test_dict
])
self
.
assertRaises
(
ValueError
,
value_error_body_returns_with_mutable_dict
)
def
value_error_body_returns_with_mutable_list
():
test_list
=
[
layers
.
fill_constant
(
shape
=
[
2
,
2
],
dtype
=
'int64'
,
value
=
1
)
]
out
=
layers
.
while_loop
(
cond_returns_with_mutable_list
,
body_returns_with_mutable_list
,
[
data
,
test_list
])
self
.
assertRaises
(
ValueError
,
value_error_body_returns_with_mutable_list
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录