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 le
(arr, timesteps, broadcast_shape)
| 859 | |
| 860 | |
| 861 | def _extract_into_tensor(arr, timesteps, broadcast_shape): |
| 862 | """ |
| 863 | Extract values from a 1-D numpy array for a batch of indices. |
| 864 | :param arr: the 1-D numpy array. |
| 865 | :param timesteps: a tensor of indices into the array to extract. |
| 866 | :param broadcast_shape: a larger shape of K dimensions with the batch |
| 867 | dimension equal to the length of timesteps. |
| 868 | :return: a tensor of shape [batch_size, 1, ...] where the shape has K dims. |
| 869 | """ |
| 870 | res = th.from_numpy(arr).to(device=timesteps.device)[timesteps].float() |
| 871 | while len(res.shape) < len(broadcast_shape): |
| 872 | res = res[..., None] |
| 873 | return res + th.zeros(broadcast_shape, device=timesteps.device) |
no outgoing calls
no test coverage detected