jax-ml/jax · error · ValueError
Need at least one array to concatenate
Error message
Need at least one array to concatenate
What it means
FragmentedArray.concatenate validates that at least one array is passed, mirroring numpy.concatenate semantics. An empty sequence has no shape, dtype, or layout to infer a result from, so the library raises ValueError immediately.
Source
Thrown at jax/experimental/mosaic/gpu/fragmented_array.py:5340
for i, dim in enumerate(src.shape):
if dim == 1 and dst.shape[dims[i]] > 1:
exp_indices.append(i)
if dim > 1:
pre_indices.append(i)
# If both exist, all expansions must happen before all preserved
# dimensions.
if exp_indices and pre_indices and max(exp_indices) >= min(pre_indices):
return False
return True
def concatenate(
arrays: Sequence[FragmentedArray],
axis: int = 0,
) -> FragmentedArray:
"""Concatenates fragmented arrays along the specified axis."""
if not arrays:
raise ValueError("Need at least one array to concatenate")
arr0 = arrays[0]
rank = len(arr0.shape)
if not -rank <= axis < rank:
raise ValueError(f"{axis=} is out of bounds for array of {rank=}")
if axis < 0:
axis += rank
if len(arrays) == 1:
return arr0
new_shape = list(arr0.shape)
for i, arr in enumerate(arrays[1:], start=1):
if len(arr.shape) != rank:
raise ValueError(
f"All arrays must have the same rank, got {len(arr.shape)} at index"
f" {i} (expected {rank})"
)
if arr.mlir_dtype != arr0.mlir_dtype:View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Guard the call: if not arrays: skip, return None, or construct a zero-length FragmentedArray explicitly.
- Fix the upstream logic so the list is guaranteed non-empty (e.g., default to a single empty array).
Example fix
# before
result = FragmentedArray.concatenate(parts, axis=0) # parts == []
# after
result = (
FragmentedArray.concatenate(parts, axis=0)
if parts else None
) Defensive patterns
Strategy: validation
Validate before calling
if not arrays:
return # or build an explicit zero-length fragment
result = FragmentedArray.concatenate(arrays, axis=axis) Try / catch
try:
out = FragmentedArray.concatenate(parts, axis=0)
except ValueError as e:
if 'at least one array' not in str(e): raise
out = None Prevention
- Treat empty parts lists as a no-op at the call site.
- Assert len(parts) > 0 in debug builds.
- Return early when accumulators are empty.
When it happens
Trigger: Calling FragmentedArray.concatenate([], axis=...) with an empty list/tuple, often because a list comprehension or accumulator produced zero arrays at runtime.
Common situations: Dynamic-length kernel pipelines where the number of arrays depends on runtime conditions (e.g., splitting work by number of tensor cores and getting 0); refactoring code that assumed a non-empty batch; passing an empty generator result.
Related errors
- need sequence of keys with len > 0 in lexsort
- dims and idxs must have the same length
- Swizzle {self.swizzle} is not supported. Only 32, 64 and 128
- cluster= must be at most 3D, got {self}.
- grid_names must have the same length as grid, got {self}.
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/06b04ff09426d196.
Report an issue: GitHub.