fix: clamp RT histogram to non-negative before sqrt#434
Merged
Conversation
interp_hist() can produce tiny negative values (on the order of -1e-31) from floating-point noise in linear interpolation of energy histograms. np.sqrt() turns these into NaN, and downstream IIR filters (sosfiltfilt in compute_rir's high-pass) propagate a single NaN sample to the entire RIR — silently destroying it. Fixes LCAV#433. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
Thanks for the fix! |
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.
Summary
interp_hist()can produce tiny negative values (~1e-31) from floating-point noise in linear interpolation of energy histogramsnp.sqrt()turns these into NaNsosfiltfiltincompute_rir's high-pass) propagate a single NaN sample to the entire RIR, silently destroying itnp.sqrt(np.maximum(hist, 0.0))— clamp before sqrtFixes #433.
Reproduction
The issue triggers when ray tracing + HRTF directivity are combined. A specific source/mic geometry produces a histogram band where linear interpolation dips infinitesimally below zero. The resulting NaN cascades through the IIR high-pass filter to corrupt every sample in the RIR.
Test plan