fn
isin
→Tensorisin(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
elementsTensor | TensorLikeValues to test. Reshaped to 1-D internally; the output is
reshaped back to
elements.shape.test_elementsTensor | TensorLikeThe set of values to test against. Flattened internally.
invertboolIf
True, return the negation of the membership test.
Defaults to False.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])