Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
3ea6899f
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看板
未验证
提交
3ea6899f
编写于
4月 10, 2020
作者:
W
wangchaochaohu
提交者:
GitHub
4月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
API(fluid.layers.array_read/array_write) error message enhancement (#23568)
上级
eda7ff05
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
0 deletion
+24
-0
python/paddle/fluid/layers/control_flow.py
python/paddle/fluid/layers/control_flow.py
+9
-0
python/paddle/fluid/tests/unittests/test_array_read_write_op.py
.../paddle/fluid/tests/unittests/test_array_read_write_op.py
+15
-0
未找到文件。
python/paddle/fluid/layers/control_flow.py
浏览文件 @
3ea6899f
...
@@ -1314,7 +1314,15 @@ def array_write(x, i, array=None):
...
@@ -1314,7 +1314,15 @@ def array_write(x, i, array=None):
array
.
append
(
x
)
array
.
append
(
x
)
return
array
return
array
check_variable_and_dtype
(
i
,
'i'
,
[
'int64'
],
'array_write'
)
check_type
(
x
,
'x'
,
(
Variable
),
'array_write'
)
helper
=
LayerHelper
(
'array_write'
,
**
locals
())
helper
=
LayerHelper
(
'array_write'
,
**
locals
())
if
array
is
not
None
:
if
not
isinstance
(
array
,
Variable
)
or
array
.
type
!=
core
.
VarDesc
.
VarType
.
LOD_TENSOR_ARRAY
:
raise
TypeError
(
"array should be tensor array vairable in array_write Op"
)
if
array
is
None
:
if
array
is
None
:
array
=
helper
.
create_variable
(
array
=
helper
.
create_variable
(
name
=
"{0}.out"
.
format
(
helper
.
name
),
name
=
"{0}.out"
.
format
(
helper
.
name
),
...
@@ -1686,6 +1694,7 @@ def array_read(array, i):
...
@@ -1686,6 +1694,7 @@ def array_read(array, i):
i
=
i
.
numpy
()[
0
]
i
=
i
.
numpy
()[
0
]
return
array
[
i
]
return
array
[
i
]
check_variable_and_dtype
(
i
,
'i'
,
[
'int64'
],
'array_read'
)
helper
=
LayerHelper
(
'array_read'
,
**
locals
())
helper
=
LayerHelper
(
'array_read'
,
**
locals
())
if
not
isinstance
(
if
not
isinstance
(
array
,
array
,
...
...
python/paddle/fluid/tests/unittests/test_array_read_write_op.py
浏览文件 @
3ea6899f
...
@@ -21,6 +21,7 @@ import paddle.fluid.layers as layers
...
@@ -21,6 +21,7 @@ import paddle.fluid.layers as layers
from
paddle.fluid.executor
import
Executor
from
paddle.fluid.executor
import
Executor
from
paddle.fluid.backward
import
append_backward
from
paddle.fluid.backward
import
append_backward
from
paddle.fluid.framework
import
default_main_program
from
paddle.fluid.framework
import
default_main_program
from
paddle.fluid
import
compiler
,
Program
,
program_guard
import
numpy
import
numpy
...
@@ -125,5 +126,19 @@ class TestArrayReadWrite(unittest.TestCase):
...
@@ -125,5 +126,19 @@ class TestArrayReadWrite(unittest.TestCase):
self
.
assertAlmostEqual
(
1.0
,
g_out_sum_dygraph
,
delta
=
0.1
)
self
.
assertAlmostEqual
(
1.0
,
g_out_sum_dygraph
,
delta
=
0.1
)
class
TestArrayReadWriteOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
#for ci coverage
x1
=
numpy
.
random
.
randn
(
2
,
4
).
astype
(
'int32'
)
x2
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int32'
,
value
=
1
)
x3
=
numpy
.
random
.
randn
(
2
,
4
).
astype
(
'int32'
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
array_read
,
array
=
x1
,
i
=
x2
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
array_write
,
array
=
x1
,
i
=
x2
,
out
=
x3
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录