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
Bikeshed: might be worthwhile considering the current constellation of names among various array libraries and whether we want to introduce new vocabulary or build on existing vocabulary. E.g., NumPy already has fill, so fill_equal could be an option.
Additionally, the proposed operation is a functional equivalent to
x[x==old] =new
which is already supported by the standard vis-a-vis boolean indexing. In principle, one could have a dedicated kernel for this operation, thus avoiding the intermediate boolean array, but there is a question whether this API is actually needed given support for boolean indexing.
Additionally, the proposed operation is a functional equivalent to x[x==old] = new
Kinda but not really, since that doesn't work with JAX or other immutable implementations. The more generic equivalent is where(x == old, new, x), as in the issue description.
I think it makes sense to add replace to array-api-extra, probably backed by an xp.where-based generic implementation. It provides:
A cleaner API than the where equivalent,
If implemented directly in array libraries with an optimized implementation that avoids constructing the boolean intermediate array, better eager performance
Once (1) is in, we can use it immediately in scipy, since we vendor array_api_extra. There are probably a couple of dozen places where it can be used. Doing that will give a better feel for whether (2) is worth doing.
Activity
kgryte commentedon Sep 21, 2026
Bikeshed: might be worthwhile considering the current constellation of names among various array libraries and whether we want to introduce new vocabulary or build on existing vocabulary. E.g., NumPy already has
fill, sofill_equalcould be an option.Additionally, the proposed operation is a functional equivalent to
which is already supported by the standard vis-a-vis boolean indexing. In principle, one could have a dedicated kernel for this operation, thus avoiding the intermediate boolean array, but there is a question whether this API is actually needed given support for boolean indexing.
rgommers commentedon Oct 29, 2026
Kinda but not really, since that doesn't work with JAX or other immutable implementations. The more generic equivalent is
where(x == old, new, x), as in the issue description.I think it makes sense to add replace to array-api-extra, probably backed by an
xp.where-based generic implementation. It provides:whereequivalent,Once (1) is in, we can use it immediately in
scipy, since we vendorarray_api_extra. There are probably a couple of dozen places where it can be used. Doing that will give a better feel for whether (2) is worth doing.