MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / ensure_tuple

Function ensure_tuple

monai/utils/misc.py:166–178  ·  view source on GitHub ↗

Returns a tuple of `vals`. Args: vals: input data to convert to a tuple. wrap_array: if `True`, treat the input numerical array (ndarray/tensor) as one item of the tuple. if `False`, try to convert the array with `tuple(vals)`, default to `False`.

(vals: Any, wrap_array: bool = False)

Source from the content-addressed store, hash-verified

164
165
166def ensure_tuple(vals: Any, wrap_array: bool = False) -> tuple:
167 """
168 Returns a tuple of `vals`.
169
170 Args:
171 vals: input data to convert to a tuple.
172 wrap_array: if `True`, treat the input numerical array (ndarray/tensor) as one item of the tuple.
173 if `False`, try to convert the array with `tuple(vals)`, default to `False`.
174
175 """
176 if wrap_array and isinstance(vals, (np.ndarray, torch.Tensor)):
177 return (vals,)
178 return tuple(vals) if issequenceiterable(vals) else (vals,)
179
180
181def ensure_tuple_size(vals: Any, dim: int, pad_val: Any = 0, pad_from_start: bool = False) -> tuple:

Callers 15

__call__Method · 0.90
_get_methodMethod · 0.90
convert_to_onnxFunction · 0.90
convert_to_torchscriptFunction · 0.90
convert_to_trtFunction · 0.90
__init__Method · 0.90
__init__Method · 0.90
grid_pullFunction · 0.90
grid_pushFunction · 0.90
grid_countFunction · 0.90
grid_gradFunction · 0.90
__init__Method · 0.90

Calls 1

issequenceiterableFunction · 0.85

Tested by 5

test_valueMethod · 0.72
test_detector_utilsMethod · 0.72
test_retina_shapeMethod · 0.72
test_numpy_valuesMethod · 0.72
test_lr_valuesMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…