-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Labels
API changeChanges to existing functions or objects in the API.Changes to existing functions or objects in the API.RFCRequest for comments. Feature requests and proposed changes.Request for comments. Feature requests and proposed changes.
Milestone
Description
The following patterns are quite common [1]: x = np.r_(x[0], x, x[-1])
and x = np.r_[0, x]
. Neither of these can be directly replaced by xp.concat
because the latter requires that The arrays must have the same shape, except in the dimension specified by axis.
The most common case IME is that x
is a 1D array, which gets appended or prepended by a scalar.
An Array API replacement is something along the lines of
def npr(xp, *arys):
arys = [xp.asarray(a) for a in arys]
arys = [xpx.atleast_nd(a, ndim=1, xp=xp) for a in arys]
return xp.concat(arys)
which requires array_api_extra
and is generally a bit clunky. There was at least one case where a scipy change which was missing atleast_1d
broke jax.scipy
.
Allowing 0D arrays and python scalars in concat
would obviate the need for these sorts of helpers.
[1] At least in scipy,
$ git grep "np.r_" |wc -l
169
vnmabus
Metadata
Metadata
Assignees
Labels
API changeChanges to existing functions or objects in the API.Changes to existing functions or objects in the API.RFCRequest for comments. Feature requests and proposed changes.Request for comments. Feature requests and proposed changes.