searchsorted(sorted_sequence: Tensor, input: Tensor | Scalar, out_int32: _bool = ..., right: _bool = ..., side: str | None = ..., sorter: Tensor | None = ...)Implementing kernel
C++ engine symbols that back this Python API.Find insertion points to maintain order in a sorted sequence.
For each v = input[i] returns the smallest j such that
v < sorted_sequence[j] (or <= when right=True). Equivalent
to per-element binary search.
Parameters
sorted_ sequenceTensor1-D sorted sequence of boundaries.
inputTensor | ScalarQuery values (arbitrary shape). A Python number is searched as a
0-d value on the sequence's device. The two operands are promoted
to their common dtype, as the reference does: a bool beside an
integer, or an integer beside a float, is searched at the wider
dtype.
rightbool= FalseUse
<= rather than < for the comparison.Returns
Tensorint64 tensor of insertion indices with the same shape as
input.
Notes
Sister function bucketize reverses the argument order
(values first).
Examples
>>> import lucid
>>> seq = lucid.tensor([1.0, 3.0, 5.0])
>>> lucid.searchsorted(seq, lucid.tensor([0.5, 2.0, 4.0, 6.0]))
Tensor([0, 1, 2, 3])