{"record":{"id":"c5f1d9428f92a1d2","repo":"jax-ml/jax","slug":"out-argument-of-self-name-reduce","errorCode":null,"errorMessage":"out argument of {self.__name__}.reduce()","messagePattern":"out argument of (.+?)\\.reduce\\(\\)","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/ufunc_api.py","lineNumber":247,"sourceCode":"      >>> jnp.logical_and.reduce(x > 2)\n      Array([False, False,  True], dtype=bool)\n      >>> jnp.all(x > 2, axis=0)\n      Array([False, False,  True], dtype=bool)\n\n      Some reductions do not correspond to any built-in aggregation function;\n      for example here is the reduction of :func:`jax.numpy.bitwise_or` along\n      the first axis of ``x``:\n\n      >>> jnp.bitwise_or.reduce(x, axis=1)\n      Array([3, 7], dtype=int32)\n    \"\"\"\n    check_arraylike(f\"{self.__name__}.reduce\", a)\n    if self.nin != 2:\n      raise ValueError(\"reduce only supported for binary ufuncs\")\n    if self.nout != 1:\n      raise ValueError(\"reduce only supported for functions returning a single value\")\n    if out is not None:\n      raise NotImplementedError(f\"out argument of {self.__name__}.reduce()\")\n    if initial is not None:\n      check_arraylike(f\"{self.__name__}.reduce\", initial)\n    if where is not None:\n      check_arraylike(f\"{self.__name__}.reduce\", where)\n      if self.identity is None and initial is None:\n        raise ValueError(f\"reduction operation {self.__name__!r} does not have an identity, \"\n                         \"so to use a where mask one has to specify 'initial'.\")\n      if lax._dtype(where) != bool:\n        raise ValueError(f\"where argument must have dtype=bool; got dtype={lax._dtype(where)}\")\n    reduce = self.__static_props['reduce'] or self._reduce_via_scan\n    return reduce(a, axis=axis, dtype=dtype, keepdims=keepdims, initial=initial, where=where)\n\n  def _reduce_via_scan(self, arr: ArrayLike, axis: int | tuple[int, ...] | None = 0, dtype: DTypeLike | None = None,\n                       keepdims: bool = False, initial: ArrayLike | None = None,\n                       where: ArrayLike | None = None) -> Array:\n    assert self.nin == 2 and self.nout == 1\n    arr = lax.asarray(arr)\n    if initial is None:","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/ufunc_api.py#L229-L265","documentation":"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.","triggerScenarios":"jnp.add.reduce(x, axis=0, out=buf).","commonSituations":"Numpy code ported to JAX that used out= in reductions to save allocations.","solutions":["Remove out= and use the returned array","Pre-allocate nothing; rely on XLA buffer donation under jit for memory reuse"],"exampleFix":"// before\njnp.add.reduce(x, out=total)\n// after\ntotal = jnp.add.reduce(x)","handlingStrategy":"type-guard","validationCode":"assert out is None, 'ufunc.reduce does not support out='","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remove out= from reductions when porting numpy"],"tags":["jax","ufunc","reduce","immutable-arrays"],"backgroundTag":"unsupported-out-parameter","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}