Sort function behaviour for same values

Hi everyone,

I have the following situation: I want to clamp a tensor with a given minimum value and then I want to sort the tensor, and for the positions of the same value, I want to get the locations sorted (first to last):

val is a tensor of dimension B x T x 1000

val = torch.clamp(val, min=0.01)
_, indices = val.sort(-1)

The indices for locations with the same values (e.g. 0.01) are NOT sorted (I think they are just random). Is there a way to enforce that I get the smallest indices first?

Thanks a lot!