{"record":{"id":"4c4b728412c100eb","repo":"jax-ml/jax","slug":"cannot-concatenate-an-empty-list-of-vectors","errorCode":null,"errorMessage":"Cannot concatenate an empty list of vectors","messagePattern":"Cannot concatenate an empty list of vectors","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/utils.py","lineNumber":2126,"sourceCode":"  v_ty = ir.VectorType(v.type)\n  if len(v_ty.shape) != 1:\n    raise NotImplementedError(f\"Only 1D vectors are supported {v_ty}\")\n  [v_len] = v_ty.shape\n  slice_length = len(range(v_len)[s])\n  return vector.extract_strided_slice(\n      ir.VectorType.get((slice_length,), v_ty.element_type),\n      v,\n      [s.start or 0],\n      [slice_length],\n      [1],\n  )\n\n\ndef vector_concat(\n    vectors: Sequence[ir.Value[ir.VectorType]],\n) -> ir.Value[ir.VectorType]:\n  if not vectors:\n    raise ValueError(\"Cannot concatenate an empty list of vectors\")\n  vty = vectors[0].type\n  if not isinstance(vty, ir.VectorType):\n    raise ValueError(\"Cannot concatenate non-vector values\")\n  vty = ir.VectorType(vty)\n  if vty.rank != 1:\n    raise NotImplementedError(\"Only 1D vectors are supported\")\n  for v in vectors:\n    if v.type.element_type != vty.element_type:\n      raise ValueError(\"Cannot concatenate vectors of different element types\")\n    if v.type.rank != 1:\n      raise ValueError(\"Can only concatenate 1D vectors\")\n  return _vector_concat_rec(vectors)\n\n\ndef _vector_concat_rec(\n    vectors: Sequence[ir.Value[ir.VectorType]],\n) -> ir.Value[ir.VectorType]:\n  match vectors:","sourceCodeStart":2108,"sourceCodeEnd":2144,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/utils.py#L2108-L2144","documentation":"vector_concat builds a result by recursively concatenating, starting from vectors[0]; an empty sequence has no element type or length to anchor on, so it raises rather than returning an undefined value.","triggerScenarios":"Calling vector_concat([]) — usually because a list comprehension over blocks/fragments produced zero elements (empty range, empty tile list, filtered-out everything).","commonSituations":"Concatenating per-iteration partial vectors inside a loop whose trip count is 0 (e.g. zero-length sequence dimension); dynamic shapes producing empty fragments at runtime; off-by-one slice producing an empty list.","solutions":["Guard the call site: skip concatenation or return an undef/zero vector when the list is empty","Fix the loop/range producing the list so it yields at least one fragment","Pad the sequence dimension so fragment lists are never empty"],"exampleFix":"# before\nout = vector_concat(parts)  # parts == []\n# after\nout = vector_concat(parts) if parts else llvm.mlir_undef(ir.VectorType.get((0,), f32))","handlingStrategy":"validation","validationCode":"assert vectors, 'vector_concat received empty list'\nresult = vector_concat(vectors)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard loops producing fragment lists with `if parts:`","Debug empty trip counts before building vectors"],"tags":["mosaic-gpu","vector-concat","empty-input"],"backgroundTag":"empty-sequence","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}