MCPcopy Create free account
hub / github.com/NVlabs/InstantSplat / searchsorted

Function searchsorted

utils/stepfun.py:6–25  ·  view source on GitHub ↗

Find indices where v should be inserted into a to maintain order. Args: a: tensor, the sorted reference points that we are scanning to see where v should lie. v: tensor, the query points that we are pretending to insert into a. Does not need to be sorted. All but the last dime

(a, v)

Source from the content-addressed store, hash-verified

4
5
6def searchsorted(a, v):
7 """Find indices where v should be inserted into a to maintain order.
8
9 Args:
10 a: tensor, the sorted reference points that we are scanning to see where v
11 should lie.
12 v: tensor, the query points that we are pretending to insert into a. Does
13 not need to be sorted. All but the last dimensions should match or expand
14 to those of a, the last dimension can differ.
15
16 Returns:
17 (idx_lo, idx_hi), where a[idx_lo] <= v < a[idx_hi], unless v is out of the
18 range [a[0], a[-1]] in which case idx_lo and idx_hi are both the first or
19 last index of a.
20 """
21 i = torch.arange(a.shape[-1], device=a.device)
22 v_ge_a = v[..., None, :] >= a[..., :, None]
23 idx_lo = torch.max(torch.where(v_ge_a, i[..., :, None], i[..., :1, None]), -2).values
24 idx_hi = torch.min(torch.where(~v_ge_a, i[..., :, None], i[..., -1:, None]), -2).values
25 return idx_lo, idx_hi
26
27
28def query(tq, t, y, outside_value=0):

Callers 2

queryFunction · 0.85
inner_outerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected