Skip to content

Fix Minkowski distance for infinite order - #3681

Open
WeiLiuu wants to merge 2 commits into
Lightning-AI:masterfrom
WeiLiuu:fix/minkowski-infinite-order
Open

WeiLiuu wants to merge 2 commits into
Lightning-AI:masterfrom
WeiLiuu:fix/minkowski-infinite-order

Conversation

@WeiLiuu

@WeiLiuu WeiLiuu commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #3680

For p=float("inf"), the final exponent was zero, so even identical inputs had a distance of 1. Take the maximum absolute difference and use the same maximum when combining batches or distributed states. Finite orders still accumulate the sum of powers.

The tests compare both APIs to SciPy, including identical inputs and an uneven split where the largest error is in the first batch. All 46 CPU tests in the Minkowski module passed. A two-process Gloo run also matched SciPy on both ranks.

AI use: Claude and Codex did most of the work, the patch and the test, and drafted this text.

Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

Use the maximum absolute error within each batch and across metric
states when p is infinite. The finite-order power sum gives a final
exponent of zero at infinity, even when the inputs are identical.

Compare both APIs with SciPy on identical inputs and uneven batches.
@codecov-commenter

codecov-commenter commented Nov 28, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 35%. Comparing base (d184220) to head (ca9b985).
⚠️ Report is 70 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #3681    +/-   ##
=======================================
- Coverage      37%     35%    -1%     
=======================================
  Files         349     357     +8     
  Lines       19901   20294   +393     
=======================================
- Hits         7264    7201    -63     
- Misses      12637   13093   +456     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@atishay-kasliwal atishay-kasliwal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared minkowski_distance and MinkowskiDistance (two batches) with scipy for p = 1, 2, 3.5 and inf. p=inf now gives 2.71469, the same as scipy.spatial.distance.chebyshev; master returned 1.0. The finite orders are unchanged and match scipy...minkowski.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite-order Minkowski distance returns 1 for identical inputs

3 participants