Skip to content

Commit 44066af

Browse files
KumoLiuatbenmurray
andauthored
Update monai/transforms/transform.py
Co-authored-by: Ben Murray <[email protected]> Signed-off-by: YunLiu <[email protected]>
1 parent d1fe247 commit 44066af

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

monai/transforms/transform.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,12 @@ def apply_transform(
137137
Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof.
138138
"""
139139
try:
140-
if isinstance(data, (list, tuple)) and (map_items or type(map_items) is int):
141-
# if map_items is an int, apply the transform to each item in the list `map_items` times
142-
if type(map_items) is int and map_items > 0:
143-
return [
144-
apply_transform(transform, item, map_items - 2, unpack_items, log_stats, lazy, overrides)
145-
for item in data
146-
]
147-
else:
148-
return [_apply_transform(transform, item, unpack_items, lazy, overrides, log_stats) for item in data]
140+
map_items_ = int(map_items) if isinstance(map_items, bool) else map_items
141+
if isinstance(data, (list, tuple)) and map_items_ > 0:
142+
return [
143+
apply_transform(transform, item, map_items - 1, unpack_items, log_stats, lazy, overrides)
144+
for item in data
145+
]
149146
return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
150147
except Exception as e:
151148
# if in debug mode, don't swallow exception so that the breakpoint

0 commit comments

Comments
 (0)