Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: searchsorted: incomplete index conditions? #861

Open
mdhaber opened this issue Nov 25, 2024 · 0 comments
Open

DOC: searchsorted: incomplete index conditions? #861

mdhaber opened this issue Nov 25, 2024 · 0 comments
Labels
bug Something isn't working.
Milestone

Comments

@mdhaber
Copy link
Contributor

mdhaber commented Nov 25, 2024

The "index conditions" of searchsorted, which are documented in the description of the side argument, are:

image

In "Let x be an array of rank N":

  • I think x is supposed to be x2, and
  • it looks like N is not supposed to be the N defined later as the "number of elements in x1".

Also, it looks like these conditions don't cover the edge cases where either

  • side='left' and v exceeds all elements of x1 or
  • side='right' and v is less than all elements of x1:
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].

@kgryte kgryte added the bug Something isn't working. label Nov 25, 2024
@kgryte kgryte added this to the v2024 milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

2 participants