Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
极客李华
Paddle
提交
a523b6f4
P
Paddle
项目概览
极客李华
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a523b6f4
编写于
6月 18, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add python api for argsort_op
上级
7ca511e0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
6 deletion
+63
-6
doc/fluid/api/layers.rst
doc/fluid/api/layers.rst
+6
-0
paddle/fluid/operators/argsort_op.cc
paddle/fluid/operators/argsort_op.cc
+6
-6
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+51
-0
未找到文件。
doc/fluid/api/layers.rst
浏览文件 @
a523b6f4
...
...
@@ -1105,6 +1105,12 @@ argmax
.. autofunction:: paddle.fluid.layers.argmax
:noindex:
argsort
------
.. autofunction:: paddle.fluid.layers.argsort
:noindex:
ones
----
...
...
paddle/fluid/operators/argsort_op.cc
浏览文件 @
a523b6f4
...
...
@@ -34,13 +34,13 @@ class ArgsortOp : public framework::OperatorWithKernel {
auto
num_dims
=
in_dims
.
size
();
PADDLE_ENFORCE
(
axis
<
num_dims
,
"Attr(axis) %d of ArgsortOp is out of bounds for Input(X) "
"dimension %d."
,
"Attr(axis) %d of ArgsortOp is out of bounds for Input(X)'s "
"rank %d."
,
axis
,
num_dims
);
PADDLE_ENFORCE
(
axis
>=
-
num_dims
,
"Attr(axis) %d of ArgsortOp must be not less than "
"-rank(Input(X)) (%d)."
,
axis
,
num_dims
);
PADDLE_ENFORCE
(
in_dims
.
size
()
+
axis
>=
0
,
"Attr(axis) %d of ArgsortOp plus the rank %d of Input(X) "
"must be nonnegative."
,
axis
,
in_dims
.
size
());
ctx
->
SetOutputDim
(
"Out"
,
in_dims
);
ctx
->
SetOutputDim
(
"Indices"
,
in_dims
);
...
...
python/paddle/fluid/layers/tensor.py
浏览文件 @
a523b6f4
...
...
@@ -33,6 +33,7 @@ __all__ = [
'fill_constant'
,
'argmin'
,
'argmax'
,
'argsort'
,
'ones'
,
'zeros'
,
'reverse'
,
...
...
@@ -438,6 +439,56 @@ def argmax(x, axis=0):
return
out
def
argsort
(
input
,
axis
=-
1
):
"""
Performs sorting on the input Variable along the given axis, and outputs
sorted data Varibale and its corresponding index Variable with the same
shape as :attr:`input`.
.. code-block:: text
For example, the given axis is -1 and the input Variable
input = [[0.15849551, 0.45865775, 0.8563702 ],
[0.12070083, 0.28766365, 0.18776911]],
after argsort, the sorted Vairable becomes
out = [[0.15849551, 0.45865775, 0.8563702 ],
[0.12070083, 0.18776911, 0.28766365]],
and the sorted indices along the given axis turn outs to be
indices = [[0, 1, 2],
[0, 2, 1]]
Args:
input(Variable): The input Variable for sorting.
axis(int): The axis along which to sort the input Variable. When
:attr:`axis` < 0, the actual axis will be :attr:`axis` +
rank(:attr:`input`). Default -1, the last dimension.
Returns:
tuple: A tuple of sorted data Variable and the sorted indices.
Examples:
.. code-block:: python
input = fluid.layers.data(data=[2, 3])
out, indices = fluid.layers.argsort(input, axis=0)
"""
helper
=
LayerHelper
(
"argsort"
,
**
locals
())
out
=
helper
.
create_tmp_variable
(
dtype
=
input
.
dtype
,
stop_gradient
=
True
)
ids
=
helper
.
create_tmp_variable
(
VarDesc
.
VarType
.
INT64
,
stop_gradient
=
True
)
helper
.
append_op
(
type
=
'argsort'
,
inputs
=
{
'X'
:
input
},
outputs
=
{
'Out'
:
out
,
'Indics'
:
ids
},
attts
=
{
'axis'
:
axis
})
return
out
,
ids
def
ones
(
shape
,
dtype
,
force_cpu
=
False
):
"""
**ones**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录