Repository navigation
feat: support array-api - #2071
Merged
Merged
Conversation
…a into ig/array_api_continue import merge
flying-sheep
left a comment
Member
There was a problem hiding this comment.
OK, I just went over general code style, nothing JAX-related
ilan-gold
reviewed
Aug 19, 2025
Comment on lines
+670
to
+675
| dest = self._adata_ref._X | ||
| # Handles read-only NumPy views from backend arrays like JAX by | ||
| # making a writable copy so in-place assignment on views can succeed. | ||
| if isinstance(dest, np.ndarray) and not dest.flags.writeable: | ||
| dest = np.array(dest, copy=True) # make a fresh, writable buffer | ||
| self._adata_ref._X = dest |
Contributor
There was a problem hiding this comment.
I would actually just let the error be thrown in this case. If something isn't writeable, I don't think that's our responsibility to handle
… with copying introduced as an extra precaution
ilan-gold
reviewed
Aug 21, 2025
ilan-gold
reviewed
Aug 21, 2025
This was referenced Feb 4, 2026
flying-sheep
approved these changes
Feb 6, 2026
flying-sheep
left a comment
Member
There was a problem hiding this comment.
looks great, I just have some clarifying questions!
Co-authored-by: Philipp A. <flying-sheep@web.de>
Co-authored-by: Philipp A. <flying-sheep@web.de>
for more information, see https://pre-commit.ci
flying-sheep
reviewed
Feb 6, 2026
| # As of 2023 dlpack, it must be possible for a library to export to this, see: https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.__dlpack__.html#array_api.array.__dlpack__ | ||
| # However, https://github.com/numpy/numpy/issues/20742 means we can't roundtrip jax arrays using dlpack so better to just let numpy do its thing in asarray. | ||
| self.add_array(np.asarray(self.get_default())) | ||
| res = np.from_dlpack(self._manager[(1, 0)]) |
Member
There was a problem hiding this comment.
Suggested change
| res = np.from_dlpack(self._manager[(1, 0)]) | |
| res = np.from_dlpack(self._manager[1, 0]) |
ilan-gold
approved these changes
Feb 6, 2026
katosh
added a commit
to settylab/anndata
that referenced
this pull request
Feb 10, 2026
Two-tier detection: tier 1 uses the canonical has_xp() protocol check from anndata.compat (catches JAX, numpy >=2.0); tier 2 falls back to duck-typing (shape/dtype/ndim) for arrays that don't yet implement the full protocol (PyTorch, TensorFlow). Also uses __array_namespace__() for backend label resolution and updates stale PR scverse#2063 → scverse#2071.
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.
fixes #1731, fixes #1195, fixes #697
First step in getting anndata concat and test generation to work properly with JAX, (and Cubed potentially), without just converting everything into NumPy.
Random data creation and shape handling use xp.asarray so arrays stay in their original backend where possible. I also updated concat paths to actually check types before converting, added helpers for sparse detection and array API checks, and made sure backend arrays only get turned into NumPy when absolutely necessary. This fixes a bunch of concat-related test failures.
It’s still not perfect. Some pandas calls in concat still force conversion to NumPy, so the data gets copied instead of being used directly. Cubed support is only a placeholder right now. Type detection might still be a bit too broad, which can lead to extra conversions. Works for NumPy and JAX in tests, but I haven’t tried other backends.