I think scatter_ should work:
orig_input = torch.randint(10, 15, (10,))

sorted_and_unique, idx = torch.unique(orig_input, sorted=True, return_inverse=True, dim=0)
# recontruct the original (same as orig_input)
original = sorted_and_unique[idx]

print((orig_input == original).all())
> tensor(True)

ret = torch.zeros_like(sorted_and_unique).scatter_(0, idx, orig_input)
print((ret == sorted_and_unique).all())
> tensor(True)

However, note that the result might not be deterministic as you are writing to the same location in case your other tensor has different values, which should be mapped to the same index.