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)
| 1161 | |
| 1162 | |
| 1163 | def _extract_into_tensor(arr, timesteps, broadcast_shape): |
| 1164 | """ |
| 1165 | Extract values from a 1-D numpy array for a batch of indices. |
| 1166 | |
| 1167 | :param arr: the 1-D numpy array. |
| 1168 | :param timesteps: a tensor of indices into the array to extract. |
| 1169 | :param broadcast_shape: a larger shape of K dimensions with the batch |
| 1170 | dimension equal to the length of timesteps. |
| 1171 | :return: a tensor of shape [batch_size, 1, ...] where the shape has K dims. |
| 1172 | """ |
| 1173 | res = th.from_numpy(arr).to(device=timesteps.device)[timesteps].float() |
| 1174 | while len(res.shape) < len(broadcast_shape): |
| 1175 | res = res[..., None] |
| 1176 | return res.expand(broadcast_shape) |
| 1177 | |
| 1178 | |
| 1179 | def space_timesteps(num_timesteps, section_counts): |
no outgoing calls
no test coverage detected