Open
Description
The specification of diff
requires append
and prepend
to be arrays with the same shape as the first argument except along axis
.
array-api-strict
currently does not:
import array_api_strict as xp
xp.diff(xp.ones((2, 3)), append=xp.asarray(10), axis=0)
# Array([[0., 0., 0.],
# [9., 9., 9.]], dtype=array_api_strict.float64)
xp.diff(xp.ones((2, 3)), append=xp.asarray(10), axis=1)
# Array([[0., 0., 9.],
# [0., 0., 9.]], dtype=array_api_strict.float64)
Like NumPy, CuPy, and JAX, it expands the value as necessary (and follows the same promotion rules as other functions. I see that following the usual promotion rules was already tabled, so I won't bring that up again right now.)
This suggest that the operation can be well-defined, and I think it can be useful (e.g. prepend 0
and append shape[axis]
). It would be even more useful to accept Python scalars, following the example of clip
(which also requires array min
/max
to have the same type as x
, but allows Python scalars). This would avoid requiring the user to do something like:
append = xp.full(x.shape[:axis] + (1,) + x.shape[axis:], append, dtype=xp.result_type(x, prepend, append))
Metadata
Metadata
Assignees
Labels
No labels