Skip to content

Conversation

@ev-br
Copy link
Member

@ev-br ev-br commented Jan 8, 2026

Array API 2025.12 allows python scalars for the x2 argument of searchsorted. CuPy only supports python scalars for x2 from CuPy 14.0. Until this is the minimum supported version, array-api-compat needs a workaround.

Array API spec PR: data-apis/array-api#982
A matching test: data-apis/array-api-tests#394
The matching CuPy enhancement: cupy/cupy#9512

Array API 2025.12 allows python scalars for the x2 argument of
`searchsorted`. CuPy only supports python scalars for x2 from
CuPy 14.0.
Until this is the minimum supported version, array-api-compat
needs a workaround.
@ev-br ev-br added this to the 1.14 milestone Jan 8, 2026
Copilot AI review requested due to automatic review settings January 8, 2026 20:20
@ev-br ev-br marked this pull request as draft January 8, 2026 20:20
@ev-br
Copy link
Member Author

ev-br commented Jan 8, 2026

Marking as a draft until 2025.12 is out.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a workaround for CuPy's searchsorted function to support Python scalars for the x2 argument, which is now allowed by Array API 2025.12 but only supported in CuPy 14.0+. Until CuPy 14.0 becomes the minimum supported version, this compatibility wrapper converts scalar inputs to arrays before passing them to the underlying CuPy function.

Key Changes

  • Added new searchsorted function in array_api_compat/cupy/_aliases.py that wraps cp.searchsorted with scalar-to-array conversion
  • Added Literal import from typing for type annotations
  • Updated __all__ exports to include the new searchsorted function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


def searchsorted(
x1: Array,
x2: Array | int | float,
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation for x2 is missing complex which is checked in the isinstance check on line 154. The type annotation should be Array | int | float | complex to match the runtime validation logic.

Suggested change
x2: Array | int | float,
x2: Array | int | float | complex,

Copilot uses AI. Check for mistakes.
raise NotImplementedError(
'Only python scalars or ndarrays are supported for x2')
x2 = cp.asarray(x2)
return cp.searchsorted(x1, x2, side, sorter)
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arguments side and sorter should be passed as keyword arguments to cp.searchsorted, not positional arguments. The call should be cp.searchsorted(x1, x2, side=side, sorter=sorter) to match the API signature.

Suggested change
return cp.searchsorted(x1, x2, side, sorter)
return cp.searchsorted(x1, x2, side=side, sorter=sorter)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant