Reject non-finite / float32-underflowing local_position_std - #45
Merged
Merged
Conversation
_DetectorBase only checked `local_position_std < 0`, so NaN and Inf slipped through (`nan < 0` and `inf < 0` are both False) and a positive value whose float32 square underflows to 0 (below sqrt(float32 tiny) ~1.085e-19) passed too. Both then produced NaN / divide-by-zero in the Local anchor kernel (-0.5*d**2/sigma**2, evaluated in float32 with JAX flush-to-zero). Raise ValidationError at __init__ for all three. None (legacy single-bin) and 0.0 (delta kernel) remain valid and unchanged. Ports the validator hardening from the now-superseded PR #25; its anchor-kernel and mass-balance work already landed on main via other PRs, and this was the only piece main still lacked. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the one piece of value left in #25 (closed as superseded): hardened
validation of
local_position_std. The anchor-kernel and mass-balance work #25carried already landed on
mainvia other PRs, butmainstill only checkslocal_position_std < 0.Problem
_DetectorBase.__init__gated solely onlocal_position_std < 0, so:nan < 0andinf < 0are bothFalse)sqrt(np.finfo(np.float32).tiny)≈1.085e-19— passed tooEither then produced a
NaN/ divide-by-zero in the Local anchor kernel(
-0.5·d²/σ², evaluated in float32 where JAX flushes subnormals to zero).Change
Raise
ValidationErrorat construction for non-finite and float32-underflowingwidths, alongside the existing negative check.
None(legacy single-bin Local)and
0.0(delta kernel) remain valid and unchanged — this only rejects inputsthat were already silently broken.
Consistent with the tier-1 "invalid input → raise" policy from #35.
Tests
Added to
TestLocalPositionStdValidation: NaN/Inf/-Inf rejection (parametrized),float32-square-underflow rejection, and a boundary-accept case at the threshold.
Verified they fail on
mainbefore the guard and pass after; the existingnegative-rejection test is unchanged. Full
test_local_position_std.py(39) andthe
test_local_spatial_uncertaintyintegration suite (10) pass; ruff clean.🤖 Generated with Claude Code