Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
f594ca43
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f594ca43
编写于
1月 10, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reuse the usable variable in edit_distance_op
上级
0250e54c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
12 addition
and
12 deletion
+12
-12
paddle/operators/edit_distance_op.cc
paddle/operators/edit_distance_op.cc
+2
-2
paddle/operators/edit_distance_op.cu
paddle/operators/edit_distance_op.cu
+4
-4
paddle/operators/edit_distance_op.h
paddle/operators/edit_distance_op.h
+6
-6
未找到文件。
paddle/operators/edit_distance_op.cc
浏览文件 @
f594ca43
...
...
@@ -49,10 +49,10 @@ class EditDistanceOpMaker : public framework::OpProtoAndCheckerMaker {
EditDistanceOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"Hyps"
,
"(2-D LoDTensor, 2nd dim. equal to 1) "
"(2-D LoDTensor
<int>
, 2nd dim. equal to 1) "
"The indices for hypothesis strings."
);
AddInput
(
"Refs"
,
"(2-D LoDTensor, 2nd dim. equal to 1) "
"(2-D LoDTensor
<int>
, 2nd dim. equal to 1) "
"The indices for reference strings."
);
AddAttr
<
bool
>
(
"normalized"
,
"(bool, default false) Indicated whether to normalize "
...
...
paddle/operators/edit_distance_op.cu
浏览文件 @
f594ca43
...
...
@@ -93,21 +93,21 @@ class EditDistanceGPUKernel : public framework::OpKernel<T> {
out_t
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
auto
out
=
out_t
->
data
<
T
>
();
std
::
vector
<
T
>
distance
(
num_strs
,
0.0
)
;
T
distance
=
0.0
;
for
(
size_t
num
=
0
;
num
<
num_strs
;
num
++
)
{
auto
m
=
static_cast
<
int64_t
>
(
hyp_lod
[
num
+
1
]
-
hyp_lod
[
num
]);
auto
n
=
static_cast
<
int64_t
>
(
ref_lod
[
num
+
1
]
-
ref_lod
[
num
]);
if
(
m
==
0
||
n
==
0
)
{
distance
[
num
]
=
std
::
max
(
m
,
n
);
distance
=
std
::
max
(
m
,
n
);
if
(
normalized
)
{
PADDLE_ENFORCE
(
n
>
0
,
"The reference string (#%d) cannot be empty "
"when Attr(normalized) is enabled."
,
n
);
distance
[
num
]
=
distance
[
num
]
/
n
;
distance
=
distance
/
n
;
}
memory
::
Copy
(
boost
::
get
<
Place
>
(
ctx
.
GetPlace
()),
out
+
num
,
platform
::
CPUPlace
(),
&
distance
[
num
]
,
sizeof
(
T
),
stream
);
platform
::
CPUPlace
(),
&
distance
,
sizeof
(
T
),
stream
);
}
else
{
framework
::
Tensor
dist_t
;
dist_t
.
Resize
({
m
+
1
,
n
+
1
});
...
...
paddle/operators/edit_distance_op.h
浏览文件 @
f594ca43
...
...
@@ -46,15 +46,15 @@ class EditDistanceKernel : public framework::OpKernel<T> {
out_t
->
mutable_data
<
float
>
(
ctx
.
GetPlace
());
auto
out
=
out_t
->
data
<
T
>
();
std
::
vector
<
T
>
distance
(
num_strs
,
0.0
)
;
T
distance
=
0.0
;
for
(
size_t
num
=
0
;
num
<
num_strs
;
++
num
)
{
auto
m
=
static_cast
<
int64_t
>
(
hyp_lod
[
num
+
1
]
-
hyp_lod
[
num
]);
auto
n
=
static_cast
<
int64_t
>
(
ref_lod
[
num
+
1
]
-
ref_lod
[
num
]);
if
(
m
==
0
)
{
distance
[
num
]
=
n
;
distance
=
n
;
}
else
if
(
n
==
0
)
{
distance
[
num
]
=
m
;
distance
=
m
;
}
else
{
framework
::
Tensor
dist_t
;
dist_t
.
Resize
({
m
+
1
,
n
+
1
});
...
...
@@ -77,7 +77,7 @@ class EditDistanceKernel : public framework::OpKernel<T> {
dist
[
i
*
(
n
+
1
)
+
j
]
=
std
::
min
(
dels
,
std
::
min
(
ins
,
subs
));
}
}
distance
[
num
]
=
dist
[
m
*
(
n
+
1
)
+
n
];
distance
=
dist
[
m
*
(
n
+
1
)
+
n
];
}
if
(
normalized
)
{
...
...
@@ -85,9 +85,9 @@ class EditDistanceKernel : public framework::OpKernel<T> {
"The reference string (#%d) cannot be empty "
"when Attr(normalized) is enabled."
,
n
);
distance
[
num
]
=
distance
[
num
]
/
n
;
distance
=
distance
/
n
;
}
out
[
num
]
=
distance
[
num
]
;
out
[
num
]
=
distance
;
}
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录