Skip to content

[MRG] Use the weights w in ot.dist for the cityblock metric - #859

Merged
rflamary merged 2 commits into
PythonOT:masterfrom
itzzdev09:dist-cityblock-weights
Sep 17, 2026
Merged

rflamary merged 2 commits into
PythonOT:masterfrom
itzzdev09:dist-cityblock-weights

Conversation

@itzzdev09

Copy link
Copy Markdown
Contributor

Types of changes

  • Bug fix

Description

ot.dist documents that w is used by the cityblock and minkowski metrics, but the cityblock branch never read it and returned the unweighted distance:

import numpy as np, ot
from scipy.spatial.distance import cdist
x, y, w = np.array([[0., 0.]]), np.array([[1., 1.]]), np.array([1., 2.])
ot.dist(x, y, metric="cityblock", w=w)   # [[2.]]
cdist(x, y, metric="cityblock", w=w)     # [[3.]]

The weighted minkowski branch already handled this. cityblock now applies w the same way, in both the use_tensor=True and loop implementations.

How has this been tested

Added test_dist_weighted_cityblock, which compares against scipy.spatial.distance.cdist for both implementations. It fails on master and passes with this change. test/test_utils.py passes.

Checklist

  • My change requires a change to the documentation. (not needed)
  • I have added tests to cover my changes.
  • I have updated the RELEASES.md file.

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.85%. Comparing base (10c74a1) to head (7f52892).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #859      +/-   ##
==========================================
- Coverage   96.86%   96.85%   -0.01%     
==========================================
  Files         128      128              
  Lines       26181    26197      +16     
==========================================
+ Hits        25359    25373      +14     
- Misses        822      824       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rflamary
rflamary merged commit 649b968 into PythonOT:master Sep 17, 2026
21 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.

2 participants