Skip to content

PRF Ridge - centering trick for cholesky solver - #34793

Open
cakedev0 wants to merge 13 commits into
scikit-learn:mainfrom
cakedev0:ridge/optim_cholesky
Open

PRF Ridge - centering trick for cholesky solver#34793
cakedev0 wants to merge 13 commits into
scikit-learn:mainfrom
cakedev0:ridge/optim_cholesky

Conversation

@cakedev0

@cakedev0 cakedev0 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

None, I started investigated for a speed gain while comparing speed/profiles with the scikit-learn-intelex (oneDAL) implementation.

What does this implement/fix? Explain your changes.

  • It uses an algebra trick to avoid the need for re-centering in Cholesky
  • It refactors a bit the validation so to avoid a double pass of check_array (and to avoid a copy in the algebraic centering Cholesky path).

Those relatively simple changes provide a speedups ranging from ~1.2x to 2x.

AI usage disclosure

I used AI assistance for:

  • Code generation (many iterations)
  • Comments
  • Research and understanding

Benchmarks

Benchmarks are run through the PR: probabl-ai/scikit-learn-benchmarks#31 (see bot comments with links to dashboards)

The benchmark cases are the same than the ones used to compare with scikit-learn-intelex, they are a mix of synthetic and real-world datasets.

On the intel-laptop, one case show a regression but it's a benchmark artifact: this case uses the dual path, which is not affected by this PR. And if you look at the granular timings, you'll see in both branches (main and this one) oscillate a lot.

@cakedev0 cakedev0 changed the title PRF Ridge - centering trick & fast mean & fast assert finite [WIP] PRF Ridge - centering trick & fast mean & fast assert finite Aug 21, 2026
… to svd

use_no_center_cholesky matched on solver in ("auto", "cholesky") but didn't
check the array namespace. With array API dispatch to a non-numpy namespace,
solver="auto" silently resolves to "svd" instead of "cholesky" (see
resolve_solver), which needs X to actually be centered. This left X
uncentered while running svd, causing
test_cross_val_predict_array_api_compliance[...-Ridge] failures on
array_api_strict and torch in CI.
@cakedev0 cakedev0 changed the title [WIP] PRF Ridge - centering trick & fast mean & fast assert finite [WIP] PRF Ridge - centering trick Aug 25, 2026
Comment on lines +396 to +399
elif is_X_sparse and fit_intercept:
# when `fit_intercept=True`, `mean_variance_axis` will be called on X
# and it requires csr/csc format
return ["csr", "csc"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note to reviewers: this addition is needed because I now pass check_input=False to _preprocess_data which would have done this logic.

@cakedev0 cakedev0 changed the title [WIP] PRF Ridge - centering trick PRF Ridge - centering trick for cholesky solver Aug 27, 2026
@cakedev0
cakedev0 marked this pull request as ready for review August 27, 2026 06:55
@cakedev0

Copy link
Copy Markdown
Contributor Author

cc @antoinebaker, I was told you're the specialist of this kind of tricks πŸ˜‰

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant