PR #124927
tensorflow/tensorflow · Core Math · Merged · 2 files changed
The C++ Eigen kernel for tf.math.igamma omitted a domain boundary check for non-positive shape parameters (a <= 0) when x == 0, returning invalid finite values instead of NaN. I restored exact mathematical domain semantics across the kernel.
Checkout Pull Request
Inspect the full commit history and diff locally from upstream tensorflow/tensorflow.
$gh pr checkout 124927 --repo tensorflow/tensorflowThe C++ Eigen kernel for tf.math.igamma omitted a domain boundary check for non-positive shape parameters (a <= 0) when x == 0, returning invalid finite values instead of NaN. I restored exact mathematical domain semantics across the kernel.
File-by-File Modification Breakdown (2)
- +37 / -1
tensorflow/core/kernels/cwise_ops.h
Core C++ Eigen kernel implementation and boundary guards
- +24 / -0
tensorflow/python/kernel_tests/math_ops/cwise_ops_binary_test.py
Python/XLA regression test suite verifying edge-case behavior
Changed Files (2)
1. Introduction & Motivation
Special functions in TensorFlow underpin probabilistic programming, survival analysis, and Bayesian inference. Because downstream models often evaluate tf.math.igamma across broad parameter sweeps or during unconstrained optimization steps, out-of-domain inputs must strictly produce NaN rather than silent finite numbers that could corrupt loss landscapes or gradients without warning [1].
2. Mathematical Formulation & Domain Analysis
The lower regularized incomplete gamma function is defined for and by:
When and , two singularities interact in Equation (1): exhibits simple poles at non-positive integers (), while the integrand diverges as . Consequently, for is mathematically indeterminate and must evaluate to :
| Domain Region | Analytical Value | Kernel Output (After) |
|---|---|---|
0.0 | ||
| Indeterminate | NaN (matches SciPy) |
3. Implementation & Verification
Regression tests confirm exact agreement with SciPy scipy.special.gammainc across float32 and float64.
4. References
- DLMF (NIST Digital Library of Mathematical Functions), Chapter 8: Incomplete Gamma and Related Functions, Eq. 8.2.4.
- IEEE Computer Society, IEEE Standard for Floating-Point Arithmetic (IEEE Std 754-2019), quiet
NaNpropagation rules.