{"record":{"id":"45ab98e528423f68","repo":"jax-ml/jax","slug":"can-only-concatenate-1d-vectors","errorCode":null,"errorMessage":"Can only concatenate 1D vectors","messagePattern":"Can only concatenate 1D vectors","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/utils.py","lineNumber":2137,"sourceCode":"  )\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:\n    case [v]:\n      return v\n    case [v, w]:\n      [v_len] = ir.VectorType(v.type).shape\n      [w_len] = ir.VectorType(w.type).shape\n      mask = ir.DenseI64ArrayAttr.get(list(range(v_len + w_len)))\n      return vector.shuffle(*vectors, mask=mask)\n    case _:\n      assert vectors\n      l = _vector_concat_rec(vectors[: len(vectors) // 2])\n      r = _vector_concat_rec(vectors[len(vectors) // 2 :])","sourceCodeStart":2119,"sourceCodeEnd":2155,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/utils.py#L2119-L2155","documentation":"Beyond the first element, vector_concat also verifies each operand is itself rank-1; a later operand of rank>=2 raises this ValueError (note: a ValueError, unlike the NotImplementedError used for the first operand).","triggerScenarios":"Calling vector_concat where vectors[0] is 1D but a subsequent element is e.g. vector<2x4xf32>.","commonSituations":"Heterogeneous fragment lists where one producer changed shape; appending a reshaped tile to a list of flat vectors.","solutions":["Flatten every operand to rank-1 before concatenating (vector.shape_cast)","Validate all operands in a loop: assert ir.VectorType(v.type).rank == 1","Fix the producer emitting the multi-dimensional vector"],"exampleFix":"# before\nv = vector_concat([flat_a, tile_2d])\n# after\nflat_tile = vector.shape_cast(ir.VectorType.get((tile_2d.type.num_elements,), tile_2d.type.element_type), tile_2d)\nv = vector_concat([flat_a, flat_tile])","handlingStrategy":"validation","validationCode":"assert all(ir.VectorType(v.type).rank == 1 for v in vectors), 'all operands must be 1D'","typeGuard":"def all_rank1(vals) -> bool:\n    return all(isinstance(v.type, ir.VectorType) and ir.VectorType(v.type).rank == 1 for v in vals)","tryCatchPattern":null,"preventionTips":["Validate every operand, not just the first","shape_cast any multi-dim fragment before appending"],"tags":["mosaic-gpu","vector-concat","rank"],"backgroundTag":"unsupported-vector-rank","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}