Skip to content

[MRG] Crash when computing weightless Hamming distance & Doc build #402

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 6 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ incomplete transport plan above a certain size (slightly above 46k, its square b
roughly 2^31) (PR #381)
- Error raised when mass mismatch in emd2 (PR #386)
- Fixed an issue where a pytorch example would throw an error if executed on a GPU (Issue #389, PR #391)
- Added a work-around for scipy's bug, where you cannot compute the Hamming distance with a "None" weight attribute. (Issue #400, PR #402)
- Fixed an issue where the doc could not be built due to some changes in matplotlib's API (Issue #403, PR #402)


## 0.8.2
Expand Down
4 changes: 2 additions & 2 deletions examples/barycenters/plot_barycenter_1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
ys = B_l2[:, i]
verts.append(list(zip(x, ys)))

ax = plt.gcf().gca(projection='3d')
ax = plt.gcf().add_subplot(projection='3d')

poly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])
poly.set_alpha(0.7)
Expand All @@ -128,7 +128,7 @@
ys = B_wass[:, i]
verts.append(list(zip(x, ys)))

ax = plt.gcf().gca(projection='3d')
ax = plt.gcf().add_subplot(projection='3d')

poly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list])
poly.set_alpha(0.7)
Expand Down
4 changes: 2 additions & 2 deletions examples/unbalanced-partial/plot_UOT_barycenter_1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
ys = B_l2[:, i]
verts.append(list(zip(x, ys)))

ax = pl.gcf().gca(projection='3d')
ax = pl.gcf().add_subplot(projection='3d')

poly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list])
poly.set_alpha(0.7)
Expand All @@ -149,7 +149,7 @@
ys = B_wass[:, i]
verts.append(list(zip(x, ys)))

ax = pl.gcf().gca(projection='3d')
ax = pl.gcf().add_subplot(projection='3d')

poly = PolyCollection(verts, facecolors=[cmap(a) for a in weight_list])
poly.set_alpha(0.7)
Expand Down
4 changes: 3 additions & 1 deletion ot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ def dist(x1, x2=None, metric='sqeuclidean', p=2, w=None):
else:
if isinstance(metric, str) and metric.endswith("minkowski"):
return cdist(x1, x2, metric=metric, p=p, w=w)
return cdist(x1, x2, metric=metric, w=w)
if w is not None:
return cdist(x1, x2, metric=metric, w=w)
return cdist(x1, x2, metric=metric)


def dist0(n, method='lin_square'):
Expand Down
1 change: 1 addition & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def test_dist():
for metric in metrics_w:
print(metric)
ot.dist(x, x, metric=metric, p=3, w=np.random.random((2, )))
ot.dist(x, x, metric=metric, p=3, w=None) # check that not having any weight does not cause issues
for metric in metrics:
print(metric)
ot.dist(x, x, metric=metric, p=3)
Expand Down