jax-ml/jax · error · ValueError

dawsn does not support complex-valued inputs.

Error message

dawsn does not support complex-valued inputs.

What it means

jax.scipy.special.dawsn (Dawson's integral) only supports real inputs. After promote_args_inexact, if the dtype is a complex subtype it raises ValueError because the custom-JVP implementation _dawsn branches only on float32/float64.

Source

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

  JAX implementation of :obj:`scipy.special.dawsn`.

  .. math::

     \mathrm{dawsn}(x) = e^{-x^2} \int_0^x e^{t^2} \, dt

  Args:
    x: arraylike, real-valued.

  Returns:
    array containing values of Dawson's integral.

  See also:
    - :func:`jax.scipy.special.erfcx`
  """
  x, = promote_args_inexact("dawsn", x)
  if dtypes.issubdtype(x.dtype, np.complexfloating):
    raise ValueError("dawsn does not support complex-valued inputs.")
  return _dawsn(x)


@custom_derivatives.custom_jvp
def _dawsn(x: Array) -> Array:
  if x.dtype in [np.float32, np.float64]:
    return _dawsn_impl(x)
  else:  # float16, bfloat16 — upcast to float32
    return _dawsn_impl(x.astype(np.float32)).astype(x.dtype)

_dawsn.defjvps(
    lambda g, ans, x: g * (_lax_const(x, 1.) - _lax_const(x, 2.) * x * ans))


def _dawsn_impl(x: Array) -> Array:
  # Rational approximations from Cody, Paciorek, Thacher (1970).
  # All approximations work on |x|; odd symmetry restores the sign.
  sign = jnp.sign(x)

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Take the real part first: dawsn(jnp.real(x))
  2. Validate dtype before calling: reject or branch on np.issubdtype(x.dtype, np.complexfloating)
  3. Use mpmath or a custom implementation for complex Dawson's integral outside JAX

Example fix

// before
jax.scipy.special.dawsn(complex_array)
// after
jax.scipy.special.dawsn(jnp.real(complex_array))
Defensive patterns

Strategy: type-guard

Validate before calling

if np.issubdtype(jnp.dtype(x), np.complexfloating):
    x = jnp.real(x)  # or raise

Type guard

def is_real_scalar_dtype(x):
    return jnp.dtype(x) in (jnp.float32, jnp.float64)

Prevention

When it happens

Trigger: Calling jax.scipy.special.dawsn(x) with complex input, e.g. dawsn(1j) or a complex array produced upstream (testDawsnLargeX-style tests with complex tensors).

Common situations: Plasma/physics simulations where Dawson's integral appears alongside complex fields; passing complex168 arrays from FFT-based pipelines; assuming SciPy's broader dtype tolerance carries over to jax.scipy.

Related errors


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