-
Notifications
You must be signed in to change notification settings - Fork 41
Description
When writing code that should be widely compatible with multiple Array implementations, it would be helpful if array-api-compat could return a strict Array API namespace, that did not blend the Array API with the target type's namespace.
E.g., in:
import numpy as np
import array_api_compat
import dask.array as da
d = da.from_array(np.arange(256), chunks=(12,))
nx = array_api_compat.get_namespace(d)The nx object contains non-Array-API-compatible members, such as flatnonzero. This caused some confusion when examining dask/dask#11298.
While developing, I'd like to get a namespace that only consists of Array API functions. I presume the additional blending is done to produce a minimally modified version of a library namespace that, like NumPy, supports the Array API, but also does a bunch of other things. However, I'd argue that this is unhelpful in the context of developing for the Array API. In our example above, I'd be tempted to use flatnonzero when, in fact, that function is not in the array API. Worse, in the case above, that would not work (the only guaranteed Array API compatible dask implementations come from array-api-compat).
Since the blending of namespaces has the potential for confusion, and reduces the utility of the namespace in coding for Array API compatibility, I am curious why it is the default. However, since it is the default, I'd like to request a new feature, along the lines of:
nx = array_api_compat.get_namespace(d, strict=True)
@lucascolley mentioned to me the array-api-strict package for use in test suites, but while helpful, it is somewhat orthogonal to my request here.
I am only now really starting to dig into Array API compatibility, thinking about scikit-image in particular, so apologies if I missed some obvious existing mechanisms of doing what I want.