-
Notifications
You must be signed in to change notification settings - Fork 199
Description
From what I understood, the modern way of writing Python packages that use arrays is to use the Python array API standard instead of directly Numpy (see https://data-apis.org and also https://docs.scipy.org/doc/scipy-1.12.0/dev/api-dev/array_api.html).
Package maintainers should use https://data-apis.org/array-api-compat/ and https://data-apis.org/array-api-extra/ and write code like:
import array_api_extra as xpx
from array_api_compat import array_namespace
def compute(x):
xp = array_namespace(x)
y = xp.sum(x)
...
return xpx.atleast_nd(y, ndim=2, xp=xp)
def your_function(x, y):
xp = array_namespace(x, y)
return xp.mean(x, axis=0) + 2*xp.std(y, axis=0)It would be useful if Pythran supported this new API.
Of course, Pythran would need to support only Numpy arrays, so xp would always be as np (see https://numpy.org/doc/stable/reference/array_api.html).
Moreover, I guess it would also be theoretically possible to write an implementation of the Python array API standard for Numpy arrays using Pythran 🙂. I guess it would be quite useless except maybe for testing (see https://data-apis.org/array-api/2024.12/verification_test_suite.html and https://github.com/data-apis/array-api-tests). I'm afraid it would be a bit long to compile.