jax-ml/jax · error · ValueError

Clip received a complex value either through the input or th

Error message

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.

What it means

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.

Source

Thrown at jax/_src/numpy/lax_numpy.py:3421

    An array containing values from ``arr``, with values smaller than ``min`` set
    to ``min``, and values larger than ``max`` set to ``max``.
    Wherever ``min`` is larger than ``max``, the value of ``max`` is returned.

  See also:
    - :func:`jax.numpy.minimum`: Compute the element-wise minimum value of two arrays.
    - :func:`jax.numpy.maximum`: Compute the element-wise maximum value of two arrays.

  Examples:
    >>> arr = jnp.array([0, 1, 2, 3, 4, 5, 6, 7])
    >>> jnp.clip(arr, 2, 5)
    Array([2, 2, 2, 3, 4, 5, 5, 5], dtype=int32)
  """
  if arr is None:
    raise ValueError("No input was provided to the clip function.")

  util.check_arraylike("clip", arr)
  if any(iscomplexobj(t) for t in (arr, min, max)):
    raise ValueError(
      "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.")
  if min is not None:
    arr = ufuncs.maximum(min, arr)
  if max is not None:
    arr = ufuncs.minimum(max, arr)
  return asarray(arr)


@export
@api.jit(static_argnames=('decimals',))
def round(a: ArrayLike, decimals: int = 0, out: None = None) -> Array:
  """Round input evenly to the given number of decimals.

  JAX implementation of :func:`numpy.round`.

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Clip magnitudes: jnp.clip(jnp.abs(z), 0, 1)
  2. Extract real/imag: jnp.clip(jnp.real(z), lo, hi)
  3. Convert dtype to float where appropriate

Example fix

// before
jnp.clip(spectrum, 0, 10)  # spectrum is complex
// after
jnp.clip(jnp.abs(spectrum), 0, 10)
Defensive patterns

Strategy: type-guard

Validate before calling

if jnp.iscomplexobj(arr) or jnp.iscomplexobj(min) or jnp.iscomplexobj(max):
    arr = jnp.real(arr)

Type guard

def is_clip_safe(*vals) -> bool:
    return not any(jnp.iscomplexobj(v) for v in vals)

Prevention

When it happens

Trigger: jnp.clip(jnp.array([1+2j]), 0, 3), or clipping a real array with complex bounds like min=1j.

Common situations: 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.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/ddb83bf34099e218. Report an issue: GitHub.