MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / append_dims

Function append_dims

k_diffusion/utils.py:44–49  ·  view source on GitHub ↗

Appends dimensions to the end of a tensor until it has target_dims dimensions.

(x, target_dims)

Source from the content-addressed store, hash-verified

42
43
44def append_dims(x, target_dims):
45 """Appends dimensions to the end of a tensor until it has target_dims dimensions."""
46 dims_to_append = target_dims - x.ndim
47 if dims_to_append < 0:
48 raise ValueError(f'input has {x.ndim} dims but target_dims is {target_dims}, which is less')
49 return x[(...,) + (None,) * dims_to_append]
50
51
52def n_params(module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected