if
statements can be merged PTC-W0048137 g_norm = torch.norm(p.grad.data)
138
139 # lars scaling + weight decay part
140 if weight_decay != 0:141 if p_norm != 0 and g_norm != 0:
142 lars_lr = p_norm / (
143 g_norm + p_norm * weight_decay + group["eps"]
Nested if
statements can be collapsed into a single if
statement by separating their condition using and
operator.
Merging collapsible if
statements increases the code's readability.
if condition1:
if condition2:
dosomething()
if condition1 and condition2:
dosomething()
DeepSource will not raise this issue when the nested if
statements have comments in between them, as it could be explaining why the nested if
is in place.