{"record":{"id":"763a28d80a994966","repo":"jax-ml/jax","slug":"static-slice-indices-must-be-static-scalars-or-sl","errorCode":null,"errorMessage":"static_slice: indices must be static scalars or slices. Got index of type {type(pidx.index)} at position {position}","messagePattern":"static_slice: indices must be static scalars or slices\\. Got index of type (.+?) at position (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":403,"sourceCode":"        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}\")\n      else:\n        raise TypeError(f\"static_slice: unrecognized index {pidx.index} at position {position}.\")\n\n    # Now re-iterate to generate static slices.\n    start_indices: list[int] = []\n    limit_indices: list[int] = []\n    strides: list[int] = []\n    rev_axes: list[int] = []\n    squeeze_axes: list[int] = []\n    newaxis_dims: list[int] = []\n\n    expanded = self.expand_ellipses()\n    for pidx in expanded.indices:\n      if pidx.typ in [IndexType.ARRAY, IndexType.BOOLEAN, IndexType.ELLIPSIS]:\n        raise RuntimeError(f\"Internal: unexpected index encountered: {pidx}\")\n      elif pidx.typ == IndexType.NONE:\n        # Expanded axes indices are based on the rank of the array after slicing","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L385-L421","documentation":"to_static_slice requires every index to be a static scalar, slice, ellipsis, or None. If any index was classified as ARRAY, BOOLEAN, or DYNAMIC_SLICE (e.g. an integer array, boolean mask, or jax.ds marker), it raises TypeError naming the position and underlying type.","triggerScenarios":"Calling the static-slice path with advanced indices, e.g. x[np.array([0,2])] or x[mask] routed into to_static_slice (typically via internal dispatch with mode='slice' or unique_indices settings).","commonSituations":"Downstream libraries or user code forcing the static-slice lowering while still using advanced indexing; mixing gather-style indices with slice lowering config.","solutions":["Use plain int/slice indices when the static-slice path is requested","Let the default gather path handle array/boolean indices (don't force mode='slice')","Split the expression: slice statically, then advanced-index the result"],"exampleFix":"// before\ny = x[np.array([0, 2])]  # routed to static_slice\n// after\ny = x[np.array([0, 2])]  # via default gather: drop mode='slice' configuration\n# or\ny = x[0:3:2]","handlingStrategy":"validation","validationCode":"assert all(i is None or i is Ellipsis or isinstance(i, (int, np.integer, slice)) for i in idx_tuple)","typeGuard":"def is_static_index(idx) -> bool:\n    return isinstance(idx, (int, np.integer, slice, type(None), type(Ellipsis)))","tryCatchPattern":null,"preventionTips":["Don't force the static-slice lowering with array/boolean indices","Separate static slicing from advanced indexing steps"],"tags":["jax","static-slice","advanced-indexing"],"backgroundTag":"invalid-index-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}