Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
81e8fd4a
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看板
未验证
提交
81e8fd4a
编写于
4月 09, 2020
作者:
W
wangchaochaohu
提交者:
GitHub
4月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
API(fluid.layers.array_length) error message enhancement (#23547)
上级
1b8fe70e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
2 deletion
+21
-2
paddle/fluid/operators/lod_array_length_op.cc
paddle/fluid/operators/lod_array_length_op.cc
+3
-2
python/paddle/fluid/layers/control_flow.py
python/paddle/fluid/layers/control_flow.py
+7
-0
python/paddle/fluid/tests/unittests/test_lod_array_length_op.py
.../paddle/fluid/tests/unittests/test_lod_array_length_op.py
+11
-0
未找到文件。
paddle/fluid/operators/lod_array_length_op.cc
浏览文件 @
81e8fd4a
...
...
@@ -60,8 +60,9 @@ CPU and the length of LoDTensorArray should be used as control variables.
class
LoDArrayLengthInferShape
:
public
framework
::
InferShapeBase
{
public:
void
operator
()(
framework
::
InferShapeContext
*
context
)
const
override
{
PADDLE_ENFORCE
(
context
->
HasInput
(
"X"
));
PADDLE_ENFORCE
(
context
->
HasOutput
(
"Out"
));
OP_INOUT_CHECK
(
context
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"LDArrayLength"
);
OP_INOUT_CHECK
(
context
->
HasOutput
(
"Out"
),
"Output"
,
"Out"
,
"LoDArrayLength"
);
context
->
SetOutputDim
(
"Out"
,
{
1
});
}
};
...
...
python/paddle/fluid/layers/control_flow.py
浏览文件 @
81e8fd4a
...
...
@@ -1782,12 +1782,19 @@ def array_length(array):
# so the dtype value is typeid(int64_t).Name(), which is 'x' on MacOS, 'l' on Linux,
# and '__int64' on Windows. They both represent 64-bit integer variables.
"""
if
in_dygraph_mode
():
assert
isinstance
(
array
,
list
),
"The 'array' in array_write must be a list in dygraph mode"
return
len
(
array
)
if
not
isinstance
(
array
,
Variable
)
or
array
.
type
!=
core
.
VarDesc
.
VarType
.
LOD_TENSOR_ARRAY
:
raise
TypeError
(
"array should be tensor array vairable in array_length Op"
)
helper
=
LayerHelper
(
'array_length'
,
**
locals
())
tmp
=
helper
.
create_variable_for_type_inference
(
dtype
=
'int64'
)
tmp
.
stop_gradient
=
True
...
...
python/paddle/fluid/tests/unittests/test_lod_array_length_op.py
浏览文件 @
81e8fd4a
...
...
@@ -18,6 +18,8 @@ import unittest
import
paddle.fluid.layers
as
layers
from
paddle.fluid.executor
import
Executor
import
paddle.fluid.core
as
core
import
paddle.fluid
as
fluid
from
paddle.fluid
import
compiler
,
Program
,
program_guard
import
numpy
...
...
@@ -33,5 +35,14 @@ class TestLoDArrayLength(unittest.TestCase):
self
.
assertEqual
(
11
,
result
[
0
])
class
TestLoDArrayLengthOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
#for ci coverage
x1
=
numpy
.
random
.
randn
(
2
,
4
).
astype
(
'int32'
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
array_length
,
array
=
x1
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录