feat: add `isin` to the specification
This PR:
-
resolves https://github.com/data-apis/array-api/issues/854 by adding
isinto the specification. -
of the keyword arguments determined according to array comparison data, this PR chooses to support only the
invertkwarg. Theassume_uniquekwarg was not included for the following reasons:- not all array libraries support this kwarg (e.g., ndonnx and CuPy). CuPy lists the kwarg in its documentation but states that this kwarg is ignored.
- when doing a quick search through sklearn, I was only able to find one usage of
assume_uniquewhen usingisinand that was when searching lists of already known unique values. -
assume_uniqueis something of a performance optimization/implementation detail which we have generally attempted to avoid when standardizing APIs.
-
does not place restrictions on the shape of
x2. While some libraries may choose to flatten a multi-dimensionalx2, that is something of an implementation detail and not strictly necessary. For example, an implementation could defer to an "includes" kernel which performs nested loop iteration without needing to perform explicit reshapes/copies. -
adds support for scalar arguments for either
x1orx2. This follows recent general practice in standardized APIs, with the restriction that at least one ofx1orx2must be an array. -
specifies that value equality should be used, but not must be used. This follows other set APIs (e.g.,
unique*). As a consequence of value equality,NaNvalues can never test asTrueand there is no distinction between signed zeros. -
allows both
x1andx2to be of any data type. However, ifx1andx2have no promotable data type, behavior is left unspecified and thus implementation-defined.
Questions
Update: answers provided based on feedback below and discussions during workgroup meetings.
- Would we be okay with requiring that value equality must be used? Is there a scenario where we want to allow libraries some wiggle room, such as with
NaNand signed zero comparison?-
answer: use
must, notshould, due to predominant usage patterns.
-
answer: use
- Are we okay with leaving out
assume_unique?- answer: yes, this can be left out.
- Are we okay with not mandating reshape behavior if
x2is multi-dimensional?- answer: yes, no reshape behavior is required.