How can I get the unique value of an array without changing the sequence of elements in the array?
for example, for array [5,5,3,3,4,4]
If I use torch.unique direct on gpu, the result is always asendingly sorted: [3,4,5]
If I use torch.unique on cpu, the result is still not correct: [4,3,5]
Only numpy.unique can get what I wanted: [5,3,4]
So is this a bug of torch.unique?
code to test:
import torch
import numpy as np
c=torch.tensor([5,5,3,3,4,4]).cuda()
print('raw array on gpu: '+str( c ))
d=torch.unique( c )
print('unique by torch.unique on gpu: '+str(d))
c2=c.cpu()
d2=torch.unique(c2)
print('unique by torch.unique on cpu: '+str(d2))
c3=c2.numpy()
d3,i=np.unique(c3,return_index=True)
d3=d3[np.argsort(i)]
print('unique by numpy: '+str(d3))