Sort

torch_sort(self, dim = -1L, descending = FALSE)

## Arguments

self (Tensor) the input tensor. (int, optional) the dimension to sort along (bool, optional) controls the sorting order (ascending or descending)

## sort(input, dim=-1, descending=FALSE) -> (Tensor, LongTensor)

Sorts the elements of the input tensor along a given dimension in ascending order by value.

If dim is not given, the last dimension of the input is chosen.

If descending is TRUE then the elements are sorted in descending order by value.

A namedtuple of (values, indices) is returned, where the values are the sorted values and indices are the indices of the elements in the original input tensor.

## Examples

if (torch_is_installed()) {

x = torch_randn(c(3, 4))
out = torch_sort(x)
out
out = torch_sort(x, 1)
out
}
#> [[1]]
#> torch_tensor
#> -0.6111 -0.1704 -1.4755 -0.5555
#> -0.0641  0.1995 -0.9370  0.1078
#>  0.1174  0.8468  0.6367  1.2926
#> [ CPUFloatType{3,4} ]
#>
#> [[2]]
#> torch_tensor
#>  0  1  1  1
#>  2  0  0  0
#>  1  2  2  2
#> [ CPULongType{3,4} ]
#>