8000 FIX dtype handling regression in pairwise distance computation by Shree7676 · Pull Request #29746 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

FIX dtype handling regression in pairwise distance computation #29746

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 2 commits into from
Aug 30, 2024
Merged
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
12 changes: 6 additions & 6 deletions sklearn/metrics/pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
from .. import config_context
from ..exceptions import DataConversionWarning
from ..preprocessing import normalize
from ..utils import (
check_array,
gen_batches,
gen_even_slices,
)
from ..utils import check_array, gen_batches, gen_even_slices
from ..utils._array_api import (
_fill_or_add_to_diagonal,
_find_matching_floating_dtype,
Expand Down Expand Up @@ -1169,7 +1165,11 @@ def cosine_distances(X, Y=None):
# TODO: remove the xp.asarray calls once the following is fixed:
# https://github.com/data-apis/array-api-compat/issues/177
device_ = device(S)
S = xp.clip(S, xp.asarray(0.0, device=device_), xp.asarray(2.0, device=device_))
S = xp.clip(
S,
xp.asarray(0.0, device=device_, dtype=S.dtype),
xp.asarray(2.0, device=device_, dtype=S.dtype),
)
if X is Y or Y is None:
# Ensure that distances between vectors and themselves are set to 0.0.
# This may not be the case due to floating point rounding errors.
Expand Down
0