ENH: Add Array API support to center_distance_matrix#2436
Open
LarytheLord wants to merge 2 commits intoscikit-bio:mainfrom
Open
ENH: Add Array API support to center_distance_matrix#2436LarytheLord wants to merge 2 commits intoscikit-bio:mainfrom
LarytheLord wants to merge 2 commits intoscikit-bio:mainfrom
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (47.05%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2436 +/- ##
==========================================
- Coverage 97.81% 97.77% -0.05%
==========================================
Files 127 127
Lines 15640 15649 +9
Branches 2882 2883 +1
==========================================
+ Hits 15299 15301 +2
- Misses 165 171 +6
- Partials 176 177 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
center_distance_matrix() currently only dispatches to the Cython implementation, which requires NumPy arrays via the buffer protocol. GPU-backed arrays (CuPy, JAX, PyTorch) cannot flow through it. Add an xp-compatible fallback path using ingest_array and xp.mean, implementing the same Gower centering (Eqs. 9.20/9.21, Legendre & Legendre 1998). NumPy arrays continue using the optimized Cython path. Array type and device are preserved for non-NumPy backends. Tests added for NumPy, PyTorch, and JAX.
…trix Add array-api-strict to CI test requirements so the Array API fallback path is exercised on every run without requiring optional GPU backends. Two new tests in TestCenterDistanceMatrixArrayAPI: - test_numpy_noncontiguous: covers the C-contiguous conversion branch by passing a Fortran-order array - test_xp_array_api_strict: covers the full xp fallback path Also adds a changelog entry for the Array API support introduced in this PR.
839b162 to
875c92c
Compare
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.
center_distance_matrix()currently only dispatches to the Cython implementation, which requires NumPy arrays via the CPython buffer protocol. This means GPU-backed arrays (CuPy, JAX, PyTorch) cannot pass throughcenter_distance_matrix()or the PCoA pipeline that depends on it.What changed
ingest_arrayandxp.meaninplace=Trueis documented as NumPy-onlyTests
TestCenterDistanceMatrixArrayAPIwith NumPy, PyTorch, and JAX backendsf_matrix(e_matrix())referenceNumerical agreement
Cython vs xp path max absolute difference at n=100: 8.88e-16
Context
This follows the same
ingest_array+xpnamespace pattern established in the composition module (centralize, vlr, closure, clr, etc.) and extends Array API support into the ordination module for the first time.Related: #2429