Efficient way to get number of inversions in an array using pytorch

Please may I know how to get the number of inversions in an array using pytorch?

Could you describe a bit more what you mean by “inversions”?