Commit 05f2506
fix: bounds-guard the kernel gather in psf_weighted_data_from
`psf_weighted_data_from` indexed the weight map directly at
`ip0_y + k0_y + kernel_shift_y`, with no check that the position lands on
the array. numba `@jit()` does not bounds-check array reads, so for any
unmasked pixel within `kernel_shape // 2` of the array edge the gather
silently read uninitialized heap memory instead of raising IndexError —
producing contributions of order 1e299 that overflowed downstream into a
NaN figure of merit. A negative index is unsafe in the same way: it wraps
to the opposite edge and convolves in unrelated pixels.
Because the values read are whatever the allocator happened to leave next
to the weight map, the corruption is heap-state dependent, which explains
both reported symptoms: deterministic garbage on the first call after a
cold-cache compile (numba's compilation churns the heap), and intermittent
corruption in forked multiprocessing workers, where each worker has a
different heap layout.
The sibling `psf_precision_value_from` was already hardened against exactly
this; `psf_weighted_data_from` was missed. This applies the same guard, so
kernel positions off the array contribute zero — matching the zero-padded
numpy reference in `inversion_imaging_util.psf_weighted_data_from`.
The regression test compares the numba and numpy implementations on a mask
whose unmasked pixels reach the array edge. Every existing test in that
module masks a one-pixel border, so none of them exercised this path.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013unzp382r79c4BN8g4ckb21 parent 1c33850 commit 05f2506
2 files changed
Lines changed: 67 additions & 3 deletions
File tree
- autoarray/inversion/inversion/imaging_numba
- test_autoarray/inversion/inversion/imaging
Lines changed: 22 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
67 | 86 | | |
68 | 87 | | |
69 | 88 | | |
| |||
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
39 | 84 | | |
40 | 85 | | |
41 | 86 | | |
| |||
0 commit comments