Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@icfaust
Copy link
Contributor

@icfaust icfaust commented Sep 16, 2025

Follow on to #31784 (which is a follow-up to #30777), the conditions laid out in documentation for PCA: https://scikit-learn.org/dev/modules/array_api.html#estimators states:

PCA with svd_solver="full", svd_solver="randomized" and power_iteration_normalizer="QR")

The documentation for PCA states for power_iteration_normalizer ("https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html) that:

Power iteration normalizer for randomized SVD solver. Not used by ARPACK. See randomized_svd for more details.

This is leading to array API support failures in our repository (uxlfoundation/scikit-learn-intelex#2578) as we prep for your 1.8 release.

The logic should swap from a whitelist to a blacklist to speed and simplify logic, thereby only checking the power_iteration_normalizer if svd_solver is either 1) "randomized" or _fit_svd_solver is set to "randomized". This corrects the logic to probe for the _fit_svd_solver if available (to handle the svd_sovler=auto condition) or fall back to checking svd_solver if the PCA estimator has not been fit.

I'm not sure how to update the documentation to reflect this as the 'covariance_eigh' solver also supports array API but is not reflected in the documentation.
@OmarManzoor @lesteve

@github-actions
Copy link

github-actions bot commented Sep 16, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: d3f9aaf. Link to the linter CI: here

@icfaust icfaust changed the title [fix] Repair PCA array API support tag for svd_solver="full" [fix] Repair PCA array API support tag for svd_solver="full" or "auto" Sep 16, 2025
@icfaust icfaust changed the title [fix] Repair PCA array API support tag for svd_solver="full" or "auto" [fix] Repair PCA array API support tag for svd_solvers "full", "covariance_eigh", or "auto" Sep 16, 2025
@icfaust icfaust changed the title [fix] Repair PCA array API support tag for svd_solvers "full", "covariance_eigh", or "auto" [fix] Repair PCA array API support tag for svd_solver "full", "covariance_eigh", or "auto" Sep 16, 2025
@icfaust icfaust changed the title [fix] Repair PCA array API support tag for svd_solver "full", "covariance_eigh", or "auto" FIX: Repair PCA array API support tag for svd_solver "full", "covariance_eigh", or "auto" Sep 16, 2025
Copy link
Contributor

@OmarManzoor OmarManzoor left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @icfaust

If the covariance_eigh solver supports the array api then you can simply add in the current docs for array_api where PCA is already mentioned and add covariance_eigh as an additional value.

Copy link
Contributor

@OmarManzoor OmarManzoor left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @icfaust

@OmarManzoor OmarManzoor added the Waiting for Second Reviewer First reviewer is done, need a second one! label Sep 17, 2025
@OmarManzoor
Copy link
Contributor

CC: @ogrisel or @lesteve for a second review.

self.svd_solver in ["full", "randomized"]
and self.power_iteration_normalizer == "QR"
solver = getattr(self, "_fit_svd_solver", self.svd_solver)
tags.array_api_support = solver not in ["arpack", "randomized"] or (
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing this!

I would keep a whitelist here because for now array API is available in a few cases. It also makes it easier to check that the documentation and the code match.

If the documentation is correct I would expect something like this?

tags.array_api_support = solver in ["full", "covariance_eigh"] or (solver == "randomized" and self.power_iteration_normalizer == "QR")

@lesteve
Copy link
Member

lesteve commented Sep 23, 2025

Merging this one, thanks!

@lesteve lesteve merged commit 92f14e2 into scikit-learn:main Sep 23, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants