jax.scipy.special.expi(0.0)` returns nan instead of -inf
Description
expi documents itself as the "JAX implementation of scipy.special.expi". At x = 0 the exponential integral
has a logarithmic singularity and SciPy returns -inf; JAX returns nan, which then propagates through any array
or reduction that contains a zero.
import jax
jax.config.update("jax_enable_x64", True)
import numpy as np
import jax.numpy as jnp
import scipy.special as osp
from jax.scipy.special import expi, exp1
print(expi(0.0)) # nan
print(osp.expi(0.0)) # -inf
print(expi(jnp.array([-1.0, 0.0, 1.0]))) # [-0.21938396 nan 1.8951179]
print(osp.expi(np.array([-1.0, 0.0, 1.0]))) # [-0.21938393 -inf 1.89511782]
print(exp1(0.0)) # inf <- the sibling handles 0
The branch table in _expi_pos covers 0 < x <= 2, 2 < x <= 4, ... and x > 64; x == 0 matches none of the
bounded intervals and falls into the asymptotic branch, which evaluates 1/x = inf and produces nan. A
subnormal positive argument (for example 2.2e-311) takes the same path.
Expected behavior
-inf, as SciPy returns, and as exp1(0.0) already does with +inf.
System info (python version, jaxlib version, accelerator, etc.)
System info
jax 0.11.2 (the latest release) and 0.10.1, CPU, Python 3.12, Linux x86_64.
Reproduced on main (35e4da0): jax.scipy.special.expi(0.0) returns nan, while scipy gives -inf. I'd like to fix it — special-case x == 0 to -inf and add a scipy-checked test. Signing the Google CLA first. Disclosure: this comment was drafted with an AI assistant; I'm the author and I'll answer review myself. Could a maintainer assign it to me?