{"record":{"id":"c9b28c842a9e27b9","repo":"jax-ml/jax","slug":"complex-input-not-supported","errorCode":null,"errorMessage":"complex input not supported.","messagePattern":"complex input not supported\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/special.py","lineNumber":1925,"sourceCode":"    n_iter: The number of iterations required for updating the function\n      values. As a rule of thumb, `n_iter` is the smallest nonnegative integer\n      that satisfies the condition\n      `int(0.5 * log10(6.28 + n_iter) - n_iter *  log10(1.36 + abs(z) / n_iter)) > 20`.\n      Details in `BJNDD` (https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.f)\n\n  Returns:\n    An array of shape `(v+1, *z.shape)` containing the values of the Bessel\n    function of orders 0, 1, ..., v. The return type matches the type of `z`.\n\n  Raises:\n    TypeError if `v` is not integer.\n    ValueError if elements of array `z` are not float.\n  \"\"\"\n  z = jnp.asarray(z)\n  z, = promote_dtypes_inexact(z)\n  z_dtype = lax.dtype(z)\n  if dtypes.issubdtype(z_dtype, complex):\n    raise ValueError(\"complex input not supported.\")\n\n  v = core.concrete_or_error(operator.index, v, 'Argument v of bessel_jn.')\n  n_iter = core.concrete_or_error(int, n_iter, 'Argument n_iter of bessel_jn.')\n\n  bessel_jn_fun = partial(_bessel_jn, v=v, n_iter=n_iter)\n  for _ in range(z.ndim):\n    bessel_jn_fun = vmap(bessel_jn_fun)\n  return jnp.moveaxis(bessel_jn_fun(z), -1, 0)\n\n\ndef _gen_recurrence_mask(\n    l_max: int, is_normalized: bool, dtype: Any\n) -> tuple[Array, Array]:\n  \"\"\"Generates a mask for recurrence relation on the remaining entries.\n\n  The remaining entries are with respect to the diagonal and offdiagonal\n  entries.\n","sourceCodeStart":1907,"sourceCodeEnd":1943,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/special.py#L1907-L1943","documentation":"jax.scipy.special.bessel_jn(z, v, n_iter) computes Bessel functions of integer order via recurrence and only supports real float inputs; complex z raises ValueError. It also requires v and n_iter to be concrete (non-traced) values.","triggerScenarios":"Calling bessel_jn with complex z, e.g. bessel_jn(1+2j, v=2, n_iter=15); complex arrays coming from FFT-based optics/EM simulations.","commonSituations":"Physics/engineering code (wave propagation, cylindrical harmonics) where complex arguments J_v(z) are standard in SciPy but unsupported in JAX; passing complex128 fields from an FFT into bessel_jn.","solutions":["Split real/imaginary parts and handle separately — note J_v(complex) cannot be recovered from real/imag calls, so instead use jax.scipy.special functions that support complex or implement via series","Use real z: bessel_jn(jnp.real(z), ...) if imaginary parts are numerically zero","For true complex arguments, drop to mpmath/scipy outside the JAX graph"],"exampleFix":"// before\njax.scipy.special.bessel_jn(z, v=2, n_iter=15)  # z complex\n// after\njax.scipy.special.bessel_jn(jnp.real(z), v=2, n_iter=15)  # if imag(z)==0","handlingStrategy":"type-guard","validationCode":"z = jnp.asarray(z)\nif np.issubdtype(z.dtype, np.complexfloating):\n    raise ValueError('bessel_jn is real-only')","typeGuard":"def real_only(z):\n    return not np.issubdtype(jnp.dtype(z), np.complexfloating)","tryCatchPattern":null,"preventionTips":["Keep v and n_iter as concrete Python ints (not traced)","Handle complex Bessel arguments outside the JAX graph (mpmath/scipy)"],"tags":["jax","scipy-special","bessel","complex-dtype"],"backgroundTag":"unsupported-complex-input","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}