You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RFC: add isin for elementwise set inclusion test #854
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.
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.
We discussed this in the community meeting today. A summary with a couple of points to follow up on:
In general, folks were 👍🏼 on adding isin
For the second argument, accepting arrays and scalars but not sequences seemed preferred.
Some discussion about promotion behavior, this needs to be specified. Since the semantics of isin are element-wise comparison like, it is probably a good idea to match what == does.
For the second argument: limit to 1-D, or accept any shape and then reshape to 1-D? NumPy does the latter.
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
isinin 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
boolfor 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_uniqueandinvertkeywords seem easy to support and useful. So this should probably work:The type of
test_elementsis 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:
isinisinare element-wise comparison like, it is probably a good idea to match what==does.feat: add `isin` to the specification
kgryte commentedon Jun 12, 2025
A PR adding
isinto the specification is now up for review: #959feat: add `isin` to the specification