sort

dragon.vm.torch.sort(
  input,
  dim=- 1,
  descending=False,
  out=None
)[source]

Return the sorted elements along the given dimension.

By default, the last dimension is chosen:

x = torch.tensor([[1, 2, 3], [3, 2, 1]])
value1, index1 = torch.sort(x)
value2, index2 = torch.sort(x, dim=1)  # Equivalent

Sort in the descending order if descending is True:

x = torch.tensor([1, 2, 3])
_, index1 = torch.sort(-x)
_, index2 = torch.sort(x, descending=True)  # Equivalent
Parameters:
  • input (dragon.vm.torch.Tensor) The input tensor.
  • dim (int, optional, default=-1) The dimension to sort elements.
  • descending (bool, optional, default=False) Sort in the descending order or not.
  • out (Sequence[dragon.vm.torch.Tensor], optional) The optional output value and index.
Returns:

Sequence[dragon.vm.torch.Tensor] The value and index tensor.