jax icon indicating copy to clipboard operation
jax copied to clipboard

Propagate NaNs in uniform stats functions

Open KirtiRamchandani opened this issue 5 months ago • 2 comments

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

  • cdf uses comparison masks with jnp.select; comparisons with NaN are all false, so the default branch returned 0.
  • logpdf only checked range comparisons, so NaN inputs fell through to -log(scale), and pdf inherited that finite result via exp(logpdf).

Tests

  • Reproduced the pre-fix behavior: cdf(nan)=0.0, pdf(nan)=1.0, logpdf(nan)=-0.0 while SciPy returns nan.
  • .\.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.py
  • git diff --check

KirtiRamchandani avatar Jun 11 '26 12:06 KirtiRamchandani

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.

KirtiRamchandani avatar Jun 13 '26 17:06 KirtiRamchandani

This falls under #38651; please note that it may take a while for this to receive attention from the team.

jakevdp avatar Jun 22 '26 12:06 jakevdp