{"record":{"id":"83652e5966e22aa0","repo":"jax-ml/jax","slug":"reduction-operation-self-name-r-does-not-hav","errorCode":null,"errorMessage":"reduction operation {self.__name__!r} does not have an identity, so to use a where mask one has to specify 'initial'.","messagePattern":"reduction operation (.+?) does not have an identity, so to use a where mask one has to specify 'initial'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/ufunc_api.py","lineNumber":253,"sourceCode":"      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:\n      initial = self.identity\n    if dtype is None:\n      dtype = api.eval_shape(self._func, lax._one(arr), lax._one(arr)).dtype\n    if where is not None:\n      where = _broadcast_to(where, arr.shape)\n    if isinstance(axis, tuple):","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/ufunc_api.py#L235-L271","documentation":"When reduce is called with a where mask, elements outside the mask are replaced by the operation's identity. If the ufunc has no identity (e.g. maximum over empty sets is undefined for some dtypes) and no initial value is given, the result is undefined, so JAX raises ValueError demanding an initial.","triggerScenarios":"jnp.maximum.reduce(x, where=mask) without initial for a ufunc whose identity is None.","commonSituations":"Masked reductions where all elements may be masked out; porting numpy where-masked reductions that relied on numpy's error semantics.","solutions":["Pass an explicit initial value, e.g. jnp.maximum.reduce(x, where=mask, initial=-jnp.inf)","If semantically valid, choose a ufunc that has an identity or compute the initial from your data's neutral element"],"exampleFix":"// before\njnp.maximum.reduce(x, where=mask)\n// after\njnp.maximum.reduce(x, where=mask, initial=-jnp.inf)","handlingStrategy":"validation","validationCode":"if where is not None and ufunc.identity is None and initial is None:\n    raise ValueError('must pass initial for masked reduce without identity')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass initial when using where= masks with maximum/minimum-style reductions"],"tags":["jax","ufunc","reduce","where-mask"],"backgroundTag":"masked-reduction-needs-initial","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}