Skip to content

Commit

Permalink
Minor re-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
carmocca committed Nov 9, 2021
1 parent fc77d6c commit 50db279
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pytorch_lightning/utilities/apply_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,20 @@ def apply_to_collection(
result = deepcopy(data, memo=memo)
# apply function to each field
for field_name, (field_value, field_init) in fields.items():
if field_init:
v = apply_to_collection(
field_value,
dtype,
function,
*args,
wrong_dtype=wrong_dtype,
include_none=include_none,
**kwargs,
)
if include_none or v is not None:
setattr(result, field_name, v)
else: # retain old value
setattr(result, field_name, getattr(data, field_name))
if not field_init:
continue
v = apply_to_collection(
field_value,
dtype,
function,
*args,
wrong_dtype=wrong_dtype,
include_none=include_none,
**kwargs,
)
if not include_none and v is None: # retain old value
v = getattr(data, field_name)
setattr(result, field_name, v)
return result

# data is neither of dtype, nor a collection
Expand Down

0 comments on commit 50db279

Please sign in to comment.