jax-ml/jax · error · NotImplementedError

out argument of {self.__name__}.reduce()

Error message

out argument of {self.__name__}.reduce()

What it means

ufunc.reduce's out parameter is accepted for numpy API compatibility but unsupported because JAX arrays are immutable. A non-None out raises NotImplementedError naming the ufunc.

Source

Thrown at jax/_src/numpy/ufunc_api.py:247

      >>> jnp.logical_and.reduce(x > 2)
      Array([False, False,  True], dtype=bool)
      >>> jnp.all(x > 2, axis=0)
      Array([False, False,  True], dtype=bool)

      Some reductions do not correspond to any built-in aggregation function;
      for example here is the reduction of :func:`jax.numpy.bitwise_or` along
      the first axis of ``x``:

      >>> jnp.bitwise_or.reduce(x, axis=1)
      Array([3, 7], dtype=int32)
    """
    check_arraylike(f"{self.__name__}.reduce", a)
    if self.nin != 2:
      raise ValueError("reduce only supported for binary ufuncs")
    if self.nout != 1:
      raise ValueError("reduce only supported for functions returning a single value")
    if out is not None:
      raise NotImplementedError(f"out argument of {self.__name__}.reduce()")
    if initial is not None:
      check_arraylike(f"{self.__name__}.reduce", initial)
    if where is not None:
      check_arraylike(f"{self.__name__}.reduce", where)
      if self.identity is None and initial is None:
        raise ValueError(f"reduction operation {self.__name__!r} does not have an identity, "
                         "so to use a where mask one has to specify 'initial'.")
      if lax._dtype(where) != bool:
        raise ValueError(f"where argument must have dtype=bool; got dtype={lax._dtype(where)}")
    reduce = self.__static_props['reduce'] or self._reduce_via_scan
    return reduce(a, axis=axis, dtype=dtype, keepdims=keepdims, initial=initial, where=where)

  def _reduce_via_scan(self, arr: ArrayLike, axis: int | tuple[int, ...] | None = 0, dtype: DTypeLike | None = None,
                       keepdims: bool = False, initial: ArrayLike | None = None,
                       where: ArrayLike | None = None) -> Array:
    assert self.nin == 2 and self.nout == 1
    arr = lax.asarray(arr)
    if initial is None:

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Remove out= and use the returned array
  2. Pre-allocate nothing; rely on XLA buffer donation under jit for memory reuse

Example fix

// before
jnp.add.reduce(x, out=total)
// after
total = jnp.add.reduce(x)
Defensive patterns

Strategy: type-guard

Validate before calling

assert out is None, 'ufunc.reduce does not support out='

Prevention

When it happens

Trigger: jnp.add.reduce(x, axis=0, out=buf).

Common situations: Numpy code ported to JAX that used out= in reductions to save allocations.

Related errors


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