MCPcopy Create free account
hub / github.com/CompVis/diff2flow / extract_and_interpolate_into_tensor

Function extract_and_interpolate_into_tensor

diff2flow/utils/diffusion_utils.py:61–71  ·  view source on GitHub ↗
(a, t, x_shape)

Source from the content-addressed store, hash-verified

59 return out.reshape(b, *((1,) * (len(x_shape) - 1)))
60
61def extract_and_interpolate_into_tensor(a, t, x_shape):
62 b, *_ = t.shape
63 # t can be float here, linearly interpolate between left and right index
64 t = t.clamp(0, a.shape[-1] - 1)
65 left_idx = t.long()
66 right_idx = (left_idx + 1).clamp(max=a.shape[-1] - 1)
67 left_val = a.gather(-1, left_idx)
68 right_val = a.gather(-1, right_idx)
69 t_ = t - left_idx.float()
70 out = left_val * (1 - t_) + right_val * t_
71 return out.reshape(b, *((1,) * (len(x_shape) - 1)))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected