|
1 |
| -__all__ = ["unique_all", "unique_counts", "unique_inverse", "unique_values"] |
| 1 | +__all__ = ["isin", "unique_all", "unique_counts", "unique_inverse", "unique_values"] |
2 | 2 |
|
3 | 3 |
|
4 | 4 | from ._types import Tuple, array
|
5 | 5 |
|
6 | 6 |
|
| 7 | +def isin( |
| 8 | + x1: Union[array, int, float, complex, bool], |
| 9 | + x2: Union[array, int, float, complex, bool], |
| 10 | + /, |
| 11 | + *, |
| 12 | + invert: bool = False, |
| 13 | +) -> array: |
| 14 | + """ |
| 15 | + Tests whether each element in ``x1`` is in ``x2``. |
| 16 | +
|
| 17 | + Parameters |
| 18 | + ---------- |
| 19 | + x1: Union[array, int, float, complex, bool] |
| 20 | + first input array. **May** have any data type. |
| 21 | + x2: Union[array, int, float, complex, bool] |
| 22 | + second input array. **May** have any 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 the same shape as ``x1`` and **must** have a boolean data type. |
| 30 | +
|
| 31 | + Notes |
| 32 | + ----- |
| 33 | +
|
| 34 | + - At least one of ``x1`` or ``x2`` **must** be an array. |
| 35 | +
|
| 36 | + - If an element in ``x1`` is in ``x1``, the corresponding element in the output array **must** be ``True``; otherwise, the corresponding element in the output array **must** be ``False``. |
| 37 | +
|
| 38 | + - Testing whether an element in ``x1`` corresponds to an element in ``x2`` **should** be determined based on value equality (see :func:`~array_api.equal`). For input arrays having floating-point data types, value-based equality implies the following behavior. |
| 39 | +
|
| 40 | + - As ``nan`` values compare as ``False``, if an element in ``x1`` is ``nan`` and ``invert`` is ``False``, the corresponding element in the returned array **should** be ``False``. Otherwise, if an element in ``x1`` is ``nan`` and ``invert`` is ``True``, the corresponding element in the returned array **should** be ``True``. |
| 41 | + - As complex floating-point values having at least one ``nan`` component compare as ``False``, if an element in ``x1`` is a complex floating-point value having one or more ``nan`` components and ``invert`` is ``False``, the corresponding element in the returned array **should** be ``False``. Otherwise, if an element in ``x1`` is a complex floating-point value having one or more ``nan`` components and ``invert`` is ``True``, the corresponding element in the returned array **should** be ``True``. |
| 42 | + - As ``-0`` and ``+0`` compare as ``True``, if an element in ``x1`` is ``±0`` and ``x2`` contains at least one element which is ``±0`` |
| 43 | +
|
| 44 | + - if ``invert`` is ``False``, the corresponding element in the returned array **should** be ``True``. |
| 45 | + - if ``invert`` is ``True``, the corresponding element in the returned array **should** be ``False``. |
| 46 | +
|
| 47 | + - Comparison of arrays without a corresponding promotable data type (see :ref:`type-promotion`) is unspecified and thus implementation-defined. |
| 48 | + """ |
| 49 | + |
| 50 | + |
7 | 51 | def unique_all(x: array, /) -> Tuple[array, array, array, array]:
|
8 | 52 | """
|
9 | 53 | Returns the unique elements of an input array ``x``, the first occurring indices for each unique element in ``x``, the indices from the set of unique elements that reconstruct ``x``, and the corresponding counts for each unique element in ``x``.
|
|
0 commit comments