{"record":{"id":"c12469ce63af634c","repo":"jax-ml/jax","slug":"cannot-concatenate-non-vector-values","errorCode":null,"errorMessage":"Cannot concatenate non-vector values","messagePattern":"Cannot concatenate non-vector values","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/utils.py","lineNumber":2129,"sourceCode":"  [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:\n    case [v]:\n      return v\n    case [v, w]:","sourceCodeStart":2111,"sourceCodeEnd":2147,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/utils.py#L2111-L2147","documentation":"vector_concat only concatenates ir.VectorType values. If vectors[0].type is a scalar (or any non-vector type) the helper cannot determine element type/shape semantics and raises ValueError.","triggerScenarios":"Calling vector_concat where the first element is a scalar i32/f32, a memref value, or a tensor — e.g. accidentally passing extracted scalars instead of vector<1xT> values.","commonSituations":"Refactoring that replaced broadcast/scalar insert with raw scalars; passing results of extractelement (scalars) where extract_subvector outputs were expected.","solutions":["Wrap scalars as vector<1xT> with vector.broadcast before concatenating","Verify each element's .type is ir.VectorType before the call","Trace where the list was built and fix producers to emit vectors"],"exampleFix":"# before\nv = vector_concat([a_scalar, b_scalar])\n# after\none = ir.VectorType.get((1,), a_scalar.type)\nv = vector_concat([vector.broadcast(one, a_scalar), vector.broadcast(one, b_scalar)])","handlingStrategy":"type-guard","validationCode":"assert isinstance(vectors[0].type, ir.VectorType), 'vector_concat needs vectors'","typeGuard":"def all_vectors(vals) -> bool:\n    return all(isinstance(v.type, ir.VectorType) for v in vals)","tryCatchPattern":null,"preventionTips":["Broadcast scalars to vector<1xT> before concatenating","Type-check fragment lists at construction"],"tags":["mosaic-gpu","vector-concat","type-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}