Skip to content

[MRG] Faster and/or backend compatible ot.dist #701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 20, 2025
Merged

Conversation

rflamary
Copy link
Collaborator

@rflamary rflamary commented Nov 27, 2024

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.

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 89.47368% with 8 lines in your changes missing coverage. Please review.

Project coverage is 97.10%. Comparing base (cbdf979) to head (403b13a).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #701      +/-   ##
==========================================
- Coverage   97.13%   97.10%   -0.04%     
==========================================
  Files         100      100              
  Lines       20369    20428      +59     
==========================================
+ Hits        19786    19837      +51     
- Misses        583      591       +8     
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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 merged commit 928a67a into master Mar 20, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

switch to numba implementation of scipy cdist
1 participant