Open
Description
Prior art
- NumPy - https://numpy.org/doc/stable/reference/generated/numpy.isin.html
- CuPy - https://docs.cupy.dev/en/latest/reference/generated/cupy.isin.html
- Dask - https://docs.dask.org/en/stable/generated/dask.array.isin.html
- JAX - https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.isin.html
- PyTorch - https://pytorch.org/docs/stable/generated/torch.isin.html
- ndonnx - https://ndonnx.readthedocs.io/en/latest/api/ndonnx.additional.html#ndonnx.additional.isin
- MLX -
isin
is not present yet
Motivation
This function is used in scikit-learn. They've implemented it in terms of the standard, and that implementation could find a home in array-api-extra: data-apis/array-api-extra#34. @asmeurer suggested there that we should also consider adding this to the standard.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Stage 2
Activity
asmeurer commentedon Nov 22, 2024
Another potential reason for adding it is that it uses a nontrivial implementation which depends on some heuristics based on the input size.
rgommers commentedon Nov 22, 2024
Thanks @lucascolley. I've added
ndonnx
(which has it) and MLX (which doesn't) to the issue description.This seems like a very reasonable proposal to me. Implementing
isin
in terms of other primitives in the standard is a little complex indeed.The return type should always be a boolean array. The NumPy docs say it can be a
bool
for a single input element, but that's actually a bug in the docs. I checked NumPy, JAX, and PyTorch and all return a 0-D array.rgommers commentedon Nov 28, 2024
The thing to discuss here is what keywords are desired I think. NumPy and Dask use:
The private scikit-learn implementation here is:
JAX:
PyTorch:
ndonnx:
The
assume_unique
andinvert
keywords seem easy to support and useful. So this should probably work:The type of
test_elements
is a bit TBD, could be a union between arrays and sequences perhaps?rgommers commentedon Nov 28, 2024
We discussed this in the community meeting today. A summary with a couple of points to follow up on:
isin
isin
are element-wise comparison like, it is probably a good idea to match what==
does.feat: add `isin` to the specification
isin
to the specification #959kgryte commentedon Jun 12, 2025
A PR adding
isin
to the specification is now up for review: #959