isin(elements: Tensor | TensorLike, test_elements: Tensor | TensorLike, invert: _bool = ...)Per-element set-membership test.
For each entry of elements, checks whether the value appears
anywhere in test_elements. Implemented as a broadcasted
equality compare followed by an OR reduction.
Parameters
Returns
TensorBoolean tensor of the same shape as elements.
Notes
Mathematical definition (with and ):
Cost is . For large test_elements
a sort-based implementation would be cheaper, but this composite
form keeps the operation differentiable-by-default (the gradient
is zero everywhere — the output dtype is boolean — but the structure
is preserved).
Examples
>>> import lucid
>>> e = lucid.tensor([1, 2, 3, 4])
>>> t = lucid.tensor([2, 4])
>>> lucid.isin(e, t)
Tensor([False, True, False, True])