You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes to make existing code compatible with backends that are not fully standard compliant, we would need to create copies where the original code would not.
For example, as a workaround for gh-144 (PyTorch doesn't support negative step), we could (sometimes) make the replacement:
fromarray_api_compatimporttorchx=torch.arange(10)
# x[::-1] xp.flip(x) # ValueError: step must be greater than zero
As a workaround for JAX not supporting mutation, we could sometimes make replacements like:
fromarray_api_compatimportjax# x is an array, i is a mask with the same shape# x[i] = 0x=jax.where(i, 0, x)
However, making substitutions like this could decrease performance for array types that do support the desired operation (returning a view or mutating the original, in these cases).
Functions that perform the desired operation when possible and the substitute otherwise (e.g. scipy/scipy#20085 (comment)) have been proposed. Do such things belong in array_api_compat?