{"record":{"id":"f5472551261f4333","repo":"jax-ml/jax","slug":"indices-must-not-be-empty","errorCode":null,"errorMessage":"Indices must not be empty","messagePattern":"Indices must not be empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/sc_primitives.py","lineNumber":396,"sourceCode":"    ref: Ref,\n    indices: Sequence[jax.Array],\n    x: jax.Array,\n    *,\n    mask: jax.Array | None = None,\n) -> None:\n  \"\"\"Scatters an array to a ref.\n\n  Args:\n    ref: The ref in ``VMEM`` to scatter to.\n    indices: A sequence of 1D arrays, one for each dimension of ``ref``. Each\n      array specifies an index for that dimension. All arrays must have the same\n      size.\n    x: The array to store.\n    mask: An optional boolean array, which specifies which elements to store. If\n      ``None``, all elements are stored.\n  \"\"\"\n  if not indices:\n    raise ValueError(\"Indices must not be empty\")\n  ref, transforms = state_primitives.get_ref_and_transforms(\n      ref, None, \"store_scatter\"\n  )\n  flat_args, tree = jax.tree.flatten((ref, transforms, indices, x, mask))\n  _ = scatter_p.bind(*flat_args, tree=tree, add=False)\n  return None\n\n\ndef addupdate_scatter(\n    ref: Ref,\n    indices: Sequence[jax.Array],\n    x: jax.Array,\n    *,\n    mask: jax.Array | None = None,\n) -> None:\n  \"\"\"Scatters an array to a ref, atomically adding to existing values.\n\n  Args:","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/sc_primitives.py#L378-L414","documentation":"Public wrapper store_scatter rejects an empty indices sequence — scatter with no indices is meaningless and would make the indexed shape ambiguous.","triggerScenarios":"Calling store_scatter(ref, [], x) or passing an indices list/tuple that is empty, e.g. built dynamically and accidentally empty (indices=[] instead of None).","commonSituations":"Loop-generated index lists that end up empty for a block; confusing mask=None (store all) with indices=[] (store none).","solutions":["Pass at least one index or index array; if you meant 'store everything', use a plain store instead of scatter","Guard the call: if not indices: use store or skip"],"exampleFix":"// before\nsc_primitives.store_scatter(ref, [], x)\n\n// after\nif not indices:\n  ref[...] = x  # or skip\nelse:\n  sc_primitives.store_scatter(ref, indices, x)","handlingStrategy":"validation","validationCode":"if not indices:\n    ref[...] = x  # or skip\nelse:\n    store_scatter(ref, indices, x)","typeGuard":"def has_indices(indices) -> bool:\n    return len(indices) > 0","tryCatchPattern":null,"preventionTips":["Treat empty indices as a no-op/full-store in kernel wrappers","Assert indices non-empty when it indicates a bug upstream","Log when dynamically-built index lists are empty"],"tags":["jax","pallas","sparsecore","scatter","empty-indices"],"backgroundTag":"empty-argument-validation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}