{"record":{"id":"4337226ef96280a6","repo":"jax-ml/jax","slug":"dawsn-does-not-support-complex-valued-inputs","errorCode":null,"errorMessage":"dawsn does not support complex-valued inputs.","messagePattern":"dawsn does not support complex-valued inputs\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/special.py","lineNumber":831,"sourceCode":"\n  JAX implementation of :obj:`scipy.special.dawsn`.\n\n  .. math::\n\n     \\mathrm{dawsn}(x) = e^{-x^2} \\int_0^x e^{t^2} \\, dt\n\n  Args:\n    x: arraylike, real-valued.\n\n  Returns:\n    array containing values of Dawson's integral.\n\n  See also:\n    - :func:`jax.scipy.special.erfcx`\n  \"\"\"\n  x, = promote_args_inexact(\"dawsn\", x)\n  if dtypes.issubdtype(x.dtype, np.complexfloating):\n    raise ValueError(\"dawsn does not support complex-valued inputs.\")\n  return _dawsn(x)\n\n\n@custom_derivatives.custom_jvp\ndef _dawsn(x: Array) -> Array:\n  if x.dtype in [np.float32, np.float64]:\n    return _dawsn_impl(x)\n  else:  # float16, bfloat16 — upcast to float32\n    return _dawsn_impl(x.astype(np.float32)).astype(x.dtype)\n\n_dawsn.defjvps(\n    lambda g, ans, x: g * (_lax_const(x, 1.) - _lax_const(x, 2.) * x * ans))\n\n\ndef _dawsn_impl(x: Array) -> Array:\n  # Rational approximations from Cody, Paciorek, Thacher (1970).\n  # All approximations work on |x|; odd symmetry restores the sign.\n  sign = jnp.sign(x)","sourceCodeStart":813,"sourceCodeEnd":849,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/special.py#L813-L849","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Take the real part first: dawsn(jnp.real(x))","Validate dtype before calling: reject or branch on np.issubdtype(x.dtype, np.complexfloating)","Use mpmath or a custom implementation for complex Dawson's integral outside JAX"],"exampleFix":"// before\njax.scipy.special.dawsn(complex_array)\n// after\njax.scipy.special.dawsn(jnp.real(complex_array))","handlingStrategy":"type-guard","validationCode":"if np.issubdtype(jnp.dtype(x), np.complexfloating):\n    x = jnp.real(x)  # or raise","typeGuard":"def is_real_scalar_dtype(x):\n    return jnp.dtype(x) in (jnp.float32, jnp.float64)","tryCatchPattern":null,"preventionTips":["Assert real dtype before Dawson/Poisson-kernel style integrals","Separate complex field arrays from real special-function inputs in physics code"],"tags":["jax","scipy-special","dawson","complex-dtype"],"backgroundTag":"unsupported-complex-input","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}