Not aware of a solution via PyTorch but you can possibly make use of thrust library.
A crude logic would be to first both arrays by sort_by_key 1 operation where keys are the x, y and values are the indices. Afterwards you have a mapping from sorted indices in x to sorted indices in y which can be inverted.