Appends dimensions to the end of a tensor until it has target_dims dimensions.
(x, target_dims)
| 321 | |
| 322 | |
| 323 | def append_dims(x, target_dims): |
| 324 | """Appends dimensions to the end of a tensor until it has target_dims dimensions.""" |
| 325 | dims_to_append = target_dims - x.ndim |
| 326 | if dims_to_append < 0: |
| 327 | raise ValueError(f"input has {x.ndim} dims but target_dims is {target_dims}, which is less") |
| 328 | return x[(...,) + (None,) * dims_to_append] |
| 329 | |
| 330 | |
| 331 | def append_zero(x): |
no outgoing calls
no test coverage detected