{"record":{"id":"78add0c69d829172","repo":"jax-ml/jax","slug":"all-objects-to-concatenate-must-be-arrays-got","errorCode":null,"errorMessage":"All objects to concatenate must be arrays, got {}.","messagePattern":"All objects to concatenate must be arrays, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":7235,"sourceCode":"          select(bitwise_and(gt(min, operand), lt(min, max)),\n                 g, _zeros(operand)),\n          lambda g, min, operand, max:\n          select(bitwise_and(gt(operand, min), lt(operand, max)),\n                 g, _zeros(operand)),\n          lambda g, min, operand, max:\n          select(lt(max, operand), g, _zeros(operand)))\nbatching.primitive_batchers[clamp_p] = _clamp_batch_rule\nmlir.register_lowering(clamp_p, partial(_nary_lower_hlo, hlo.clamp))\n\ndef _concatenate_shape_rule(*operands, **kwargs):\n  dimension = kwargs.pop('dimension')\n  if not operands:\n    msg = \"concatenate expects at least one operand, got 0.\"\n    raise TypeError(msg)\n  if not all(isinstance(operand, ShapedArray) for operand in operands):\n    msg = \"All objects to concatenate must be arrays, got {}.\"\n    op = next(op for op in operands if not isinstance(op, ShapedArray))\n    raise TypeError(msg.format(type(op)))\n  if len({operand.ndim for operand in operands}) != 1:\n    msg = \"Cannot concatenate arrays with different numbers of dimensions: got {}.\"\n    raise TypeError(msg.format(\", \".join(str(o.shape) for o in operands)))\n  if not 0 <= dimension < operands[0].ndim:\n    msg = \"concatenate dimension out of bounds: dimension {} for shapes {}.\"\n    raise TypeError(msg.format(dimension, \", \".join([str(o.shape) for o in operands])))\n  shapes = [operand.shape[:dimension] + operand.shape[dimension+1:]\n            for operand in operands]\n  if shapes[:-1] != shapes[1:]:\n    msg = (\"Cannot concatenate arrays with shapes that differ in dimensions \"\n           \"other than the one being concatenated: concatenating along \"\n           \"dimension {} for shapes {}.\")\n    shapes = [operand.shape for operand in operands]\n    raise TypeError(msg.format(dimension, \", \".join(map(str, shapes))))\n\n  concat_size = sum(o.shape[dimension] for o in operands)\n  ex_shape = operands[0].shape\n  return ex_shape[:dimension] + (concat_size,) + ex_shape[dimension+1:]","sourceCodeStart":7217,"sourceCodeEnd":7253,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L7217-L7253","documentation":"JAX's concatenate shape rule requires every operand to be a ShapedArray; passing a tracer, a Python scalar/list, None, or an opaque object triggers this TypeError naming the offending type. It guards the abstract-evaluation stage before lowering to XLA.","triggerScenarios":"jnp.concatenate([x, None]), mixing a Python list into the operand list, passing a pytree node or a dict value instead of a traced array.","commonSituations":"Unpacking tuples/pytrees where one element isn't an array; passing model config objects or None defaults into a concat call; list-of-lists data not converted via jnp.asarray.","solutions":["Convert non-array operands with jnp.asarray before concatenating","Inspect the reported type to find which element of the operand list is not a JAX array","Flatten pytrees with jax.tree_util and filter/convert leaves explicitly"],"exampleFix":"// before\nout = jnp.concatenate([x, maybe_none], axis=0)\n// after\narrays = [jnp.asarray(a) for a in [x, maybe_none] if a is not None]\nout = jnp.concatenate(arrays, axis=0)","handlingStrategy":"type-guard","validationCode":"arrays = [jnp.asarray(a) for a in operands if a is not None]","typeGuard":"import jax.numpy as jnp\n\ndef all_arrays(xs) -> bool:\n    return all(isinstance(x, jnp.ndarray) or hasattr(x, '__jax_array__') for x in xs)","tryCatchPattern":"try:\n    out = jnp.concatenate(arrays, axis=0)\nexcept TypeError as e:\n    if 'must be arrays' in str(e):\n        arrays = [jnp.asarray(a) for a in arrays]\n        out = jnp.concatenate(arrays, axis=0)\n    else:\n        raise","preventionTips":["Convert inputs with jnp.asarray at API boundaries","Filter None/missing values out of operand lists before array ops"],"tags":["jax","concatenate","type-validation","dtype"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}