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

Implement NumPy search routines #2080

Closed
9 tasks done
shoyer opened this issue Jan 26, 2020 · 3 comments
Closed
9 tasks done

Implement NumPy search routines #2080

shoyer opened this issue Jan 26, 2020 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@shoyer
Copy link
Collaborator

shoyer commented Jan 26, 2020

xref https://docs.scipy.org/doc/numpy/reference/routines.sort.html

Extracted from #70:

  • np.argmax
  • np.argmin
  • np.argwhere
  • np.compress
  • np.nonzero
  • np.flatnonzero
  • np.where
  • np.searchsorted
  • np.extract

(see #2077 for nanargmax/nanargmin)

Notes:

  • argwhere/flatnonzero/extractcould should just be minimal wrappers around nonzero
  • searchsorted is harder: it need would need low-level routines/wrappers for efficient binary search, which to my knowledge do not currently existing in XLA
@djdongjin
Copy link
Contributor

@shoyer I'd like to work on the last searchsorted. Where and how should I implement the efficient binary search you mentioned? Should I implement it in tensorflow.xla first and wrap it in Jax when it is merged into tensorflow?

And a more general question, if we want to add some functions using ops that don't exist in XLA (like here), how should we do? Can we implement the ops directly in python, or we need to implement it in XLA first?

@terhorst
Copy link
Contributor

terhorst commented Apr 19, 2020

If your data don't have ties, then the following should work:

def hacky_searchsorted(a, v):
    i = np.argsort(np.concatenate([a, v]))
    ranks = i.argsort()
    A = len(a)
    V = len(v)
    return (np.arange(A + V) < A)[i].cumsum()[ranks[A:]]

@hawkinsp
Copy link
Collaborator

hawkinsp commented May 7, 2020

#2938 implemented searchsorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants