Skip to content
Draft
Changes from all 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
23 changes: 22 additions & 1 deletion array_api_compat/cupy/_aliases.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from builtins import bool as py_bool
from typing import Literal

import cupy as cp

Expand Down Expand Up @@ -139,6 +140,24 @@ def take_along_axis(x: Array, indices: Array, /, *, axis: int = -1) -> Array:
return cp.take_along_axis(x, indices, axis=axis)


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.
/,
*,
side: Literal['left', 'right'] = 'left',
sorter: Array | None = None
) -> Array:
# Match https://github.com/cupy/cupy/pull/9512/ until cupy v14 is the minimum
# supported version
if not isinstance(x2, cp.ndarray):
if not isinstance(x2, int | float | complex):
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.


# These functions are completely new here. If the library already has them
# (i.e., numpy 2.0), use the library version instead of our wrapper.
if hasattr(cp, 'vecdot'):
Expand All @@ -161,7 +180,9 @@ def take_along_axis(x: Array, indices: Array, /, *, axis: int = -1) -> Array:
'atan2', 'atanh', 'bitwise_left_shift',
'bitwise_invert', 'bitwise_right_shift',
'bool', 'concat', 'count_nonzero', 'pow', 'sign',
'ceil', 'floor', 'trunc', 'take_along_axis']
'ceil', 'floor', 'trunc', 'take_along_axis',
'searchsorted',
]


def __dir__() -> list[str]:
Expand Down
Loading