Skip to content

[BUG]: searchsorted has incorrect boundary conditions #861

@mdhaber

Description

@mdhaber

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].

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy