Skip to content

Apply new validation to cuml.random_projection - #8009

Merged
rapids-bot[bot] merged 1 commit into
NVIDIA:mainfrom
jcrist:validation-random-projection
Apr 24, 2026
Merged

Apply new validation to cuml.random_projection#8009
rapids-bot[bot] merged 1 commit into
NVIDIA:mainfrom
jcrist:validation-random-projection

Conversation

@jcrist

@jcrist jcrist commented Apr 23, 2026

Copy link
Copy Markdown
Member

Fixes #8003.

Note that this fixes a small bug in fit, bringing the meaning of convert_dtype in line with the rest of cuml.

@jcrist jcrist self-assigned this Apr 23, 2026
@jcrist
jcrist requested a review from a team as a code owner April 23, 2026 14:33
@jcrist jcrist added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Apr 23, 2026
@jcrist
jcrist requested a review from viclafargue April 23, 2026 14:33
@jcrist jcrist added the sklearn-api-compat Issues around cuml matching sklearn API conventions/standards label Apr 23, 2026
@pytest.mark.parametrize("cls", classes)
@pytest.mark.parametrize("dtype", ["float32", "float64"])
def test_components_dtype(cls, dtype):
def test_components_and_output_dtype(cls, dtype):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This test and behavior was incorrect and doesn't match our intended behavior of convert_dtype. I view the change here as a bugfix. Also note that I wrote the code (and test) a few months ago, so I know this wasn't intentional for a specific user need, just a buggy implementation of a standard kwarg.

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request refactors the random projection module to use centralized input validation (check_inputs) for both fit and transform methods. It updates dtype handling to preserve input dtypes (float32/float64) throughout the pipeline, modifies sparse matrix construction to use cupyx.scipy.sparse, and adjusts test expectations and sklearn compatibility configurations accordingly.

Changes

Cohort / File(s) Summary
Input Validation Refactoring
python/cuml/cuml/random_projection/random_projection.py
Replaces manual fit/transform input handling with check_inputs validation. Changes reflection reset semantics from reset=True to reset="type", removes manual dtype logic tied to convert_dtype, validates/coerces X to float32/float64, and updates sparse matrix construction to use cupyx.scipy.sparse. Simplifies sparse handling in output generation.
Test Suite Updates
python/cuml/tests/test_random_projection.py
Renames test_components_dtype to test_components_and_output_dtype and updates validation to verify that projection matrix and fit_transform preserve input dtype. Removes prior expectations for default float32 outputs and dtype alteration via convert_dtype=False.
Sklearn Compatibility Configuration
python/cuml/tests/test_sklearn_compatibility.py
Removes xfail decorators for complex-data, object-dtype, empty-data, and NaN/inf checks on GaussianRandomProjection and SparseRandomProjection, while retaining other compatibility xfail configurations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Apply new validation to cuml.random_projection' directly and clearly describes the main change: applying new validation to the random_projection module.
Linked Issues check ✅ Passed The PR fully addresses issue #8003's objective to update cuml.random_projection to new input validation by implementing centralized check_inputs validation/coercion in fit/transform.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the new input validation in random_projection module and updating tests accordingly; no out-of-scope modifications detected.
Description check ✅ Passed The pull request description directly references the related issue (#8003) and briefly explains the intent: applying new validation to random_projection and fixing a convert_dtype bug.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@python/cuml/cuml/random_projection/random_projection.py`:
- Around line 89-97: The fit() path currently calls check_inputs(...) with
accept_sparse=True which allows any sparse format but transform() only accepts
CSR/CSC; update the call in random_projection.py (inside the fit method where
check_inputs is invoked) to restrict accept_sparse to the same formats as
transform(), e.g. accept_sparse=("csr", "csc"), so fit(), transform(), and
fit_transform() accept the same sparse matrix types and avoid inconsistency.

In `@python/cuml/tests/test_random_projection.py`:
- Around line 170-177: The test test_components_and_output_dtype only exercises
dense inputs; update it to parametrize over sparse inputs as well (e.g., add a
parameter like "sparse" or "input_format") and when sparse=True convert X to a
scipy.sparse CSR/CSC matrix before calling model = cls(...); ensure you still
call transformed = model.fit_transform(X) and assert both
model.components_.dtype == dtype and transformed.dtype == dtype for the sparse
branch so the sparse conversion/validation path is covered; reference the
existing symbols random_array, classes, test_components_and_output_dtype,
model.fit_transform, model.components_, and transformed when locating where to
add the new param and assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 72da559c-8696-4258-921f-557bd8c006fa

📥 Commits

Reviewing files that changed from the base of the PR and between 42f57b5 and f41be04.

📒 Files selected for processing (3)
  • python/cuml/cuml/random_projection/random_projection.py
  • python/cuml/tests/test_random_projection.py
  • python/cuml/tests/test_sklearn_compatibility.py
💤 Files with no reviewable changes (1)
  • python/cuml/tests/test_sklearn_compatibility.py

Comment thread python/cuml/cuml/random_projection/random_projection.py
Comment thread python/cuml/tests/test_random_projection.py
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Apr 23, 2026

@viclafargue viclafargue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Just a bunch of questions to draw attention to the input processing in the fit function. Pre-approving should be good to go once solved.

Comment thread python/cuml/cuml/random_projection/random_projection.py
Comment thread python/cuml/cuml/random_projection/random_projection.py
@jcrist

jcrist commented Apr 24, 2026

Copy link
Copy Markdown
Member Author

/merge

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

Labels

Cython / Python Cython or Python issue improvement Improvement / enhancement to an existing function non-breaking Non-breaking change sklearn-api-compat Issues around cuml matching sklearn API conventions/standards

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update cuml.random_projection to new input validation

4 participants