{"record":{"id":"90be4dacd68a52cb","repo":"jax-ml/jax","slug":"unsupported-input-type-to-jax-numpy-i0-x-arr-dty","errorCode":null,"errorMessage":"Unsupported input type to jax.numpy.i0: {x_arr.dtype}","messagePattern":"Unsupported input type to jax\\.numpy\\.i0: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":6144,"sourceCode":"    An array containing the corresponding values of the modified Bessel function\n    of ``x``.\n\n  See also:\n    - :func:`jax.scipy.special.i0`: Calculates the modified Bessel function of\n      zeroth order.\n    - :func:`jax.scipy.special.i1`: Calculates the modified Bessel function of\n      first order.\n    - :func:`jax.scipy.special.i0e`: Calculates the exponentially scaled modified\n      Bessel function of zeroth order.\n\n  Examples:\n    >>> x = jnp.array([-2, -1, 0, 1, 2])\n    >>> jnp.i0(x)\n    Array([2.2795851, 1.266066 , 1.0000001, 1.266066 , 2.2795851], dtype=float32)\n  \"\"\"\n  x_arr, = util.promote_args_inexact(\"i0\", x)\n  if not issubdtype(x_arr.dtype, np.floating):\n    raise ValueError(f\"Unsupported input type to jax.numpy.i0: {x_arr.dtype}\")\n  return _i0(x_arr)\n\n\n@custom_jvp\ndef _i0(x):\n  abs_x = lax.abs(x)\n  return lax.mul(lax.exp(abs_x), lax_special.bessel_i0e(abs_x))\n\n@_i0.defjvp\ndef _i0_jvp(primals, tangents):\n  primal_out, tangent_out = api.jvp(_i0.fun, primals, tangents)\n  return primal_out, where(primals[0] == 0, 0.0, tangent_out)\n\n@export\ndef ix_(*args: ArrayLike) -> tuple[Array, ...]:\n  \"\"\"Return a multi-dimensional grid (open mesh) from N one-dimensional sequences.\n\n  JAX implementation of :func:`numpy.ix_`.","sourceCodeStart":6126,"sourceCodeEnd":6162,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L6126-L6162","documentation":"jnp.i0 (modified Bessel function of the first kind, order 0) only accepts floating-point dtypes. After promote_args_inexact promotes the input, a non-floating dtype (e.g. integer, complex, or bool that survives promotion) raises this ValueError naming the dtype.","triggerScenarios":"jnp.i0(5) or jnp.i0(jnp.array([1, 2])) with integer dtype, or complex input (promotion to complex128 is not np.floating). Note ints normally promote to float via promote_args_inexact, so complex inputs are the typical trigger.","commonSituations":"Porting scipy.special.i0 usage on complex-valued signals; passing integer constants from configuration; dtype-aware pipelines where x was cast to int for indexing and reused.","solutions":["Cast to float first: jnp.i0(x.astype(jnp.float64)) or pass float literals","For complex inputs, apply i0 to real/imag parts separately or use an implementation supporting complex (scipy on the host)","Verify dtype before the call: assert jnp.issubdtype(x.dtype, jnp.floating)"],"exampleFix":"// before\ny = jnp.i0(jnp.array([1, 2]))         # int32\n// after\ny = jnp.i0(jnp.array([1.0, 2.0]))    # float32","handlingStrategy":"type-guard","validationCode":"x = jnp.asarray(x, dtype=jnp.promote_types(jnp.asarray(x).dtype, jnp.float32)) if not jnp.issubdtype(jnp.asarray(x).dtype, jnp.floating) else x\ny = jnp.i0(x)","typeGuard":"def is_float_array(x) -> bool:\n    return jnp.issubdtype(jnp.asarray(x).dtype, jnp.floating)","tryCatchPattern":null,"preventionTips":["Cast to float before i0; complex is not supported","Wrap i0 in a helper that enforces float dtype once"],"tags":["jax","i0","bessel","dtype","complex"],"backgroundTag":"array-dtype-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}