MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / ensure_tuple_size

Function ensure_tuple_size

monai/utils/misc.py:181–191  ·  view source on GitHub ↗

Returns a copy of `tup` with `dim` values by either shortened or padded with `pad_val` as necessary.

(vals: Any, dim: int, pad_val: Any = 0, pad_from_start: bool = False)

Source from the content-addressed store, hash-verified

179
180
181def ensure_tuple_size(vals: Any, dim: int, pad_val: Any = 0, pad_from_start: bool = False) -> tuple:
182 """
183 Returns a copy of `tup` with `dim` values by either shortened or padded with `pad_val` as necessary.
184 """
185 tup = ensure_tuple(vals)
186 pad_dim = dim - len(tup)
187 if pad_dim <= 0:
188 return tup[:dim]
189 if pad_from_start:
190 return (pad_val,) * pad_dim + tup
191 return tup + (pad_val,) * pad_dim
192
193
194def ensure_tuple_rep(tup: Any, dim: int) -> tuple[Any, ...]:

Callers 12

forwardMethod · 0.90
dense_patch_slicesFunction · 0.90
iter_patch_positionFunction · 0.90
iter_patchFunction · 0.90
get_valid_patch_sizeFunction · 0.90
_create_shearFunction · 0.90
_create_scaleFunction · 0.90
__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
aggregateMethod · 0.90
aggregateMethod · 0.90

Calls 1

ensure_tupleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…