Apply new input validation to cuml.metrics.cluster - #8059
Merged
rapids-bot[bot] merged 4 commits intoMay 6, 2026
Merged
Conversation
Replace input_to_cuml_array with check_array / check_consistent_length from cuml.internals.validation. Device pointers are now accessed via .data.ptr on the returned cupy arrays. ensure_min_samples=0 preserves the existing behaviour for empty inputs (exercised by test_adjusted_rand_score_small). xref NVIDIA#7998
Replace input_to_cupy_array with check_array from cuml.internals.validation. The check now accepts 1-D or (n, 1) inputs and rejects anything wider, matching the legacy check_cols=1 behaviour. xref NVIDIA#7998
Replace input_to_cuml_array in prepare_cluster_metric_inputs (utils.py) with check_array / check_consistent_length from cuml.internals.validation. The helper now returns plain cupy int32 ndarrays instead of CumlArrays, so the four Cython callers (v_measure, mutual_info_score, homogeneity_score, completeness_score) are updated to access the device pointer via .data.ptr rather than .ptr. ensure_min_samples=0 is used throughout to preserve the existing behaviour for empty inputs. xref NVIDIA#7998
Replace input_to_cuml_array with check_array / check_consistent_length from cuml.internals.validation in _silhouette_coeff. Device pointers are now accessed via .data.ptr on the returned cupy arrays. Pass ensure_all_finite=False for the sil_scores output buffer: it is a pre-allocated cp.empty array that may contain uninitialised values (including NaN) before the C++ kernel writes into it, so checking for finite values up-front would raise a spurious ValueError. xref NVIDIA#7998
cuml.metrics.cluster|
Caution Review failedFailed to post review comments 📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR refactors clustering metrics modules to replace legacy input-handling utilities with standardized NumPy-based validation (check_array, check_consistent_length) and updates pointer extraction to use the ChangesClustering Metrics Validation Refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
jcrist
approved these changes
May 6, 2026
Member
|
/merge |
aminehd
added a commit
to aminehd/cuml
that referenced
this pull request
Jul 9, 2026
…IA#7199) homogeneity/completeness/v_measure/mutual_info must be invariant to a permutation of label values, for any int/float input dtype. int64 labels (the cp.array default) were passed to C++ funcs taking `const int*` (int32) and misread, giving wrong, permutation-variant scores. Already fixed on main by NVIDIA#8059 and NVIDIA#8269 (which force int32); this adds the missing regression test. Signed-off-by: Amineh Dadsetan <amineh.dadsetan@gmail.com>
rapids-bot Bot
pushed a commit
that referenced
this pull request
Jul 10, 2026
…7199) (#8355) Regression test for #7199. **Problem:** `homogeneity_score` / `completeness_score` / `v_measure_score` / `mutual_info_score` were not invariant to permuting label values — `metric(y, 1 - y_pred) != metric(y, y_pred)`. **Cause:** int64 labels (the `cp.array([...])` default) were passed to C++ functions that take `const int*` (int32), so the bytes were misread → garbage labels → wrong scores. float labels were rejected outright. **Status:** already fixed on `main` by #8059 and #8269 (they force int32 in `prepare_cluster_metric_inputs`), but no existing cluster-metric test used anything other than int32, so the bug was never caught. **This PR** adds `test_cluster_metric_label_permutation_invariance`: for each of the four metrics it asserts the score is invariant to a label permutation and matches scikit-learn, across int32 / int64 / float32 inputs. Fails on the code before #8059/#8269, passes after. Authors: - https://github.com/aminehd Approvers: - Victor Lafargue (https://github.com/viclafargue) URL: #8355
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Apply new input validation to
cuml.metrics.cluster.Part of #7998