Pytorch argsort ordered, with duplicate elements in the tensor
Here is one way:

sort the numpy array using numpy.argsort()
convert the result into tensor using torch.from_numpy()
import torch
 import numpy as np
 A = [0,1,2,3,0,0,1,1,2,2,3,3]
 x = np.array(A)
 y = torch.from_numpy(np.argsort(x, kind='mergesort'))
 print(y)
I have a vector A = [0,1,2,3,0,0,1,1,2,2,3,3]. I need to sort it in an increasing matter such that it is listed in an ordered fashion and from that extract the argsort. To better explain this I need to sort A to such that it returns B = [0,4,5,1,6,7,2,8,9,3,10,11]. However, when I use pyotrch's torch.argsort(A) it returns B = [4,5,0,1,6,7,2,8,9,3,10,11]. 
I'm assuming the algorithm that does so cannot be controlled on my end. Is there anyway to approach this without introducing for loops? Such operation are part of my NN model and will cause performance issues if not done efficiently. Thanks!