{"record":{"id":"30c3a0f296254f88","repo":"jax-ml/jax","slug":"accumulate-only-supported-for-functions-returning","errorCode":null,"errorMessage":"accumulate only supported for functions returning a single value","messagePattern":"accumulate only supported for functions returning a single value","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/ufunc_api.py","lineNumber":374,"sourceCode":"      >>> jnp.multiply.accumulate(x, axis=1)\n      Array([[  1,   2,   6],\n             [  4,  20, 120]], dtype=int32)\n      >>> jnp.cumprod(x, axis=1)\n      Array([[  1,   2,   6],\n             [  4,  20, 120]], dtype=int32)\n\n      For other binary ufuncs, the accumulation is an operation not available\n      via standard APIs. For example, :meth:`jax.numpy.bitwise_or.accumulate`\n      is essentially a bitwise cumulative ``any``:\n\n      >>> jnp.bitwise_or.accumulate(x, axis=1)\n      Array([[1, 3, 3],\n             [4, 5, 7]], dtype=int32)\n    \"\"\"\n    if self.nin != 2:\n      raise ValueError(\"accumulate only supported for binary ufuncs\")\n    if self.nout != 1:\n      raise ValueError(\"accumulate only supported for functions returning a single value\")\n    if out is not None:\n      raise NotImplementedError(f\"out argument of {self.__name__}.accumulate()\")\n    accumulate = self.__static_props['accumulate'] or self._accumulate_via_scan\n    return accumulate(a, axis=axis, dtype=dtype)\n\n  def _accumulate_via_scan(self, arr: ArrayLike, axis: int = 0,\n                           dtype: DTypeLike | None = None) -> Array:\n    assert self.nin == 2 and self.nout == 1\n    check_arraylike(f\"{self.__name__}.accumulate\", arr)\n    arr = lax.asarray(arr)\n\n    if dtype is None:\n      dtype = api.eval_shape(self._func, lax._one(arr), lax._one(arr)).dtype\n\n    if axis is None or isinstance(axis, tuple):\n      raise ValueError(\"accumulate does not allow multiple axes\")\n    axis = canonicalize_axis(axis, np.ndim(arr))\n","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/ufunc_api.py#L356-L392","documentation":"ufunc.accumulate requires the ufunc to return exactly one output (nout == 1); accumulating a multi-output ufunc is undefined and raises this ValueError.","triggerScenarios":"Calling .accumulate on a multi-output ufunc (e.g. divmod-like ops).","commonSituations":"Metaprogramming over the ufunc registry; rare in direct use.","solutions":["Check ufunc.nout == 1 before calling .accumulate","Accumulate the single output component you need via an explicit scan"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert ufunc.nout == 1","typeGuard":"def is_single_output_ufunc(u): return u.nout == 1","tryCatchPattern":null,"preventionTips":["Check ufunc metadata before generic .accumulate dispatch"],"tags":["jax","ufunc","accumulate","api-misuse"],"backgroundTag":"unsupported-accumulate-operation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}