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

Function integrate_weights

utils/stepfun.py:108–128  ·  view source on GitHub ↗

Compute the cumulative sum of w, assuming all weight vectors sum to 1. The output's size on the last dimension is one greater than that of the input, because we're computing the integral corresponding to the endpoints of a step function, not the integral of the interior/bin values. Args:

(w)

Source from the content-addressed store, hash-verified

106
107
108def integrate_weights(w):
109 """Compute the cumulative sum of w, assuming all weight vectors sum to 1.
110
111 The output's size on the last dimension is one greater than that of the input,
112 because we're computing the integral corresponding to the endpoints of a step
113 function, not the integral of the interior/bin values.
114
115 Args:
116 w: Tensor, which will be integrated along the last axis. This is assumed to
117 sum to 1 along the last axis, and this function will (silently) break if
118 that is not the case.
119
120 Returns:
121 cw0: Tensor, the integral of w, where cw0[..., 0] = 0 and cw0[..., -1] = 1
122 """
123 cw = torch.cumsum(w[..., :-1], dim=-1).clamp_max(1)
124 shape = cw.shape[:-1] + (1,)
125 # Ensure that the CDF starts with exactly 0 and ends with exactly 1.
126 cw0 = torch.cat([torch.zeros(shape, device=cw.device), cw,
127 torch.ones(shape, device=cw.device)], dim=-1)
128 return cw0
129
130
131def integrate_weights_np(w):

Callers 2

invert_cdfFunction · 0.85
weighted_percentileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected