{"record":{"id":"3f6c5a40c06fe4d5","repo":"jax-ml/jax","slug":"hyp1f1-does-not-support-complex-valued-inputs","errorCode":null,"errorMessage":"hyp1f1 does not support complex-valued inputs.","messagePattern":"hyp1f1 does not support complex-valued inputs\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/special.py","lineNumber":3357,"sourceCode":"  and ``x``, leading to high values of 1F1 may lead to erroneous results;\n  consider enabling double precision in this case. The convention for\n  ``a = b = 0`` is ``1``, unlike in scipy's implementation.\n\n  Args:\n    a: arraylike, real-valued\n    b: arraylike, real-valued\n    x: arraylike, real-valued\n\n  Returns:\n    array of 1F1 values.\n  \"\"\"\n  # This is backed by https://doi.org/10.48550/arXiv.1407.7786\n  # There is room for improvement in the implementation using recursion to\n  # evaluate lower values of hyp1f1 when a or b or both are > 60-80\n  a, b, x = promote_args_inexact('hyp1f1', a, b, x)\n\n  if dtypes.issubdtype(x.dtype, np.complexfloating):\n    raise ValueError(\"hyp1f1 does not support complex-valued inputs.\")\n\n  result = lax.cond(lax.abs(x) < 100, _hyp1f1_serie, _hyp1f1_asymptotic, a, b, x)\n  index = (a == 0) * 1 + ((a == b) & (a != 0)) * 2 + ((b == 0) & (a != 0)) * 3\n\n  return lax.select_n(index,\n                      result,\n                      jnp.array(1, dtype=x.dtype),\n                      jnp.exp(x),\n                      jnp.array(np.inf, dtype=x.dtype))\n\n\nhyp1f1.defjvps(\n  lambda a_dot, primal_out, a, b, x: _hyp1f1_a_derivative(a, b, x) * a_dot,\n  lambda b_dot, primal_out, a, b, x: _hyp1f1_b_derivative(a, b, x) * b_dot,\n  lambda x_dot, primal_out, a, b, x: _hyp1f1_x_derivative(a, b, x) * x_dot\n)\n\n","sourceCodeStart":3339,"sourceCodeEnd":3375,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/special.py#L3339-L3375","documentation":"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.","triggerScenarios":"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.","commonSituations":"Quantum/physics computations needing complex-valued 1F1; reusing scipy code where x is complex.","solutions":["Keep all three arguments real-valued; cast complex128 with zero imaginary part to float64 before the call.","Use scipy.special.hyp1f1 (or mpmath.hyp1f1) on the host for complex inputs.","Restructure the computation to avoid complex x, e.g. evaluate identities that keep intermediates real."],"exampleFix":"// before\njax.scipy.special.hyp1f1(1.0, 2.0, jnp.array(1.0 + 0.0j))\n\n// after\njax.scipy.special.hyp1f1(1.0, 2.0, jnp.array(1.0))  # real dtype","handlingStrategy":"type-guard","validationCode":"x = x.real if (jnp.issubdtype(jnp.result_type(x), jnp.complexfloating) and bool(jnp.allclose(x.imag, 0))) else x","typeGuard":"def is_real_hyp1f1_args(a, b, x) -> bool:\n    return not jnp.issubdtype(jnp.result_type(a, b, x), jnp.complexfloating)","tryCatchPattern":null,"preventionTips":["Verify dtype after promotion of all args, not just x.","Cast away zero imaginary parts before calling."],"tags":["jax","scipy","hyp1f1","complex-dtype","unsupported-operation"],"backgroundTag":"jax-complex-unsupported","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}