{"record":{"id":"f79631912fc1a5d2","repo":"jax-ml/jax","slug":"reduce-only-supported-for-functions-returning-a-si","errorCode":null,"errorMessage":"reduce only supported for functions returning a single value","messagePattern":"reduce only supported for functions returning a single value","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/ufunc_api.py","lineNumber":245,"sourceCode":"      :func:`jax.numpy.all`:\n\n      >>> 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","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/ufunc_api.py#L227-L263","documentation":"ufunc.reduce requires the ufunc to return a single output (nout == 1). Some numpy ufuncs return multiple values, and reducing those is undefined, so JAX raises this ValueError.","triggerScenarios":"Calling .reduce on a ufunc whose nout != 1 (multi-output ufuncs, e.g. divmod-style ops registered as ufuncs).","commonSituations":"Rare; typically metaprogramming that iterates over the ufunc registry and blindly calls .reduce.","solutions":["Check ufunc.nout == 1 before calling .reduce","Reduce over the specific single-output component you need instead"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert ufunc.nout == 1","typeGuard":"def is_single_output_ufunc(u): return u.nout == 1","tryCatchPattern":null,"preventionTips":["Inspect nin/nout metadata before dynamically dispatching reduce"],"tags":["jax","ufunc","reduce","api-misuse"],"backgroundTag":"unsupported-reduce-operation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}