diff --git a/array_api_tests/_array_module.py b/array_api_tests/_array_module.py index 1c52a983..96d0d452 100644 --- a/array_api_tests/_array_module.py +++ b/array_api_tests/_array_module.py @@ -35,6 +35,8 @@ def __repr__(self): _funcs += ["take", "isdtype", "conj", "imag", "real"] # TODO: bump spec and update array-api-tests to new spec layout _top_level_attrs = _dtypes + _constants + _funcs + stubs.EXTENSIONS + ["fft"] +_top_level_attrs += ['isin'] # FIXME: until the spec is not updated + for attr in _top_level_attrs: try: globals()[attr] = getattr(xp, attr) diff --git a/array_api_tests/test_set_functions.py b/array_api_tests/test_set_functions.py index 8a6f7a9d..b349c500 100644 --- a/array_api_tests/test_set_functions.py +++ b/array_api_tests/test_set_functions.py @@ -5,6 +5,7 @@ import pytest from hypothesis import assume, given +from hypothesis import strategies as st from . import _array_module as xp from . import dtype_helpers as dh @@ -256,3 +257,42 @@ def test_unique_values(x): except Exception as exc: ph.add_note(exc, repro_snippet) raise + + +@given( + *hh.two_mutual_arrays(two_shapes=st.tuples(hh.shapes(), hh.shapes())), + hh.kwargs(invert=st.booleans()) +) +def test_isin(x1, x2, kw): + print("\nx1 = ", type(x1)) + print(x1.shape, x2.shape, x1.dtype, x2.dtype, kw) + + repro_snippet = ph.format_snippet(f"xp.isin({x1!r}, {x2!r}, **kw) with {kw = }") + try: + out = xp.isin(x1, x2, **kw) + + assert out.dtype == xp.bool + assert out.shape == x1.shape + # TODO value tests + except Exception as exc: + ph.add_note(exc, repro_snippet) + raise + + +@given( + x1x2=hh.array_and_py_scalar(dh.all_dtypes), + kw=hh.kwargs(invert=st.booleans()) +) +def test_isin_scalars(x1x2, kw): + x1, x2 = x1x2 + + repro_snippet = ph.format_snippet(f"xp.isin({x1!r}, {x2!r}, **kw) with {kw = }") + try: + out = xp.isin(x1, x2, **kw) + + assert out.dtype == xp.bool + assert out.shape == () if isinstance(x1, bool | int | float | complex) else x1.shape + # TODO value tests + except Exception as exc: + ph.add_note(exc, repro_snippet) + raise