Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2025-02-12 - Avoid np.isnan with lists for scalar checks
**Learning:** Checking for NaNs in scalars using `np.isnan([a, b, c]).any()` incurs significant overhead from list allocation and array conversion, taking ~20x longer than using `math.isnan(a) or math.isnan(b) or math.isnan(c)`.
**Action:** For simple scalar validation where types are handled or fallbacks exist, prefer `math.isnan` coupled with `try/except TypeError` over constructing NumPy arrays.
6 changes: 4 additions & 2 deletions ml_peg/analysis/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collections import defaultdict
from collections.abc import Callable, Iterable
import math
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -696,8 +697,9 @@ def normalize_metric(
return None

try:
# Handle NaNs robustly
if np.isnan([value, good_threshold, bad_threshold]).any():
# Handle NaNs robustly. Use math.isnan instead of np.isnan
# to avoid list/array allocation overhead.
if math.isnan(value) or math.isnan(good_threshold) or math.isnan(bad_threshold):
return None
except TypeError:
return None
Expand Down
Loading