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
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 arraymin/max to have the same type as x, but allows Python scalars). This would avoid requiring the user to do something like:
The text was updated successfully, but these errors were encountered:
mdhaber
changed the title
diff to allow Python scalar or 0d arrayappend and prepend?diff to allow Python scalar or 0d array append and prepend?
Apr 18, 2025
As noted in #791, scalar kwargs support is not supported in PyTorch, which was a primary motivation for restricting portable behavior to prepend and append being arrays.
Thanks for those references; good to see it was considered.
I understand that when a library doesn't support a feature that the rest do, the standard needs to strike a balance between importance of the feature and difficulty of adding support. Features like uint16-uint64 support, a size attribute, negative step sizes for slices, etc. are very challenging for for PyTorch to add and impossible for array-api-compat to compensate for within its current scope, but the standard includes them because they are very important. (Thank goodness!)
This is a lot less important than those features, but it is also much easier to add. data-apis/array-api-compat#271 and data-apis/array-api-compat#274 have several other examples of PyTorch lacking support for scalars (and these are just the ones I've run across), but the standard decided to include them. I'd suggest that this could be similar.
The specification of
diff
requiresappend
andprepend
to be arrays with the same shape as the first argument except alongaxis
.array-api-strict
currently does not: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 appendshape[axis]
). It would be even more useful to accept Python scalars, following the example ofclip
(which also requires arraymin
/max
to have the same type asx
, but allows Python scalars). This would avoid requiring the user to do something like:The text was updated successfully, but these errors were encountered: