Python Array API Support#
Note
cupy.array_api
will be removed in CuPy v14 because its NumPy counterpart numpy.array_api
has been removed.
The root module cupy.*
is now compatible with the Array API specification as it mirrors the NumPy v2 API.
Use the Array API compatibility library to develop applications compatible with various array libraries, including CuPy, NumPy, and PyTorch.
The Python array API standard aims to provide a coherent set of APIs for array and tensor libraries developed by the community to build upon. This solves the API fragmentation issue across the community by offering concrete function signatures, semantics and scopes of coverage, enabling writing backend-agnostic codes for better portability.
CuPy provides experimental support based on NumPy’s NEP-47,
which is in turn based on the v2021 standard. All of the functionalities can be accessed
through the cupy.array_api
namespace.
NumPy’s Array API Standard Compatibility is an excellent starting
point to understand better the differences between the APIs under the main namespace and the array_api
namespace.
Keep in mind, however, that the key difference between NumPy and CuPy is that we are a GPU-only library, therefore CuPy users should be aware
of potential device management issues.
Same as in regular CuPy codes, the GPU-to-use can be specified via the Device
objects, see
Device management. GPU-related semantics (e.g. streams, asynchronicity, etc) are also respected.
Finally, remember there are already differences between NumPy and CuPy,
although some of which are rectified in the standard.
- Array API Functions
abs()
acos()
acosh()
add()
all()
any()
arange()
argmax()
argmin()
argsort()
asarray()
asin()
asinh()
atan()
atan2()
atanh()
bitwise_and()
bitwise_invert()
bitwise_left_shift()
bitwise_or()
bitwise_right_shift()
bitwise_xor()
broadcast_arrays()
broadcast_to()
can_cast()
ceil()
concat()
cos()
cosh()
divide()
empty()
empty_like()
equal()
exp()
expand_dims()
expm1()
eye()
finfo()
flip()
floor()
floor_divide()
from_dlpack()
full()
full_like()
greater()
greater_equal()
iinfo()
isfinite()
isinf()
isnan()
less()
less_equal()
linspace()
log()
log10()
log1p()
log2()
logaddexp()
logical_and()
logical_not()
logical_or()
logical_xor()
matmul()
meshgrid()
multiply()
negative()
nonzero()
not_equal()
ones()
ones_like()
permute_dims()
positive()
pow()
remainder()
reshape()
result_type()
roll()
round()
sign()
sin()
sinh()
sort()
sqrt()
square()
squeeze()
stack()
subtract()
take()
tan()
tanh()
tril()
triu()
trunc()
unique_all()
unique_inverse()
unique_values()
where()
zeros()
zeros_like()
- Array API Compliant Object