Skip to content

Adding array API support to sklearn.covariance #33584

Open

Description

@betatim

This is a mega-issue tracking work on adding array API support to the parts of sklearn.covariance where it makes sense.

Important

This is a fresh issue that still needs refining before it is ready for contribution. Please don't yet open PRs.

This is a list of all the items in the covariance module, they are sorted by (roughly) the order in which they should be tackled.

Functions listed here should be tackled with the class (from above):

Please refer to this issue when opening a PR to tackle something from this list. Use Towards #33584 to refer to this issue, do not use "closes" or "fixes" (that would close this issue when merging your PR).

After the LedoitWolf and OAS PRs are merged we will consider opening this issue for a wider audience of contributors.

The next thing to work out is in which order items should be tackled. This will require looking at the existing PR for LedoitWolf and investigating how the other estimator classes depend on each other. If you investigate this and find out an order that makes sense please post in this issue.

Activity

  1. bruAristimunha commented on Mar 19, 2026

    @bruAristimunha
    Contributor

    hey @betatim!

    I generate the graph dependency in the covariance classes:

    pip install pylint
    pyreverse -o png -p covariance sklearn/covariance/*.py
    Image

    I think, in this context, the best strategy is to focus on the empirical covariance first, and then a breadth-first search should solve the rest, maybe the order should be:

    1. FEA Make LedoitWolf estimator array API compatible #33573, and empirical covariance.
    2. ShrunkCovariance + OAS + shrunk_covariance() + oas()
    3. GraphicalLasso + GraphicalLassoCV + graphical_lasso()
    4. MinCovDet
    5. EllipticEnvelope

    I can start the ShruckCovariance or OAS. I feel we should include the functionality and the classes in the PR. I can do the empirical_covariance() + EmpiricalCovariance too!

  2. betatim commented on Mar 19, 2026

    @betatim
    MemberAuthor

    I like your suggested order. Doing one class and the corresponding function in one PR is good. I think beyond that we risk getting big diffs which are hard to review (review hardness probably scales quadratically or exponentially with diff size).

    TIL about pyreverse!

  3. bruAristimunha commented on Mar 20, 2026

    @bruAristimunha
    Contributor

    I'm starting the empirical covariance branch, and I think the best strategy is to build it on top of your PR. You end up modifying some functions that are necessary for empirical covariance.

    I think if you need it, maybe @agramfort can help with the review.

  4. bruAristimunha commented on Mar 20, 2026

    @bruAristimunha
    Contributor

    you are super close to fix the empirical covariance too, so i just comment the last point: #33573 (review)

  5. bruAristimunha commented on Apr 2, 2026

    @bruAristimunha
    Contributor

    Hey @betatim,

    Many thanks for your work with #33573. Now that the PR is almost merged, I would like to ask if it would be okay if I create a PR for the fast mcd, or even the other covariances, and request your review. As this aligns with my research agenda at Pyriemman, I can contribute my time and dedication to help convert all the covariances by the next release in 2 months.

    Do you think this would work for you?

    I would also be happy to accommodate any other request that might help or facilitate this integration.

    Again, many thanks for your time on this 🙏🏽

  6. betatim commented on Apr 14, 2026

    @betatim
    MemberAuthor

    Yes I think that makes sense. Apologies for the very very delayed reply.

  7. AbdulAliMamnun commented on Sep 4, 2026

    @AbdulAliMamnun

    Hi! I'd like to work on ShrunkCovariance and the shrunk_covariance function, following the pattern established in #33573 and the OAS conversion.

    One thing I want to flag before starting: shrunk_covariance currently accepts n-dimensional input (allow_nd=True, with axis1=-2, axis2=-1 on the trace), so it supports stacks of covariance matrices rather than just a single 2-D one. I'll check whether the existing array API helpers handle the batched case and will follow up here if it turns out to need a design decision rather than a straight port.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions