jax
jax copied to clipboard
Propagate NaNs in uniform stats functions
Summary
Fixes #38317.
jax.scipy.stats.uniform.cdf, pdf, and logpdf now propagate NaNs in x, loc, or scale instead of treating NaN comparisons as ordinary in-support values.
Root cause
cdfuses comparison masks withjnp.select; comparisons with NaN are all false, so the default branch returned0.logpdfonly checked range comparisons, so NaN inputs fell through to-log(scale), andpdfinherited that finite result viaexp(logpdf).
Tests
- Reproduced the pre-fix behavior:
cdf(nan)=0.0,pdf(nan)=1.0,logpdf(nan)=-0.0while SciPy returnsnan. .\.venv\Scripts\python.exe -m pytest tests/scipy_stats_test.py -k testUniformNanPropagation -q.\.venv\Scripts\python.exe -m pytest tests/scipy_stats_test.py -k "testUniformLogPdf or testUniformCdf or testUniformPpf" -q.\.venv\Scripts\python.exe -m pytest tests/scipy_stats_test.py -k Uniform -q.\.venv\Scripts\python.exe -m ruff check jax/_src/scipy/stats/uniform.py tests/scipy_stats_test.pygit diff --check
Thanks for the review — appreciate the confirmation on NaN propagation behavior for uniform logpdf/cdf.
Ready to adjust if you'd like explicit scalar/array NaN cases split out.
This falls under #38651; please note that it may take a while for this to receive attention from the team.