Commit 9732581
fix OOB read in psf_precision_value_from causing NaN sparse-CPU log_evidence
The kernel walk in psf_precision_value_from (used by the sparse-operator
CPU inversion path) reads value_native[ip0_y + k0_y + kernel_shift_y, ...]
without bounds checking. For mask pixels within `kernel_shift` of the
noise-map array boundary, that index lands off the array; @numba.jit()
does not bounds-check, so the read returns uninitialized memory.
For the HST 28x28 RectangularAdaptDensity pixelization profiled in
autolens_workspace_developer/jax_profiling/imaging/pixelization_sparse_cpu.py,
this produced 1064 inf entries in the curvature matrix, a NaN log_det,
and ultimately NaN log_evidence. log_likelihood was -191493 (vs the
correct +28664) because the inf-poisoned F+H made the NNLS solver
return all-zeros for s, giving a wildly wrong chi-squared.
The fix adds an explicit bounds check around the kernel read. Off-array
positions are skipped, which matches the function's existing semantics
for masked-but-zeroed interior pixels (`if value > 0.0: ...` already
filters those). After the fix, sparse and non-sparse paths agree on
the HST workspace_developer model to rtol=1.18e-09.
Existing tests are unaffected: the closest util test
(test__psf_precision_operator_sparse_from) uses interior pixels in a
4x4 noise map so the bounds check is a no-op there. The integration
tests in test_factory.py use a 3x3 no-blur PSF (only center=1) so
off-diagonal kernel reads contribute zero regardless. The new
test__psf_precision_operator_sparse_from__edge_pixels exercises the
fixed path with corner pixels and a non-trivial 3x3 PSF, validating
against a pure-numpy reference.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent c9976ed commit 9732581
2 files changed
Lines changed: 104 additions & 3 deletions
File tree
- autoarray/inversion/inversion/imaging_numba
- test_autoarray/inversion/inversion/imaging
Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | | - | |
314 | | - | |
315 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
316 | 331 | | |
317 | 332 | | |
318 | 333 | | |
| |||
Lines changed: 86 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
124 | 210 | | |
125 | 211 | | |
126 | 212 | | |
| |||
0 commit comments