{"record":{"id":"18cb5db65046d4dc","repo":"jax-ml/jax","slug":"exp1-does-not-support-complex-valued-inputs","errorCode":null,"errorMessage":"exp1 does not support complex-valued inputs.","messagePattern":"exp1 does not support complex-valued inputs\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/special.py","lineNumber":3022,"sourceCode":"\n  .. math::\n\n     \\mathrm{exp1}(x) = E_1(x) = \\int_x^\\infty\\frac{e^{-t}}{t}\\mathrm{d}t\n\n\n  Args:\n    x: arraylike, real-valued\n\n  Returns:\n    array of exp1 values\n\n  See also:\n    - :func:`jax.scipy.special.expi`\n    - :func:`jax.scipy.special.expn`\n  \"\"\"\n  x, = promote_args_inexact(\"exp1\", x)\n  if dtypes.issubdtype(x.dtype, np.complexfloating):\n    raise ValueError(\"exp1 does not support complex-valued inputs.\")\n  return expn(1, x)\n\n\ndef _spence_poly(w: Array) -> Array:\n  A = jnp.array([4.65128586073990045278E-5,\n                  7.31589045238094711071E-3,\n                  1.33847639578309018650E-1,\n                  8.79691311754530315341E-1,\n                  2.71149851196553469920E0,\n                  4.25697156008121755724E0,\n                  3.29771340985225106936E0,\n                  1.00000000000000000126E0,\n                  ], dtype=w.dtype)\n\n  B = jnp.array([6.90990488912553276999E-4,\n                  2.54043763932544379113E-2,\n                  2.82974860602568089943E-1,\n                  1.41172597751831069617E0,","sourceCodeStart":3004,"sourceCodeEnd":3040,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/special.py#L3004-L3040","documentation":"jax.scipy.special.exp1 (exponential integral E1) immediately delegates to expn(1, x) and inherits its restriction: complex inputs raise ValueError. Although E1 has a standard complex definition (Ei/E1 via analytic continuation), JAX's implementation is real-only.","triggerScenarios":"Passing complex arrays or Python complex numbers to jax.scipy.special.exp1; complex tangents under jit/grad flows that reach exp1.","commonSituations":"Porting SciPy/mpmath code computing E1 for complex arguments (e.g. plasma dispersion, Laplace-transform inversion); accidental complex promotion from previous ops.","solutions":["Use scipy.special.exp1 or mpmath.expint via jax.pure_callback for complex arguments.","If the imaginary part is a numerical artifact, take jnp.real(x) after verifying it is ~0.","Add a dtype assertion in your wrapper to fail fast with a clearer message."],"exampleFix":"# before (raises)\ny = jax.scipy.special.exp1(z)  # z complex\n\n# after\ny = jax.pure_callback(scipy.special.exp1, z.real.dtype, z)","handlingStrategy":"type-guard","validationCode":"x = jnp.asarray(x)\nif dtypes.issubdtype(x.dtype, jnp.complexfloating):\n    raise TypeError('exp1 in JAX is real-only; use scipy.special.exp1 for complex x')","typeGuard":"def is_real_float(x) -> bool:\n    return not dtypes.issubdtype(jnp.asarray(x).dtype, jnp.complexfloating)","tryCatchPattern":"try:\n    y = jax.scipy.special.exp1(x)\nexcept ValueError:\n    y = jax.pure_callback(scipy.special.exp1, x.real.dtype, x)","preventionTips":["Add dtype checks at API boundaries receiving external numeric data.","Remember exp1 delegates to expn, so complex restrictions propagate."],"tags":["jax","exp1","complex-numbers","unsupported-dtype","exponential-integral"],"backgroundTag":"complex-input-unsupported","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}