jax-ml/jax · error · ValueError
betainc does not support complex-valued inputs.
Error message
betainc does not support complex-valued inputs.
What it means
jax.scipy.special.betainc (the regularized incomplete beta function) explicitly rejects complex-valued inputs. After promoting arguments to inexact dtypes, it checks whether x is a complex subtype and raises ValueError because the underlying lax.betainc primitive is only defined for real numbers.
Source
Thrown at jax/_src/scipy/special.py:461
\mathrm{betainc}(a, b, x) = \frac{1}{B(a, b)}\int_0^x t^{a-1}(1-t)^{b-1}\mathrm{d}t
where :math:`B(a, b)` is the :func:`~jax.scipy.special.beta` function.
Args:
a: arraylike, real-valued. Parameter *a* of the beta distribution.
b: arraylike, real-valued. Parameter *b* of the beta distribution.
x: arraylike, real-valued. Upper limit of the integration.
Returns:
array containing values of the betainc function
See Also:
- :func:`jax.scipy.special.beta`
- :func:`jax.scipy.special.betaln`
"""
a, b, x = promote_args_inexact("betainc", a, b, x)
if dtypes.issubdtype(x.dtype, np.complexfloating):
raise ValueError("betainc does not support complex-valued inputs.")
return lax.betainc(a, b, x)
def digamma(x: ArrayLike) -> Array:
r"""The digamma function
JAX implementation of :obj:`scipy.special.digamma`.
.. math::
\mathrm{digamma}(x) = \psi(x) = \frac{\mathrm{d}}{\mathrm{d}x}\log \Gamma(x)
where :math:`\Gamma(x)` is the :func:`~jax.scipy.special.gamma` function.
Args:
x: arraylike, real-valued.
Returns:View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Convert x (and a, b) to real before calling: jnp.real(x) or x.real if the imaginary part is known to be zero
- Check x.dtype with np.issubdtype(x.dtype, np.complexfloating) and branch to a real-only path
- If you truly need complex incomplete beta, implement it yourself or use mpmath outside of JAX
Example fix
// before jax.scipy.special.betainc(a, b, z) # z is complex // after jax.scipy.special.betainc(a, b, jnp.real(z))
Defensive patterns
Strategy: type-guard
Validate before calling
x = jnp.asarray(x)
if np.issubdtype(x.dtype, np.complexfloating):
raise TypeError('betainc requires real x; got ' + str(x.dtype)) Type guard
def is_real(x) -> bool:
return not np.issubdtype(jnp.dtype(x), np.complexfloating) Prevention
- Keep statistical CDF inputs real by design; add dtype assertions at pipeline entry
- Log jnp.result_type(a, b, x) before special-function calls to catch promotion surprises
When it happens
Trigger: Calling jax.scipy.special.betainc(a, b, x) where any argument (after promotion) yields a complex dtype, e.g. x = 1+2j or mixing a complex scalar with real arrays so promote_args_inexact upgrades the result to complex128.
Common situations: Porting SciPy code that operates on complex spectra; accidentally passing complex tensors from a signal-processing or quantum pipeline into a statistical CDF; dtype promotion surprises where one complex operand makes the whole call complex.
Related errors
- dawsn does not support complex-valued inputs.
- entr does not support complex-valued inputs.
- kl_div does not support complex-valued inputs.
- rel_entr does not support complex-valued inputs.
- Argument `n` to polygamma must be of integer type. Got dtype
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/9b8542407e95869a.
Report an issue: GitHub.