Skip to content

fix: address incorrect boundary conditions in searchsorted #898

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

Merged
merged 6 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/array_api_stubs/_2023_12/searching_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,11 @@ def searchsorted(
side: Literal['left', 'right']
argument controlling which index is returned if a value lands exactly on an edge.

Let ``x`` be an array of rank ``N`` where ``v`` is an individual element given by ``v = x2[n,m,...,j]``.
Let ``x2`` be an array of rank ``N`` where ``v`` is an individual element given by ``v = x2[n,m,...,j]``.

If ``side == 'left'``, then

- each returned index ``i`` must satisfy the index condition ``x1[i-1] < v <= x1[i]``.
- if no index satisfies the index condition, then the returned index for that element must be ``0``.

Otherwise, if ``side == 'right'``, then

- each returned index ``i`` must satisfy the index condition ``x1[i-1] <= v < x1[i]``.
- if no index satisfies the index condition, then the returned index for that element must be ``N``, where ``N`` is the number of elements in ``x1``.
- If ``v`` is less than all elements in ``x1``, then the returned index for that element must be ``0``.
- If ``v`` is greater than all elements in ``x1``, then the returned index for that element must be ``M``, where ``M`` is the number of elements in ``x1``.
- Otherwise, if ``side == 'left'``, then each returned index ``i`` must satisfy the index condition ``x1[i-1] < v <= x1[i]``. If ``side == 'right'``, then each returned index ``i`` must satisfy the index condition ``x1[i-1] <= v < x1[i]``.

Default: ``'left'``.
sorter: Optional[array]
Expand Down
14 changes: 4 additions & 10 deletions src/array_api_stubs/_draft/searching_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,11 @@ def searchsorted(
side: Literal['left', 'right']
argument controlling which index is returned if a value lands exactly on an edge.

Let ``x`` be an array of rank ``N`` where ``v`` is an individual element given by ``v = x2[n,m,...,j]``.
Let ``x2`` be an array of rank ``N`` where ``v`` is an individual element given by ``v = x2[n,m,...,j]``.

If ``side == 'left'``, then

- each returned index ``i`` must satisfy the index condition ``x1[i-1] < v <= x1[i]``.
- if no index satisfies the index condition, then the returned index for that element must be ``0``.

Otherwise, if ``side == 'right'``, then

- each returned index ``i`` must satisfy the index condition ``x1[i-1] <= v < x1[i]``.
- if no index satisfies the index condition, then the returned index for that element must be ``N``, where ``N`` is the number of elements in ``x1``.
- If ``v`` is less than all elements in ``x1``, then the returned index for that element must be ``0``.
- If ``v`` is greater than all elements in ``x1``, then the returned index for that element must be ``M``, where ``M`` is the number of elements in ``x1``.
- Otherwise, if ``side == 'left'``, then each returned index ``i`` must satisfy the index condition ``x1[i-1] < v <= x1[i]``. If ``side == 'right'``, then each returned index ``i`` must satisfy the index condition ``x1[i-1] <= v < x1[i]``.

Default: ``'left'``.
sorter: Optional[array]
Expand Down