jax-ml/jax · error · ValueError

hyp1f1 does not support complex-valued inputs.

Error message

hyp1f1 does not support complex-valued inputs.

What it means

jax.scipy.special.hyp1f1 (Kummer confluent hypergeometric) is implemented only for real arguments via series/asymptotic branches; the code checks the promoted x dtype and raises for complexfloating.

Source

Thrown at jax/_src/scipy/special.py:3357

  and ``x``, leading to high values of 1F1 may lead to erroneous results;
  consider enabling double precision in this case. The convention for
  ``a = b = 0`` is ``1``, unlike in scipy's implementation.

  Args:
    a: arraylike, real-valued
    b: arraylike, real-valued
    x: arraylike, real-valued

  Returns:
    array of 1F1 values.
  """
  # This is backed by https://doi.org/10.48550/arXiv.1407.7786
  # There is room for improvement in the implementation using recursion to
  # evaluate lower values of hyp1f1 when a or b or both are > 60-80
  a, b, x = promote_args_inexact('hyp1f1', a, b, x)

  if dtypes.issubdtype(x.dtype, np.complexfloating):
    raise ValueError("hyp1f1 does not support complex-valued inputs.")

  result = lax.cond(lax.abs(x) < 100, _hyp1f1_serie, _hyp1f1_asymptotic, a, b, x)
  index = (a == 0) * 1 + ((a == b) & (a != 0)) * 2 + ((b == 0) & (a != 0)) * 3

  return lax.select_n(index,
                      result,
                      jnp.array(1, dtype=x.dtype),
                      jnp.exp(x),
                      jnp.array(np.inf, dtype=x.dtype))


hyp1f1.defjvps(
  lambda a_dot, primal_out, a, b, x: _hyp1f1_a_derivative(a, b, x) * a_dot,
  lambda b_dot, primal_out, a, b, x: _hyp1f1_b_derivative(a, b, x) * b_dot,
  lambda x_dot, primal_out, a, b, x: _hyp1f1_x_derivative(a, b, x) * x_dot
)

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Keep all three arguments real-valued; cast complex128 with zero imaginary part to float64 before the call.
  2. Use scipy.special.hyp1f1 (or mpmath.hyp1f1) on the host for complex inputs.
  3. Restructure the computation to avoid complex x, e.g. evaluate identities that keep intermediates real.

Example fix

// before
jax.scipy.special.hyp1f1(1.0, 2.0, jnp.array(1.0 + 0.0j))

// after
jax.scipy.special.hyp1f1(1.0, 2.0, jnp.array(1.0))  # real dtype
Defensive patterns

Strategy: type-guard

Validate before calling

x = x.real if (jnp.issubdtype(jnp.result_type(x), jnp.complexfloating) and bool(jnp.allclose(x.imag, 0))) else x

Type guard

def is_real_hyp1f1_args(a, b, x) -> bool:
    return not jnp.issubdtype(jnp.result_type(a, b, x), jnp.complexfloating)

Prevention

When it happens

Trigger: Calling jax.scipy.special.hyp1f1(a, b, x) where a, b, or x is complex, or where promotion of mixed arguments (e.g. complex a with float x) yields a complex x dtype.

Common situations: Quantum/physics computations needing complex-valued 1F1; reusing scipy code where x is complex.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/3f6c5a40c06fe4d5. Report an issue: GitHub.