jax-ml/jax · error · ValueError

accumulate only supported for functions returning a single v

Error message

accumulate only supported for functions returning a single value

What it means

ufunc.accumulate requires the ufunc to return exactly one output (nout == 1); accumulating a multi-output ufunc is undefined and raises this ValueError.

Source

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

      >>> jnp.multiply.accumulate(x, axis=1)
      Array([[  1,   2,   6],
             [  4,  20, 120]], dtype=int32)
      >>> jnp.cumprod(x, axis=1)
      Array([[  1,   2,   6],
             [  4,  20, 120]], dtype=int32)

      For other binary ufuncs, the accumulation is an operation not available
      via standard APIs. For example, :meth:`jax.numpy.bitwise_or.accumulate`
      is essentially a bitwise cumulative ``any``:

      >>> jnp.bitwise_or.accumulate(x, axis=1)
      Array([[1, 3, 3],
             [4, 5, 7]], dtype=int32)
    """
    if self.nin != 2:
      raise ValueError("accumulate only supported for binary ufuncs")
    if self.nout != 1:
      raise ValueError("accumulate only supported for functions returning a single value")
    if out is not None:
      raise NotImplementedError(f"out argument of {self.__name__}.accumulate()")
    accumulate = self.__static_props['accumulate'] or self._accumulate_via_scan
    return accumulate(a, axis=axis, dtype=dtype)

  def _accumulate_via_scan(self, arr: ArrayLike, axis: int = 0,
                           dtype: DTypeLike | None = None) -> Array:
    assert self.nin == 2 and self.nout == 1
    check_arraylike(f"{self.__name__}.accumulate", arr)
    arr = lax.asarray(arr)

    if dtype is None:
      dtype = api.eval_shape(self._func, lax._one(arr), lax._one(arr)).dtype

    if axis is None or isinstance(axis, tuple):
      raise ValueError("accumulate does not allow multiple axes")
    axis = canonicalize_axis(axis, np.ndim(arr))

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Check ufunc.nout == 1 before calling .accumulate
  2. Accumulate the single output component you need via an explicit scan
Defensive patterns

Strategy: validation

Validate before calling

assert ufunc.nout == 1

Type guard

def is_single_output_ufunc(u): return u.nout == 1

Prevention

When it happens

Trigger: Calling .accumulate on a multi-output ufunc (e.g. divmod-like ops).

Common situations: Metaprogramming over the ufunc registry; rare in direct use.

Related errors


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