argsort

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

Return the index of sorted elements along the given dimension.

By default, the last dimension is chosen:

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

Sort in the descending order if descending is True:

x = torch.tensor([1, 2, 3])
index1 = torch.argsort(-x)
index2 = torch.argsort(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.
Returns:

dragon.vm.torch.Tensor – The output tensor.