getkeops / keops

KErnel OPerationS, on CPUs and GPUs, with autodiff and without memory overflows
https://www.kernel-operations.io
MIT License
1.05k stars 64 forks source link

sort operation #358

Closed DavidLapous closed 9 months ago

DavidLapous commented 9 months ago

Hi, and many thanks for your work ! I'm trying to optimize some part of my code using pykeops; and one piece that seems pykeops-friendly to me is computing sliced wasserstein kernels, as there is a bunch distance, scalar products and norms to compute there. However, to compute (1d)wasserstein on we need to be able to sort w.r.t. one axis (as the 1d wasserstein distance can be efficiently computed with sort+norm). I basically want to do the following computations to compute a sliced wassersein distance matrix

My issue here is that I cannot find a sort operation on lazytensors to compute the wasserstein 1 distance on the "num_points" axis. Is there such a "sort along one axis" operation ? or is this kind of computation out of scope of this library ? I didn't find a way to do it with geomloss either.

jeanfeydy commented 9 months ago

Hi David,

Thanks for your comment! This operation is out of the scope of KeOps, since NumPy/PyTorch already provide an optimal workflow:

This is the whole point of sliced metrics: you don't need fancy code to compute them efficiently :-)

Best regards, Jean

DavidLapous commented 9 months ago

Thanks Jean for your answer! I'll stick to my current implementation then ;) -- David