{"record":{"id":"ddb83bf34099e218","repo":"jax-ml/jax","slug":"clip-received-a-complex-value-either-through-the-i","errorCode":null,"errorMessage":"Clip received a complex value either through the input or the min/max keywords. Complex values have no ordering and cannot be clipped. Please convert to a real value or array by taking the real or imaginary components via jax.numpy.real/imag respectively.","messagePattern":"Clip received a complex value either through the input or the min/max keywords\\. Complex values have no ordering and cannot be clipped\\. Please convert to a real value or array by taking the real or imaginary components via jax\\.numpy\\.real/imag respectively\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":3421,"sourceCode":"    An array containing values from ``arr``, with values smaller than ``min`` set\n    to ``min``, and values larger than ``max`` set to ``max``.\n    Wherever ``min`` is larger than ``max``, the value of ``max`` is returned.\n\n  See also:\n    - :func:`jax.numpy.minimum`: Compute the element-wise minimum value of two arrays.\n    - :func:`jax.numpy.maximum`: Compute the element-wise maximum value of two arrays.\n\n  Examples:\n    >>> arr = jnp.array([0, 1, 2, 3, 4, 5, 6, 7])\n    >>> jnp.clip(arr, 2, 5)\n    Array([2, 2, 2, 3, 4, 5, 5, 5], dtype=int32)\n  \"\"\"\n  if arr is None:\n    raise ValueError(\"No input was provided to the clip function.\")\n\n  util.check_arraylike(\"clip\", arr)\n  if any(iscomplexobj(t) for t in (arr, min, max)):\n    raise ValueError(\n      \"Clip received a complex value either through the input or the min/max \"\n      \"keywords. Complex values have no ordering and cannot be clipped. \"\n      \"Please convert to a real value or array by taking the real or \"\n      \"imaginary components via jax.numpy.real/imag respectively.\")\n  if min is not None:\n    arr = ufuncs.maximum(min, arr)\n  if max is not None:\n    arr = ufuncs.minimum(max, arr)\n  return asarray(arr)\n\n\n@export\n@api.jit(static_argnames=('decimals',))\ndef round(a: ArrayLike, decimals: int = 0, out: None = None) -> Array:\n  \"\"\"Round input evenly to the given number of decimals.\n\n  JAX implementation of :func:`numpy.round`.\n","sourceCodeStart":3403,"sourceCodeEnd":3439,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L3403-L3439","documentation":"Clipping requires an ordering, and complex numbers are not ordered. jnp.clip rejects complex input arrays or complex min/max bounds, suggesting real()/imag() extraction instead.","triggerScenarios":"jnp.clip(jnp.array([1+2j]), 0, 3), or clipping a real array with complex bounds like min=1j.","commonSituations":"Post-FFT magnitude pipelines accidentally clipping the complex spectrum instead of its magnitude; dtype promotion to complex from another operand; porting NumPy code where complex clip also fails but differently.","solutions":["Clip magnitudes: jnp.clip(jnp.abs(z), 0, 1)","Extract real/imag: jnp.clip(jnp.real(z), lo, hi)","Convert dtype to float where appropriate"],"exampleFix":"// before\njnp.clip(spectrum, 0, 10)  # spectrum is complex\n// after\njnp.clip(jnp.abs(spectrum), 0, 10)","handlingStrategy":"type-guard","validationCode":"if jnp.iscomplexobj(arr) or jnp.iscomplexobj(min) or jnp.iscomplexobj(max):\n    arr = jnp.real(arr)","typeGuard":"def is_clip_safe(*vals) -> bool:\n    return not any(jnp.iscomplexobj(v) for v in vals)","tryCatchPattern":null,"preventionTips":["Clip abs() for complex spectra","Add iscomplexobj checks in generic numeric helpers"],"tags":["jax","clip","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"}