Request: Support for cuPyNumeric
cuPyNumeric aims to be a drop-in replacement for NumPy, with full API compatibility achieved by automatically falling back to NumPy for any functionality which isn't yet implemented.
I suspect this should make it a trivial addition to array-api-compat, although the way it falls back to NumPy may need to be explicitly handled as it returns NumPy ndarrays from any function marked with a dot in this table: https://docs.nvidia.com/cupynumeric/latest/api/comparison.html
For example:
>>> import cupynumeric as xp
>>> from array_api_compat import is_numpy_array
>>>
>>> a = xp.linspace(0.0, 1.0, 21)
>>> is_numpy_array(a)
False
>>> b = xp.acos(a)
<cupynumeric internals>:241: RuntimeWarning: cuPyNumeric has not implemented numpy.acos and is falling back to canonical NumPy. You may notice significantly decreased performance for this function call.
Set CUPYNUMERIC_FALLBACK_STACKTRACE=1 and re-run to include a full stack trace with this warning.
>>> is_numpy_array(b)
True
>>>
I don't know if there's a preferred method to do so, but it's not difficult to programmatically check which functions do not yet have a native implementation. E.g.
>>> xp.acos.__module__
'numpy'
>>> xp.cos.__module__
'cupynumeric._ufunc.ufunc'
@seberg any thoughts?
I think this has been discussed in cupynumeric, but not sure of the current status/priority. I'll bring it up with the cupynumeric team. Not sure what is best, in practice cupynumeric should be easy since it is basically NumPy compatible (I suppose there will be some subtleties when actually testing, although I doubt they will be big issues in practice).
In principle we could of course also do it here as it should be effectively a copy paste of the NumPy version.
I believe this is a bug rather than unimplemented feature. There was a fix for that in 25.08.rc1 package, however we reverted it due to the performance regression. We will discuss how to resolve this internally and update here
I believe this is a bug rather than unimplemented feature. There was a fix for that in 25.08.rc1 package, however we reverted it due to the performance regression. We will discuss how to resolve this internally and update here
What bug are you referring to, specifically? Returning numpy arrays instead of cuPyNumeric arrays?
I would also note that the array objects in cuPyNumeric 25.8.0 (i.e. the latest I was able to obtain from PyPI) do not have an __array_namespace__ attribute, but perhaps they are otherwise Array API compliant? I haven't looked into that, personally.
Returning numpy arrays instead of cuPyNumeric arrays?
Yes, this is what I am referring to
Integrating https://github.com/data-apis/array-api-tests into cuPyNumeric's CI would be the logical next step, I think.