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

cosine.cosine_distance: ComplexWarning: Casting complex values to real discards the imaginary part #22

Open
lemarcantoine opened this issue Mar 2, 2022 · 1 comment

Comments

@lemarcantoine
Copy link

Hello, when running:

import numpy as np
import ABXpy.distances.metrics.cosine as cosine

a = np.array([[1.17004299, 0.85545695, 1.00981605, 1.16844952, 0.63780457, 0.86987048]])
cosine.cosine_distance(a, a)

I get the following warning:

/home/username/anaconda3/lib/python3.7/site-packages/ABXpy/distances/metrics/cosine.py:25: ComplexWarning: Casting complex values to real discards the imaginary part
  d = np.array([[np.float64(np.lib.scimath.arccos(d[0, 0]) / np.pi)]])

I believe its because the inner intermediate d var is slightly higher than 1 because of a float rounding.

@lemarcantoine
Copy link
Author

I fixed it on my side by adding:

d = np.clip(d, -1, 1)

Right after the assignment of d.

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

No branches or pull requests

1 participant