Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
50931dee
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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,发现更多精彩内容 >>
提交
50931dee
编写于
3月 18, 2019
作者:
T
tensor-tang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine seq enum op
test=develop
上级
8e4ad008
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
18 deletion
+28
-18
paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc
paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc
+0
-7
paddle/fluid/operators/sequence_ops/sequence_enumerate_op.h
paddle/fluid/operators/sequence_ops/sequence_enumerate_op.h
+28
-11
未找到文件。
paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc
浏览文件 @
50931dee
...
...
@@ -30,13 +30,6 @@ class SequenceEnumerateOp : public framework::OperatorWithKernel {
"Output(X) of SequenceEnumerate operator should not be null."
);
const
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
PADDLE_ENFORCE_EQ
(
x_dims
.
size
(),
2
,
"Input(X) of SequenceEnumerate operator's rank should be 2."
);
PADDLE_ENFORCE_EQ
(
x_dims
[
1
],
1
,
"Input(X) of SequenceEnumerate operator's 2nd "
"dimension should be 1."
);
const
auto
win_size
=
ctx
->
Attrs
().
Get
<
int
>
(
"win_size"
);
ctx
->
SetOutputDim
(
"Out"
,
{
x_dims
[
0
],
win_size
});
ctx
->
ShareLoD
(
"X"
,
"Out"
);
...
...
paddle/fluid/operators/sequence_ops/sequence_enumerate_op.h
浏览文件 @
50931dee
...
...
@@ -27,30 +27,47 @@ class SequenceEnumerateKernel : public framework::OpKernel<T> {
auto
*
in
=
context
.
Input
<
LoDTensor
>
(
"X"
);
auto
*
out
=
context
.
Output
<
LoDTensor
>
(
"Out"
);
int
win_size
=
context
.
Attr
<
int
>
(
"win_size"
);
int
pad_value
=
context
.
Attr
<
int
>
(
"pad_value"
);
auto
pad_value
=
static_cast
<
T
>
(
context
.
Attr
<
int
>
(
"pad_value"
)
);
auto
in_dims
=
in
->
dims
();
auto
in_lod
=
in
->
lod
();
auto
lod0
=
in
->
lod
()[
0
];
PADDLE_ENFORCE_EQ
(
static_cast
<
uint64_t
>
(
in_dims
[
0
]),
in_lod
[
0
]
.
back
(),
static_cast
<
uint64_t
>
(
in_dims
[
0
]),
lod0
.
back
(),
"The actual input data's size mismatched with LoD information."
);
PADDLE_ENFORCE_EQ
(
in_dims
.
size
(),
2UL
,
"Input(X) of SequenceEnumerate operator's rank should be 2."
);
PADDLE_ENFORCE_EQ
(
in_dims
[
1
],
1
,
"Input(X) of SequenceEnumerate operator's 2nd "
"dimension should be 1."
);
// Generate enumerate sequence set
auto
lod0
=
in_lod
[
0
];
auto
in_data
=
in
->
data
<
T
>
();
out
->
Resize
({
in_dims
[
0
],
win_size
});
out
->
set_lod
(
in
->
lod
());
auto
out_data
=
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
for
(
size_t
i
=
0
;
i
<
lod0
.
size
()
-
1
;
++
i
)
{
for
(
size_t
idx
=
lod0
[
i
];
idx
<
lod0
[
i
+
1
];
++
idx
)
{
for
(
int
word_idx
=
0
;
word_idx
<
win_size
;
++
word_idx
)
{
size_t
word_pos
=
idx
+
word_idx
;
out_data
[
win_size
*
idx
+
word_idx
]
=
word_pos
<
lod0
[
i
+
1
]
?
in_data
[
word_pos
]
:
pad_value
;
int
start
=
lod0
[
i
];
int
end
=
lod0
[
i
+
1
];
int
copy_size
=
win_size
<
end
-
start
+
1
?
win_size
:
end
-
start
+
1
;
int
mid
=
end
+
1
-
copy_size
;
int
pad_num
=
win_size
-
copy_size
;
copy_size
*=
sizeof
(
T
);
for
(
int
idx
=
start
;
idx
<
mid
;
++
idx
)
{
std
::
memcpy
(
out_data
,
in_data
+
idx
,
copy_size
);
out_data
+=
win_size
;
}
for
(
int
idx
=
mid
;
idx
<
end
;
++
idx
)
{
copy_size
-=
sizeof
(
T
);
pad_num
++
;
std
::
memcpy
(
out_data
,
in_data
+
idx
,
copy_size
);
T
*
pdata
=
out_data
+
copy_size
/
sizeof
(
T
);
for
(
int
i
=
0
;
i
<
pad_num
;
++
i
)
{
pdata
[
i
]
=
pad_value
;
}
out_data
+=
win_size
;
}
}
out
->
set_lod
(
in
->
lod
());
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录