Skip to content
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

dist function errors with a callable metric #378

Closed
zdk123 opened this issue May 13, 2022 · 2 comments · Fixed by #379
Closed

dist function errors with a callable metric #378

zdk123 opened this issue May 13, 2022 · 2 comments · Fixed by #379

Comments

@zdk123
Copy link
Contributor

zdk123 commented May 13, 2022

Describe the bug

According to the docstring of ot.dist, the metric object can be be a callable function.

However, L235 clearly expects [only] a string.

Looks like this was broken in commit 0c5899

To Reproduce

Steps to reproduce the behavior:

import ot
import numpy as np

n = 10
a = np.random.randn(n,3)
b = np.random.randn(n,3)

eucl = lambda a, b: np.sum(np.square(a - b))
ot.dist(a, b, metric = eucl)

bug:

    if metric.endswith("minkowski"):
AttributeError: 'function' object has no attribute 'endswith'

Output of the following code snippet:

import ot; print("POT", ot.__version__)
# POT 0.8.2
@rflamary
Copy link
Collaborator

Hello @zdk123

Indeed this is a bug, we should just test if metric is a string before with
if type(metric)==str and metric.endswith("minkowski"):

Could you do a quick PR with this?

@zdk123
Copy link
Contributor Author

zdk123 commented May 13, 2022

sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants