Closed
Description
The "index conditions" of searchsorted
, which are documented in the description of the side
argument, are:
In "Let x
be an array of rank N
":
- I think
x
is supposed to bex2
, and - it looks like
N
is not supposed to be theN
defined later as the "number of elements inx1
".
Also, it looks like these conditions don't cover the edge cases where either
side='left'
andv
exceeds all elements ofx1
orside='right'
andv
is less than all elements ofx1
:
import array_api_strict as xp
x1 = xp.asarray([1, 2, 3])
# `side='left'` and `v` exceeds all elements of `x1` or
x2 = xp.asarray(4)
i = xp.searchsorted(x1, x2, side='left')
x1[i] # IndexError: index 3 is out of bounds for axis 0 with size 3
# `side='right'` and `v` is less than all elements of `x1`:
x2 = xp.asarray(0)
i = xp.searchsorted(x1, x2, side='right')
x1[i-1] < x1[i]
# Array(False, dtype=array_api_strict.bool)
I think complete index conditions, which describe the out
mathematically, would be helpful! Then, perhaps the details of the side
argument could be restricted to what happens when v
"lands exactly on an edge", which I interpret to mean "is equal to an element of x1
": If side == 'left'
, then v = x1[i]
; if side == 'right'
, then v = x1[i-1]
.