Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
94e72ea6
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看板
提交
94e72ea6
编写于
6月 12, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support more negative axes in argsort_op
上级
42645ff7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
21 addition
and
10 deletion
+21
-10
paddle/fluid/operators/argsort_op.cc
paddle/fluid/operators/argsort_op.cc
+12
-8
paddle/fluid/operators/argsort_op.cu
paddle/fluid/operators/argsort_op.cu
+1
-1
paddle/fluid/operators/argsort_op.h
paddle/fluid/operators/argsort_op.h
+1
-1
python/paddle/fluid/tests/unittests/test_argsort_op.py
python/paddle/fluid/tests/unittests/test_argsort_op.py
+7
-0
未找到文件。
paddle/fluid/operators/argsort_op.cc
浏览文件 @
94e72ea6
...
@@ -37,10 +37,10 @@ class ArgsortOp : public framework::OperatorWithKernel {
...
@@ -37,10 +37,10 @@ class ArgsortOp : public framework::OperatorWithKernel {
"Attr(axis) %d of ArgsortOp is out of bounds for Input(X) "
"Attr(axis) %d of ArgsortOp is out of bounds for Input(X) "
"dimension %d."
,
"dimension %d."
,
axis
,
num_dims
);
axis
,
num_dims
);
PADDLE_ENFORCE
(
axis
>=
0
||
axis
==
-
1
,
PADDLE_ENFORCE
(
in_dims
.
size
()
+
axis
>=
0
,
"Attr(axis) %d of ArgsortOp
must be nonnegative or equal to
"
"Attr(axis) %d of ArgsortOp
plus the number of Input(X)'s
"
"
-1
."
,
"
dimensions %d must be nonnegative
."
,
axis
);
axis
,
in_dims
.
size
()
);
ctx
->
SetOutputDim
(
"Out"
,
in_dims
);
ctx
->
SetOutputDim
(
"Out"
,
in_dims
);
ctx
->
SetOutputDim
(
"Indices"
,
in_dims
);
ctx
->
SetOutputDim
(
"Indices"
,
in_dims
);
...
@@ -53,9 +53,12 @@ class ArgsortOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -53,9 +53,12 @@ class ArgsortOpMaker : public framework::OpProtoAndCheckerMaker {
public:
public:
void
Make
()
override
{
void
Make
()
override
{
AddInput
(
"X"
,
"(Tensor) The input of Argsort op."
);
AddInput
(
"X"
,
"(Tensor) The input of Argsort op."
);
AddOutput
(
"Out"
,
"(Tensor) The sorted tensor of Argsort op."
);
AddOutput
(
"Out"
,
"(Tensor) The sorted tensor of Argsort op, with the same "
"shape as Input(X)."
);
AddOutput
(
"Indices"
,
AddOutput
(
"Indices"
,
"(Tensor) The indices of a tensor giving the sorted order."
);
"(Tensor) The indices of a tensor giving the sorted order, with "
"the same shape as Input(X)."
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
Argsort operator
Argsort operator
...
@@ -66,8 +69,9 @@ Output(Indices) gives the sorted order along the given axis Attr(axis).
...
@@ -66,8 +69,9 @@ Output(Indices) gives the sorted order along the given axis Attr(axis).
)DOC"
);
)DOC"
);
AddAttr
<
int
>
(
"axis"
,
AddAttr
<
int
>
(
"axis"
,
"(int, default -1) The axis along which to sort the tensor, "
"(int, default -1) The axis along which to sort the tensor. "
"default -1, the last dimension."
)
"When axis < 0, the actual axis will be the |axis|'th "
"counting backwards. Default -1, the last dimension."
)
.
SetDefault
(
-
1
);
.
SetDefault
(
-
1
);
}
}
};
};
...
...
paddle/fluid/operators/argsort_op.cu
浏览文件 @
94e72ea6
...
@@ -103,7 +103,7 @@ class ArgsortOpCUDAKernel : public framework::OpKernel<T> {
...
@@ -103,7 +103,7 @@ class ArgsortOpCUDAKernel : public framework::OpKernel<T> {
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
auto
in_dims
=
input
->
dims
();
auto
in_dims
=
input
->
dims
();
axis
=
(
axis
==
-
1
)
?
(
in_dims
.
size
()
-
1
)
:
axis
;
axis
=
(
axis
<
0
)
?
(
in_dims
.
size
()
+
axis
)
:
axis
;
const
T
*
in_data
=
input
->
data
<
T
>
();
const
T
*
in_data
=
input
->
data
<
T
>
();
T
*
out_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
T
*
out_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
...
...
paddle/fluid/operators/argsort_op.h
浏览文件 @
94e72ea6
...
@@ -31,7 +31,7 @@ class ArgsortKernel : public framework::OpKernel<T> {
...
@@ -31,7 +31,7 @@ class ArgsortKernel : public framework::OpKernel<T> {
int
axis
=
static_cast
<
int
>
(
ctx
.
Attr
<
int
>
(
"axis"
));
int
axis
=
static_cast
<
int
>
(
ctx
.
Attr
<
int
>
(
"axis"
));
auto
in_dims
=
input
->
dims
();
auto
in_dims
=
input
->
dims
();
axis
=
(
axis
==
-
1
)
?
(
in_dims
.
size
()
-
1
)
:
axis
;
axis
=
(
axis
<
0
)
?
(
in_dims
.
size
()
+
axis
)
:
axis
;
const
T
*
in_data
=
input
->
data
<
T
>
();
const
T
*
in_data
=
input
->
data
<
T
>
();
T
*
out_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
T
*
out_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
...
...
python/paddle/fluid/tests/unittests/test_argsort_op.py
浏览文件 @
94e72ea6
...
@@ -21,6 +21,8 @@ class TestArgsortOp(OpTest):
...
@@ -21,6 +21,8 @@ class TestArgsortOp(OpTest):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
init_axis
()
self
.
init_axis
()
x
=
np
.
random
.
random
((
2
,
3
,
4
,
5
)).
astype
(
"float32"
)
x
=
np
.
random
.
random
((
2
,
3
,
4
,
5
)).
astype
(
"float32"
)
if
self
.
axis
<
0
:
self
.
axis
=
self
.
axis
+
len
(
x
.
shape
)
self
.
indices
=
np
.
argsort
(
x
,
kind
=
'quicksort'
,
axis
=
self
.
axis
)
self
.
indices
=
np
.
argsort
(
x
,
kind
=
'quicksort'
,
axis
=
self
.
axis
)
self
.
out
=
np
.
sort
(
x
,
kind
=
'quicksort'
,
axis
=
self
.
axis
)
self
.
out
=
np
.
sort
(
x
,
kind
=
'quicksort'
,
axis
=
self
.
axis
)
self
.
op_type
=
"argsort"
self
.
op_type
=
"argsort"
...
@@ -45,5 +47,10 @@ class TestArgsortOpAxis1(TestArgsortOp):
...
@@ -45,5 +47,10 @@ class TestArgsortOpAxis1(TestArgsortOp):
self
.
axis
=
1
self
.
axis
=
1
class
TestArgsortOpAxisNeg2
(
TestArgsortOp
):
def
init_axis
(
self
):
self
.
axis
=
-
2
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录