Skip to content

fix: clamp RT histogram to non-negative before sqrt#434

Merged
fakufaku merged 1 commit into
LCAV:masterfrom
wizory:fix/rt-histogram-nan-sqrt
May 1, 2026
Merged

fix: clamp RT histogram to non-negative before sqrt#434
fakufaku merged 1 commit into
LCAV:masterfrom
wizory:fix/rt-histogram-nan-sqrt

Conversation

@jguice

@jguice jguice commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • interp_hist() can produce tiny negative values (~1e-31) from floating-point noise in linear interpolation of energy histograms
  • np.sqrt() turns these into NaN
  • Downstream IIR filters (sosfiltfilt in compute_rir's high-pass) propagate a single NaN sample to the entire RIR, silently destroying it
  • Fix: np.sqrt(np.maximum(hist, 0.0)) — clamp before sqrt

Fixes #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

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>
@fakufaku fakufaku merged commit 0a7a6ef into LCAV:master May 1, 2026
9 checks passed
@fakufaku

fakufaku commented May 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NaN with raytracing scattering for mics close to the wall

2 participants