Skip to content
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
8 changes: 4 additions & 4 deletions python/cuml/cuml/metrics/pairwise_kernels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# SPDX-FileCopyrightText: Copyright (c) 2022-2025, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
#
import inspect
Expand All @@ -9,7 +9,7 @@
from numba import cuda

import cuml.internals
from cuml.internals.input_utils import input_to_cupy_array
from cuml.internals.validation import check_array
from cuml.metrics import pairwise_distances


Expand Down Expand Up @@ -275,11 +275,11 @@ def pairwise_kernels(
[5.04347663e-07, 2.03468369e-04],
[4.24835426e-18, 2.54366565e-13]])
"""
X = input_to_cupy_array(X).array
X = check_array(X, input_name="X")
if Y is None:
Y = X
else:
Y = input_to_cupy_array(Y).array
Y = check_array(Y, input_name="Y")
if X.shape[1] != Y.shape[1]:
Comment on lines +278 to 283

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

convert_dtype behavior was dropped in the new validation path.

At Line 282, Y is validated but never coerced to X.dtype, so convert_dtype (Line 187) is effectively ignored. That changes prior mixed-dtype behavior and breaks the function’s documented contract.

Proposed fix
     X = check_array(X, input_name="X")
     if Y is None:
         Y = X
     else:
         Y = check_array(Y, input_name="Y")
+        if convert_dtype and Y.dtype != X.dtype:
+            Y = Y.astype(X.dtype, copy=False)

As per coding guidelines, “API breaking changes to Python estimator interfaces … or breaking backward compatibility require at least one release cycle for deprecations.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
X = check_array(X, input_name="X")
if Y is None:
Y = X
else:
Y = input_to_cupy_array(Y).array
Y = check_array(Y, input_name="Y")
if X.shape[1] != Y.shape[1]:
X = check_array(X, input_name="X")
if Y is None:
Y = X
else:
Y = check_array(Y, input_name="Y")
if convert_dtype and Y.dtype != X.dtype:
Y = Y.astype(X.dtype, copy=False)
if X.shape[1] != Y.shape[1]:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@python/cuml/cuml/metrics/pairwise_kernels.py` around lines 278 - 283, The
validation path drops the previous dtype coercion so Y is no longer converted to
X.dtype and the convert_dtype behavior is ignored; when validating Y inside
pairwise_kernels, call check_array with the dtype matching X (e.g.,
check_array(Y, input_name="Y", dtype=X.dtype)) or pass the existing
convert_dtype flag into check_array so Y is coerced to X.dtype, ensuring X and Y
keep the same dtype and preserving the original mixed-dtype behavior.

raise ValueError("X and Y have different dimensions.")

Expand Down
Loading