rflamary · GitHub

Conversation

@rflamary

Types of changes

Fixes #697 with backend implementation for a number of distances.

The current implementation of ot.dist uses the cdist foncton form sipy on non euclidean costs which makes it very slow. This PR is an attempt at making it faster by implementing the most common distances using the backend.

For the moeme,t backend computation are ot always faster

for instanec on a 1024x200 matrix X we have
n= 1024 , d= 200

cdist (scipy) dist 0.9.5 ot.dist (numpy) dist (torch) dist (torch, ten) dist (torch,GPU)
euclidean 0.942832 0.0836014 0.0897373 0.0932314 0.00872684 0.429742
sqeuclidean 0.798189 0.0778745 0.0659651 0.00911853 0.0744656 0.00241347
cityblock 1.2758 1.26534 6.4717 0.42605 2.14289 0.0770559
cosine 0.971009 0.970279 0.473443 0.0740105 0.00881105 0.00222607
minkowski 0.847159 0.843644 6.97861 0.614996 3.37625 0.0993479
correlation 1.01531 1.01237 0.0785626 0.0948708 0.012194 0.00431579

Motivation and context / Related issue

How has this been tested (if it applies)

PR checklist

  • I have read the CONTRIBUTING document.
  • The documentation is up-to-date with the changes I made (check build artifacts).
  • All tests passed, and additional code has been covered with new tests.
  • I have added the PR and Issue fix to the RELEASES.md file.

@rflamary rflamary changed the title [WIP] Faster backend compatible ot.dist [WIP] Faster and/or backend compatible ot.dist

Mar 20, 2025

@rflamary rflamary changed the title [WIP] Faster and/or backend compatible ot.dist [MRG] Faster and/or backend compatible ot.dist

Mar 20, 2025

@rflamary

@rflamary

Read the original on github.com ↗