Skip to content

Commit ffaf7fa

Browse files
authored
feat: add isin to the specification
PR-URL: #959 Closes: #854 Reviewed-by: Ralf Gommers <ralf.gommers@gmail.com> Reviewed-by: Lucas Colley Reviewed-by: Evgeni Burovski
1 parent 02ab761 commit ffaf7fa

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

spec/draft/API_specification/set_functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Objects in API
1818
:toctree: generated
1919
:template: method.rst
2020

21+
isin
2122
unique_all
2223
unique_counts
2324
unique_inverse

src/array_api_stubs/_draft/set_functions.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
1-
__all__ = ["unique_all", "unique_counts", "unique_inverse", "unique_values"]
1+
__all__ = ["isin", "unique_all", "unique_counts", "unique_inverse", "unique_values"]
22

33

4-
from ._types import Tuple, array
4+
from ._types import Tuple, Union, array
5+
6+
7+
def isin(
8+
x1: Union[array, int],
9+
x2: Union[array, int],
10+
/,
11+
*,
12+
invert: bool = False,
13+
) -> array:
14+
"""
15+
Tests for each element in ``x1`` whether the element is in ``x2``.
16+
17+
Parameters
18+
----------
19+
x1: Union[array, int]
20+
first input array. **Should** have an integer data type.
21+
x2: Union[array, int]
22+
second input array. **Should** have an integer data type.
23+
invert: bool
24+
boolean indicating whether to invert the test criterion. If ``True``, the function **must** test whether each element in ``x1`` is *not* in ``x2``. If ``False``, the function **must** test whether each element in ``x1`` is in ``x2``. Default: ``False``.
25+
26+
Returns
27+
-------
28+
out: array
29+
an array containing element-wise test results. The returned array **must** have a boolean data type. If ``x1`` is an array, the returned array **must** have the same shape as ``x1``; otherwise, the returned array **must** be a zero-dimensional array containing the result.
30+
31+
Notes
32+
-----
33+
34+
- At least one of ``x1`` or ``x2`` **must** be an array.
35+
- If an element in ``x1`` is in ``x2``, the corresponding element in the output array **must** be ``True``; otherwise, the corresponding element in the output array **must** be ``False``.
36+
- Testing whether an element in ``x1`` corresponds to an element in ``x2`` **must** be determined based on value equality (see :func:`~array_api.equal`).
37+
- Comparison of arrays without a corresponding promotable data type (see :ref:`type-promotion`) is unspecified and thus implementation-defined.
38+
"""
539

640

741
def unique_all(x: array, /) -> Tuple[array, array, array, array]:

0 commit comments

Comments
 (0)