jax-ml/jax · error · ValueError
Indices must not be empty
Error message
Indices must not be empty
What it means
Public wrapper store_scatter rejects an empty indices sequence — scatter with no indices is meaningless and would make the indexed shape ambiguous.
Source
Thrown at jax/_src/pallas/mosaic/sc_primitives.py:396
ref: Ref,
indices: Sequence[jax.Array],
x: jax.Array,
*,
mask: jax.Array | None = None,
) -> None:
"""Scatters an array to a ref.
Args:
ref: The ref in ``VMEM`` to scatter to.
indices: A sequence of 1D arrays, one for each dimension of ``ref``. Each
array specifies an index for that dimension. All arrays must have the same
size.
x: The array to store.
mask: An optional boolean array, which specifies which elements to store. If
``None``, all elements are stored.
"""
if not indices:
raise ValueError("Indices must not be empty")
ref, transforms = state_primitives.get_ref_and_transforms(
ref, None, "store_scatter"
)
flat_args, tree = jax.tree.flatten((ref, transforms, indices, x, mask))
_ = scatter_p.bind(*flat_args, tree=tree, add=False)
return None
def addupdate_scatter(
ref: Ref,
indices: Sequence[jax.Array],
x: jax.Array,
*,
mask: jax.Array | None = None,
) -> None:
"""Scatters an array to a ref, atomically adding to existing values.
Args:View on GitHub (pinned to 1e1c6a8fc0)
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
Example fix
// before sc_primitives.store_scatter(ref, [], x) // after if not indices: ref[...] = x # or skip else: sc_primitives.store_scatter(ref, indices, x)
Defensive patterns
Strategy: validation
Validate before calling
if not indices:
ref[...] = x # or skip
else:
store_scatter(ref, indices, x) Type guard
def has_indices(indices) -> bool:
return len(indices) > 0 Prevention
- 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
When it happens
Trigger: 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).
Common situations: Loop-generated index lists that end up empty for a block; confusing mask=None (store all) with indices=[] (store none).
Related errors
- {x.shape=} does not match expected shape {expected_shape}
- val.dtype={x.dtype} != ref.dtype={ref.dtype}
- {mask.shape=} does not match expected shape {expected_shape}
- Scatter only supports VectorSubcoreMesh, got {type(ref_aval.
- Scatter only supports storing to VMEM, got {memory_space}
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/f5472551261f4333.
Report an issue: GitHub.