Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
69e3f993
P
Paddle
项目概览
PaddlePaddle
/
Paddle
11 个月 前同步成功
通知
2292
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
69e3f993
编写于
4月 01, 2020
作者:
W
wangchaochaohu
提交者:
GitHub
4月 01, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine the error message (#23212)
* refine the error message of tensor_array_read_write Op
上级
5c59d213
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
21 addition
and
24 deletion
+21
-24
paddle/fluid/operators/controlflow/tensor_array_read_write_op.cc
...fluid/operators/controlflow/tensor_array_read_write_op.cc
+21
-24
未找到文件。
paddle/fluid/operators/controlflow/tensor_array_read_write_op.cc
浏览文件 @
69e3f993
...
...
@@ -82,16 +82,23 @@ $$A[i] = T$$
class
WriteToArrayInferShape
:
public
framework
::
InferShapeBase
{
public:
void
operator
()(
framework
::
InferShapeContext
*
context
)
const
override
{
PADDLE_ENFORCE
(
context
->
HasInput
(
"I"
),
"Must set the subscript index"
);
if
(
context
->
IsRuntime
())
{
PADDLE_ENFORCE_EQ
(
framework
::
product
(
context
->
GetInputDim
(
"I"
)),
1
,
"The number of element of subscript index must be 1"
);
}
PADDLE_ENFORCE_EQ
(
context
->
HasInput
(
"I"
),
true
,
platform
::
errors
::
InvalidArgument
(
"Read/Write array operation must set the subscript index."
));
// TODO(wangchaochaohu) control flow Op do not support runtime infer shape
// Later we add [ontext->GetInputDim("I")) == 1] check when it's supported
if
(
!
context
->
HasInput
(
"X"
))
{
return
;
}
PADDLE_ENFORCE
(
context
->
HasOutput
(
"Out"
),
NotHasOutError
());
PADDLE_ENFORCE_EQ
(
context
->
HasOutput
(
"Out"
),
true
,
platform
::
errors
::
InvalidArgument
(
"Read/Write array operation must set the output Tensor "
"to get the result."
));
context
->
SetOutputDim
(
"Out"
,
context
->
GetInputDim
(
"X"
));
// When compile time, we need to:
...
...
@@ -106,13 +113,6 @@ class WriteToArrayInferShape : public framework::InferShapeBase {
context
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
}
protected:
virtual
const
char
*
NotHasXError
()
const
{
return
"Must set the lod tensor"
;
}
virtual
const
char
*
NotHasOutError
()
const
{
return
"Must set the lod tensor array"
;
}
};
class
WriteToArrayInferVarType
:
public
framework
::
VarTypeInference
{
...
...
@@ -140,10 +140,15 @@ class ReadFromArrayOp : public ArrayOp {
void
RunImpl
(
const
framework
::
Scope
&
scope
,
const
platform
::
Place
&
place
)
const
override
{
auto
*
x
=
scope
.
FindVar
(
Input
(
"X"
));
PADDLE_ENFORCE
(
x
!=
nullptr
,
"X must be set"
);
PADDLE_ENFORCE_NOT_NULL
(
x
,
platform
::
errors
::
InvalidArgument
(
"X(Input Variable) must be set when we call read array operation"
));
auto
&
x_array
=
x
->
Get
<
framework
::
LoDTensorArray
>
();
auto
*
out
=
scope
.
FindVar
(
Output
(
"Out"
));
PADDLE_ENFORCE
(
out
!=
nullptr
,
"Out must be set"
);
PADDLE_ENFORCE_NOT_NULL
(
out
,
platform
::
errors
::
InvalidArgument
(
"Out(Output Varibale) must be set when we "
"call read array operation"
));
size_t
offset
=
GetOffset
(
scope
,
place
);
if
(
offset
<
x_array
.
size
())
{
auto
*
out_tensor
=
out
->
GetMutable
<
framework
::
LoDTensor
>
();
...
...
@@ -199,15 +204,7 @@ $$T = A[i]$$
}
};
class
ReadFromArrayInferShape
:
public
WriteToArrayInferShape
{
protected:
const
char
*
NotHasXError
()
const
override
{
return
"The input array X must be set"
;
}
const
char
*
NotHasOutError
()
const
override
{
return
"The output tensor out must be set"
;
}
};
class
ReadFromArrayInferShape
:
public
WriteToArrayInferShape
{};
template
<
typename
T
>
class
WriteToArrayGradMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录