From 13200c8389812089bea0871861046d8d5b207130 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Thu, 16 Dec 2021 10:07:46 +0000 Subject: [PATCH] Removes redundant casting -- ensure tuple Signed-off-by: Wenqi Li --- monai/utils/misc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monai/utils/misc.py b/monai/utils/misc.py index 1cb5c90244..d1428e4ced 100644 --- a/monai/utils/misc.py +++ b/monai/utils/misc.py @@ -89,7 +89,7 @@ def ensure_tuple(vals: Any) -> Tuple[Any, ...]: Returns a tuple of `vals`. """ if not issequenceiterable(vals): - vals = (vals,) + return (vals,) return tuple(vals) @@ -98,8 +98,8 @@ def ensure_tuple_size(tup: Any, dim: int, pad_val: Any = 0) -> Tuple[Any, ...]: """ Returns a copy of `tup` with `dim` values by either shortened or padded with `pad_val` as necessary. """ - tup = ensure_tuple(tup) + (pad_val,) * dim - return tuple(tup[:dim]) + new_tup = ensure_tuple(tup) + (pad_val,) * dim + return new_tup[:dim] def ensure_tuple_rep(tup: Any, dim: int) -> Tuple[Any, ...]: