fn
searchsorted
→Tensorsearchsorted(sorted_seq: Tensor, values: Tensor, right: bool = ...)Find insertion points to maintain order in a sorted sequence.
For each v = values[i] returns the smallest j such that
v < sorted_seq[j] (or <= when right=True). Equivalent
to per-element binary search.
Parameters
sorted_seqTensor1-D sorted sequence of boundaries.
valuesTensorQuery values (arbitrary shape).
rightbool= FalseUse
<= rather than < for the comparison.Returns
Tensorint64 tensor of insertion indices with the same shape as
values.
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])