MCPcopy Index your code
hub / github.com/MotrixLab/MotionDiffuse / _extract_into_tensor

Function _extract_into_tensor

text2motion/models/gaussian_diffusion.py:1131–1144  ·  view source on GitHub ↗

Extract values from a 1-D numpy array for a batch of indices. :param arr: the 1-D numpy array. :param timesteps: a tensor of indices into the array to extract. :param broadcast_shape: a larger shape of K dimensions with the batch dimension equal to the l

(arr, timesteps, broadcast_shape)

Source from the content-addressed store, hash-verified

1129
1130
1131def _extract_into_tensor(arr, timesteps, broadcast_shape):
1132 """
1133 Extract values from a 1-D numpy array for a batch of indices.
1134
1135 :param arr: the 1-D numpy array.
1136 :param timesteps: a tensor of indices into the array to extract.
1137 :param broadcast_shape: a larger shape of K dimensions with the batch
1138 dimension equal to the length of timesteps.
1139 :return: a tensor of shape [batch_size, 1, ...] where the shape has K dims.
1140 """
1141 res = th.from_numpy(arr).to(device=timesteps.device)[timesteps].float()
1142 while len(res.shape) < len(broadcast_shape):
1143 res = res[..., None]
1144 return res.expand(broadcast_shape)
1145

Callers 10

q_mean_varianceMethod · 0.85
q_sampleMethod · 0.85
p_mean_varianceMethod · 0.85
condition_scoreMethod · 0.85
ddim_sampleMethod · 0.85
ddim_reverse_sampleMethod · 0.85

Calls 1

toMethod · 0.80

Tested by

no test coverage detected