Skip to content

Commit 50db279

Browse files
committed
Minor re-structure
1 parent fc77d6c commit 50db279

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

pytorch_lightning/utilities/apply_func.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,20 @@ def apply_to_collection(
131131
result = deepcopy(data, memo=memo)
132132
# apply function to each field
133133
for field_name, (field_value, field_init) in fields.items():
134-
if field_init:
135-
v = apply_to_collection(
136-
field_value,
137-
dtype,
138-
function,
139-
*args,
140-
wrong_dtype=wrong_dtype,
141-
include_none=include_none,
142-
**kwargs,
143-
)
144-
if include_none or v is not None:
145-
setattr(result, field_name, v)
146-
else: # retain old value
147-
setattr(result, field_name, getattr(data, field_name))
134+
if not field_init:
135+
continue
136+
v = apply_to_collection(
137+
field_value,
138+
dtype,
139+
function,
140+
*args,
141+
wrong_dtype=wrong_dtype,
142+
include_none=include_none,
143+
**kwargs,
144+
)
145+
if not include_none and v is None: # retain old value
146+
v = getattr(data, field_name)
147+
setattr(result, field_name, v)
148148
return result
149149

150150
# data is neither of dtype, nor a collection

0 commit comments

Comments
 (0)