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
This RFC proposes adding support to the array API specification for finding the indices where elements should be inserted in order to maintain order.
Overview
Based on array comparison data, the API is available across all considered libraries.
Furthermore, all considered libraries support the side keyword argument, and all considered libraries, except for TensorFlow, support the sorter keyword argument.
JAX supports an additional kwarg, method, which is used based on device/size performance optimization considerations. PyTorch and TensorFlow support specifying the output data type, but differ in naming conventions.
All array libraries support one-dimensional arrays. PyTorch and TensorFlow generalize to any n-dimensional ndarray (stacking).
x1: one-dimensional array. If sorter is None, x1 must be sorted in ascending order.
x2: one-dimensional array.
side: if "left", the returned index i satisfies x1[i-1] < x2[j] <= x1[i]. Otherwise, if "right", the returned index i satisfies x1[i-1] <= x2[j] < x1[i]. If no suitable index, then i is either 0 or N, respectively, were N is the length of x1.
sorter: array of integer indices that sort x1 in ascending order (e.g., as might be produced via argsort).
Questions
Should the API be extended to support stacking as in PyTorch/TensorFlow?
Should the API support a scalar value for x2? NumPy, PyTorch, JAX, Dask support scalars. CuPy and TensorFlow do not.
The text was updated successfully, but these errors were encountered:
Thanks @kgryte, this LGTM. I checked usage of searchsorted across scikit-learn, SciPy, pandas and Matplotlib, and it's used quite a bit in all libraries. The side keyword is the more heavily used one; there's only two instances in total of the sorter keyword (but it still seems okay to include).
Should the API be extended to support stacking as in PyTorch?
Not for now at least, that's too much of a burden for implementers and there doesn't seem to be a real need for this.
This RFC proposes adding support to the array API specification for finding the indices where elements should be inserted in order to maintain order.
Overview
Based on array comparison data, the API is available across all considered libraries.
Furthermore, all considered libraries support the
side
keyword argument, and all considered libraries, except for TensorFlow, support thesorter
keyword argument.JAX supports an additional kwarg,
method
, which is used based on device/size performance optimization considerations. PyTorch and TensorFlow support specifying the output data type, but differ in naming conventions.All array libraries support one-dimensional arrays. PyTorch and TensorFlow generalize to any n-dimensional ndarray (stacking).
Prior Art
Proposal
sorter
isNone
,x1
must be sorted in ascending order.i
satisfiesx1[i-1] < x2[j] <= x1[i]
. Otherwise, if "right", the returned indexi
satisfiesx1[i-1] <= x2[j] < x1[i]
. If no suitable index, theni
is either0
orN
, respectively, wereN
is the length ofx1
.x1
in ascending order (e.g., as might be produced viaargsort
).Questions
x2
? NumPy, PyTorch, JAX, Dask support scalars. CuPy and TensorFlow do not.The text was updated successfully, but these errors were encountered: