Move argsort to C++

Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/17099

Differential Revision: D14165671

Pulled By: ezyang

fbshipit-source-id: 3871de6874fe09871ebd9b8943c13c9af325bf33
This commit is contained in:
Gao, Xiang
2019-02-21 07:50:27 -08:00
committed by Facebook Github Bot
parent 37890610b0
commit 722cbe3064
10 changed files with 55 additions and 41 deletions

View File

@ -4269,7 +4269,7 @@ Example::
add_docstr(torch.sort,
r"""
sort(input, dim=None, descending=False, out=None) -> (Tensor, LongTensor)
sort(input, dim=-1, descending=False, out=None) -> (Tensor, LongTensor)
Sorts the elements of the :attr:`input` tensor along a given dimension
in ascending order by value.
@ -4313,6 +4313,38 @@ Example::
[ 1, 2, 2, 0]])
""")
add_docstr(torch.argsort,
r"""
argsort(input, dim=-1, descending=False, out=None) -> LongTensor
Returns the indices that sort a tensor along a given dimension in ascending
order by value.
This is the second value returned by :meth:`torch.sort`. See its documentation
for the exact semantics of this method.
Args:
input (Tensor): the input tensor
dim (int, optional): the dimension to sort along
descending (bool, optional): controls the sorting order (ascending or descending)
Example::
>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.0785, 1.5267, -0.8521, 0.4065],
[ 0.1598, 0.0788, -0.0745, -1.2700],
[ 1.2208, 1.0722, -0.7064, 1.2564],
[ 0.0669, -0.2318, -0.8229, -0.9280]])
>>> torch.argsort(a, dim=1)
tensor([[2, 0, 3, 1],
[3, 2, 1, 0],
[2, 1, 0, 3],
[3, 2, 1, 0]])
""")
add_docstr(torch.sparse_coo_tensor,
r"""
sparse_coo_tensor(indices, values, size=None, dtype=None, device=None, requires_grad=False) -> Tensor