Description
Follow-up to #144 (comment)
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:
from array_api_compat import torch
x = 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:
from array_api_compat import jax
# x is an array, i is a mask with the same shape
# x[i] = 0
x = 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
?