feat: add Array API support via array-api-compat - #4179
Conversation
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
flying-sheep
left a comment
There was a problem hiding this comment.
OK, please remember the comments from the fast-array-utils PR, e.g. we agreed to handle singledispatch functions like this: https://github.com/scverse/fast-array-utils/blob/febaf245ecd6da849c2331638219f649935d5a21/src/fast_array_utils/stats/_power.py#L38-L39
We also need tests. There’s MAP_ARRAY_TYPES which should gain an entry, which will make many many tests run with the type you add. We can discuss how to best exclude certain tests, for starters you can just add it and make some of the tests fail – that’ll show you where things aren’t working yet (and might or might not be fixed in this PR)
Please also add a release note (hatch run towncrier:create 4179.feat.md)
for more information, see https://pre-commit.ci
…lia-k510/scanpy into array-api-compat-integration
for more information, see https://pre-commit.ci
…lia-k510/scanpy into array-api-compat-integration
…lia-k510/scanpy into array-api-compat-integration
There was a problem hiding this comment.
Looking good! Just nitpicks left in the code that’s there.
One big change we should do is updating the array type metadata so it lists Array API support.
The docs currently have one central table and each function has its own little info box.
Since you know what’s going to be supported, you should update the metadata by adding an aa tag and filling out the support here (so far, np means numpy, sp means scipy sparse, da means dask, da[...] means “... in dask”, and sp[csc] means “scipy sparse with csc format”):
Lines 178 to 210 in fc0b419
If you want, you can also update the Sphinx code, but you don’t need to learn how to do that if you don’t want to. I’ll happily do that myself.
| return metadata(package) | ||
|
|
||
|
|
||
| def get_namespace(x) -> ModuleType: |
There was a problem hiding this comment.
Did I forget something or why aren’t we using types from here? https://array-api.readthedocs.io/en/latest/index.html
There was a problem hiding this comment.
I think it is just a leftover one that I forgot to change. I ended up switching to using HasArrayNamespace from fast-array-utils for x, since that's what we already dispatch on everywhere. So my question is, would it be better to stick to fast-array-utils or switch to a proper ArrayNamespace instead?
This adds Array API support to scanpy's preprocessing pipeline, where I am planning to use JAX as the test case. The goal is for someone to put a JAX array into
adata.Xand run the usual pipeline without the array getting silently pulled to CPU partway through. It builds on the recentfast-array-utilswork, which means a lot of the heavy lifting (sums, means, variances) already works across backends.