{"record":{"id":"32890a2c83d3b020","repo":"jax-ml/jax","slug":"jnp-interp-complex-x-values-not-supported","errorCode":null,"errorMessage":"jnp.interp: complex x values not supported.","messagePattern":"jnp\\.interp: complex x values not supported\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":2622,"sourceCode":"  del x, xp, fp\n\n  if isinstance(left, str):\n    if left != 'extrapolate':\n      raise ValueError(\"the only valid string value of `left` is \"\n                       f\"'extrapolate', but got: {left!r}\")\n    extrapolate_left = True\n  else:\n    extrapolate_left = False\n  if isinstance(right, str):\n    if right != 'extrapolate':\n      raise ValueError(\"the only valid string value of `right` is \"\n                       f\"'extrapolate', but got: {right!r}\")\n    extrapolate_right = True\n  else:\n    extrapolate_right = False\n\n  if dtypes.issubdtype(x_arr.dtype, np.complexfloating):\n    raise ValueError(\"jnp.interp: complex x values not supported.\")\n\n  if period is not None:\n    if np.ndim(period) != 0:\n      raise ValueError(f\"period must be a scalar; got {period}\")\n    period = ufuncs.abs(period)\n    x_arr = x_arr % period\n    xp_arr = xp_arr % period\n    xp_arr, fp_arr = lax.sort_key_val(xp_arr, fp_arr)\n    xp_arr = concatenate([xp_arr[-1:] - period, xp_arr, xp_arr[:1] + period])\n    fp_arr = concatenate([fp_arr[-1:], fp_arr, fp_arr[:1]])\n\n  i = clip(searchsorted(xp_arr, x_arr, side='right'), 1, len(xp_arr) - 1)\n  df = fp_arr[i] - fp_arr[i - 1]\n  dx = xp_arr[i] - xp_arr[i - 1]\n  delta = x_arr - xp_arr[i - 1]\n\n  epsilon = np.spacing(np.finfo(xp_arr.dtype).eps)\n  dx0 = lax.abs(dx) <= epsilon  # Prevent NaN gradients when `dx` is small.","sourceCodeStart":2604,"sourceCodeEnd":2640,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L2604-L2640","documentation":"jnp.interp does not support complex interpolation points (x); the underlying sort and search must operate on real values. Only real-valued x arrays are accepted.","triggerScenarios":"Calling jnp.interp on x with complex dtype, e.g. jnp.interp(jnp.array([1+2j]), xp, fp), including complex inputs that arise from promotion with complex xp/fp via promote_dtypes_inexact.","commonSituations":"Signal-processing pipelines where x is derived from FFT output or complex-valued features; dtype accidentally promoted to complex by another operand.","solutions":["Take the real part: jnp.interp(jnp.real(x), xp, fp)","Cast x to real: x.astype(jnp.float32) before calling","Trace upstream dtype promotion making x complex"],"exampleFix":"// before\njnp.interp(z, xp, fp)  # z is complex\n// after\njnp.interp(jnp.real(z), xp, fp)","handlingStrategy":"validation","validationCode":"if jnp.iscomplexobj(x):\n    x = jnp.real(x)","typeGuard":"def is_real_array(a) -> bool:\n    return not jnp.iscomplexobj(a)","tryCatchPattern":null,"preventionTips":["Check jnp.iscomplexobj before interpolation","Watch dtype promotion: complex xp or fp can also make x complex"],"tags":["jax","interp","complex-dtype","unsupported-operation"],"backgroundTag":"unsupported-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}