Commit 44cc0f7
committed
fix(zenpredict): argmin_masked_top_k skips NaN scores per documented contract
The consider() closure only rejected a NaN score once the top-K array was
full (the count == K branch's score < top[K-1].0 comparison, where NaN < x
is always false). While count < K, it inserted UNCONDITIONALLY — the
shift-loop's top[i - 1].0 > score never fires for a NaN score (every
comparison with NaN is false), so the NaN just landed in the next empty
slot instead of being skipped. This violated the function's own documented
'same NaN ... contract as argmin_masked' (NaN cells silently skipped, never
picked).
Fixed: skip immediately when score.is_nan(), before either branch.
Added argmin_top_k_skips_nan_scores: 5 predictions with 2 NaNs (both in the
count<K window) must never appear in the top-3 result; an all-NaN input
must yield [None, None, None]. Verified the test fails without the fix
(reproduced: NaN landed at index 0 instead of being skipped) and passes
with it. cargo test -p zenpredict --lib --features advanced: 141 passed.1 parent 834035b commit 44cc0f7
2 files changed
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
242 | 249 | | |
243 | 250 | | |
244 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
59 | 81 | | |
60 | 82 | | |
61 | 83 | | |
| |||
0 commit comments