Extract some coefficients at specified timesteps, then reshape to [batch_size, 1, 1, 1, 1, ...] for broadcasting purposes.
(a, t, x_shape)
| 138 | |
| 139 | @staticmethod |
| 140 | def _extract(a, t, x_shape): |
| 141 | """ |
| 142 | Extract some coefficients at specified timesteps, |
| 143 | then reshape to [batch_size, 1, 1, 1, 1, ...] for broadcasting purposes. |
| 144 | """ |
| 145 | bs, = t.shape |
| 146 | assert x_shape[0] == bs |
| 147 | out = torch.gather(a, 0, t) |
| 148 | assert out.shape == torch.Size([bs]) |
| 149 | return torch.reshape(out, [bs] + ((len(x_shape) - 1) * [1])) |
| 150 | |
| 151 | |
| 152 |
no outgoing calls
no test coverage detected