Skip to content

Commit

Permalink
perf(task): only count nans/infs if any are found
Browse files Browse the repository at this point in the history
  • Loading branch information
ljgray committed Mar 27, 2023
1 parent 83d4a55 commit 32716c4
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions draco/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,26 +576,20 @@ def _nan_check_walk(self, cont):
# casting to ndarray, bc MPI ranks may fall out of sync, if a nan or inf are found
arr = n[:].view(np.ndarray)
try:
total_nan = np.isnan(arr).sum()
total_inf = np.isinf(arr).sum()
nans = np.isnan(arr)
infs = np.isinf(arr)
except TypeError:
continue

if total_nan > 0:
if nans.any():
self.log.info(
"NaN's found in dataset %s [%i of %i elements]",
n.name,
total_nan,
arr.size,
f"NaN's found in dataset {n.name} [{nans.sum()} of {arr.size} elements]"
)
found = True

if total_inf > 0:
if infs.any():
self.log.info(
"Inf's found in dataset %s [%i of %i elements]",
n.name,
total_inf,
arr.size,
f"Inf's found in dataset {n.name} [{infs.sum()} of {arr.size} elements]"
)
found = True

Expand Down

0 comments on commit 32716c4

Please sign in to comment.