{"record":{"id":"8701a86a4a19a285","repo":"jax-ml/jax","slug":"static-slice-requires-mode-promise-in-bounds-or","errorCode":null,"errorMessage":"static_slice requires mode='promise_in_bounds' or mode='clip'","messagePattern":"static_slice requires mode='promise_in_bounds' or mode='clip'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":386,"sourceCode":"  def to_static_slice(\n      self, *,\n      arr_is_sharded: bool = False,\n      normalize_indices: bool = True,\n      mode: str | slicing.GatherScatterMode | None) -> _StaticSliceIndexer:\n    \"\"\"Convert to StaticSliceIndexer data structure.\n\n    If this is not possible, raise a ValueError, TypeError, or IndexError.\n    \"\"\"\n    if mode is None:\n      parsed_mode = slicing.GatherScatterMode.PROMISE_IN_BOUNDS\n    else:\n      parsed_mode = slicing.GatherScatterMode.from_any(mode)\n    if any(core.is_symbolic_dim(s) for s in self.shape):\n      raise ValueError(\"mode='slice' is not valid for polymorphic shapes.\")\n\n    if parsed_mode not in [\n        slicing.GatherScatterMode.PROMISE_IN_BOUNDS, slicing.GatherScatterMode.CLIP]:\n      raise ValueError(\"static_slice requires mode='promise_in_bounds' or mode='clip'\")\n\n    # Validation of the unmodified user indices.\n    if parsed_mode == slicing.GatherScatterMode.PROMISE_IN_BOUNDS:\n      self.validate_static_indices(normalize_indices=normalize_indices)\n    self.validate_slices()\n\n    # For sharded inputs, indexing (like x[0]) and partial slices (like x[:2] as\n    # opposed to x[:]) lead to incorrect sharding semantics when computed via slice.\n    # TODO(yashkatariya): fix slice with sharding\n    if arr_is_sharded and self.has_partial_slices():\n      raise ValueError(\"static_slice with partial slices does not support nontrivial array sharding.\")\n\n    for position, pidx in enumerate(self.indices):\n      if pidx.typ in [IndexType.INTEGER, IndexType.ELLIPSIS, IndexType.SLICE, IndexType.NONE]:\n        pass\n      elif pidx.typ in [IndexType.ARRAY, IndexType.BOOLEAN, IndexType.DYNAMIC_SLICE]:\n        raise TypeError(\"static_slice: indices must be static scalars or slices.\"\n                        f\" Got index of type {type(pidx.index)} at position {position}\")","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L368-L404","documentation":"to_static_slice only supports the modes PROMISE_IN_BOUNDS and CLIP; other GatherScatterMode values (e.g. DROP or FILL with NaN/oob) cannot be expressed as a plain static slice, so a ValueError is raised.","triggerScenarios":"Calling the internal static-slice path (rewriting_take/to_static_slice) with mode='drop' or mode=('fill', value), e.g. via x[...] dispatch configured with unique_indices/indices_are_sorted/mode kwargs.","commonSituations":"Reusing a mode argument intended for jax.lax.gather/jnp.take (where 'fill'/'drop' are valid) in a context that lowers to a static slice.","solutions":["Drop the mode argument (default promise_in_bounds) when slicing with static indices","Use mode='clip' if out-of-range indices must be tolerated","Switch to jnp.take(x, idx, mode=...) which supports fill/drop semantics"],"exampleFix":"// before\ny = x[slice_indices]  # dispatch configured with mode='fill'\n// after\ny = jnp.take(x, slice_indices, mode='fill')","handlingStrategy":"validation","validationCode":"assert mode in (None, 'promise_in_bounds', 'clip')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reserve fill/drop modes for jnp.take/lax.gather","Default to no mode kwarg for slicing"],"tags":["jax","indexing","mode","api-misuse"],"backgroundTag":"invalid-mode-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}