Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
98460c00
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
98460c00
编写于
6月 12, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify the computation in cpu
上级
94e72ea6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
24 deletion
+27
-24
paddle/fluid/operators/argsort_op.h
paddle/fluid/operators/argsort_op.h
+27
-24
未找到文件。
paddle/fluid/operators/argsort_op.h
浏览文件 @
98460c00
...
...
@@ -28,47 +28,50 @@ class ArgsortKernel : public framework::OpKernel<T> {
auto
*
input
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X"
);
auto
*
output
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
*
indices
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Indices"
);
int
axis
=
static_cast
<
int
>
(
ctx
.
Attr
<
int
>
(
"axis"
)
);
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
auto
in_dims
=
input
->
dims
();
axis
=
(
axis
<
0
)
?
(
in_dims
.
size
()
+
axis
)
:
axis
;
const
T
*
in_data
=
input
->
data
<
T
>
();
T
*
out_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
int64_t
*
id
x
_data
=
indices
->
mutable_data
<
int64_t
>
(
ctx
.
GetPlace
());
int64_t
*
id
s
_data
=
indices
->
mutable_data
<
int64_t
>
(
ctx
.
GetPlace
());
int64_t
part_dims_prod
=
input
->
numel
()
/
in_dims
[
axis
];
for
(
int64_t
i
=
0
;
i
<
part_dims_prod
;
++
i
)
{
int64_t
groups
=
input
->
numel
()
/
in_dims
[
axis
];
int64_t
stride
=
(
axis
==
in_dims
.
size
()
-
1
)
?
1
:
framework
::
product
(
framework
::
slice_ddim
(
in_dims
,
axis
+
1
,
in_dims
.
size
()));
for
(
int64_t
i
=
0
;
i
<
groups
;
++
i
)
{
int64_t
idx
=
i
;
std
::
vector
<
int64_t
>
idx
_vec
(
in_dims
.
size
(),
0
);
std
::
vector
<
int64_t
>
shape
_vec
(
in_dims
.
size
(),
0
);
for
(
int64_t
dim
=
in_dims
.
size
()
-
1
;
dim
>=
0
;
--
dim
)
{
if
(
dim
!=
axis
)
{
idx
_vec
[
dim
]
=
idx
%
in_dims
[
dim
];
shape
_vec
[
dim
]
=
idx
%
in_dims
[
dim
];
idx
/=
in_dims
[
dim
];
}
}
std
::
vector
<
std
::
pair
<
T
,
int64_t
>>
in_vec
;
std
::
vector
<
int64_t
>
org_index_vec
(
in_dims
[
axis
],
0
);
for
(
int64_t
j
=
0
;
j
<
in_dims
[
axis
];
++
j
)
{
idx_vec
[
axis
]
=
j
;
int64_t
index
=
idx_vec
[
0
];
for
(
int64_t
dim
=
0
;
dim
<
in_dims
.
size
()
-
1
;
++
dim
)
{
index
=
index
*
in_dims
[
dim
+
1
]
+
idx_vec
[
dim
+
1
];
}
in_vec
.
push_back
(
std
::
pair
<
T
,
int64_t
>
(
in_data
[
index
],
j
));
org_index_vec
[
j
]
=
index
;
int64_t
start_index
=
shape_vec
[
0
];
for
(
int64_t
dim
=
0
;
dim
<
in_dims
.
size
()
-
1
;
++
dim
)
{
start_index
=
start_index
*
in_dims
[
dim
+
1
]
+
shape_vec
[
dim
+
1
];
}
std
::
vector
<
int64_t
>
org_index_vec
(
in_dims
[
axis
],
start_index
);
for
(
int64_t
j
=
1
;
j
<
in_dims
[
axis
];
++
j
)
{
org_index_vec
[
j
]
+=
j
*
stride
;
}
std
::
sort
(
in_vec
.
begin
(),
in_vec
.
end
(),
[](
const
std
::
pair
<
T
,
int64_t
>&
v1
,
const
std
::
pair
<
T
,
int64_t
>&
v2
)
{
return
v1
.
first
<
v2
.
first
;
});
std
::
sort
(
org_index_vec
.
begin
(),
org_index_vec
.
end
(),
[
in_data
](
const
int64_t
v1
,
const
int64_t
v2
)
{
return
in_data
[
v1
]
<
in_data
[
v2
];
});
for
(
size_t
j
=
0
;
j
<
org_index_vec
.
size
();
++
j
)
{
int64_t
index
=
org_index_vec
[
j
]
;
out_data
[
index
]
=
in_
vec
[
j
].
first
;
id
x_data
[
index
]
=
in_vec
[
j
].
second
;
int64_t
index
=
start_index
+
j
*
stride
;
out_data
[
index
]
=
in_
data
[
org_index_vec
[
j
]]
;
id
s_data
[
index
]
=
(
org_index_vec
[
j
]
-
start_index
)
/
stride
;
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录