I think that scipy.stats.wasserstein_distance 1 would be a good starting point for this. The source code 3 mostly uses standard NumPy functionality for which I think there are compatible PyTorch functions. Not exactly sure how that would translate to the .view() approach of B, though. If generating the pairwise distance matrix is the main desired output, I have a working Numba implementation that is ~130x faster than using cdist(x, y, metric=scipy.stats.wasserstein_distance)