{"record":{"id":"8da2bcac3098a280","repo":"jax-ml/jax","slug":"reps-length-must-be-equal-to-the-ndim-of-x-got-l","errorCode":null,"errorMessage":"reps length must be equal to the ndim of x, got {len(reps)=} and {x.ndim=}.","messagePattern":"reps length must be equal to the ndim of x, got (.+?) and (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":7123,"sourceCode":"      x_aval.sharding.mesh.abstract_mesh,\n      P(*tuple(s for d in x_aval.sharding.spec for s in [None, d])),\n  )\n  reshaped_aval = x_aval.update(shape=expand_shape, sharding=expand_sharding)\n  reshaped = mlir.reshape(ctx, x, reshaped_aval)\n  reshaped = mlir.lower_with_sharding_in_types(ctx, reshaped, reshaped_aval)\n  broadcast_shape = tuple(k for pair in zip(reps, x_aval.shape) for k in pair)\n  broadcasted_aval = x_aval.update(\n      shape=broadcast_shape, sharding=expand_sharding)\n  broadcasted = mlir.broadcast_in_dim(ctx, reshaped,\n      broadcasted_aval, broadcast_dimensions=tuple(range(2 * x_aval.ndim)))\n  broadcasted = mlir.lower_with_sharding_in_types(\n      ctx, broadcasted, broadcasted_aval)\n  out = mlir.reshape(ctx, broadcasted, aval_out)\n  return [mlir.lower_with_sharding_in_types(ctx, out, aval_out)]\n\ndef _tile_abstract_eval(x, reps):\n  if x.ndim != len(reps):\n    raise TypeError(\n        f\"reps length must be equal to the ndim of x, got {len(reps)=} \"\n        f\"and {x.ndim=}.\")\n  for i, (r, sh) in enumerate(zip(reps, x.sharding.spec)):\n    if r != 1 and sh is not None:\n      raise core.ShardingTypeError(\n          f'Operand cannot be sharded on dimension {i} when the tiling is'\n          f' non-trivial. Got input type: {x} with reps: {reps}')\n  return x.update(shape=tuple(np.multiply(x.shape, reps)))\n\ndef _tile_transpose_rule(ct, operand, *, reps):\n  if type(ct) is ad_util.Zero:\n    return [ad_util.Zero(operand.aval)]\n  if not isinstance(operand, ad.UndefinedPrimal):\n    return [None]  # transpose wrt literal\n  out_spec = tuple(s for sp in operand.aval.sharding.spec for s in [None, sp])\n  ct_reshaped = reshape(\n      ct, tuple(k for pair in zip(reps, operand.aval.shape) for k in pair),\n      out_sharding=operand.aval.sharding.update(spec=out_spec))","sourceCodeStart":7105,"sourceCodeEnd":7141,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L7105-L7141","documentation":"lax.tile requires the reps sequence to have exactly one entry per dimension of x. A mismatched length makes the tiling specification ambiguous and is rejected.","triggerScenarios":"Calling jax.lax.tile(x, reps) with len(reps) != x.ndim, e.g. tile(x_2d, [3]) or tile(x_1d, [2, 2]).","commonSituations":"Coming from np.tile habits where numpy broadcasts shorter reps (np.tile(x, 3) is fine but lax.tile requires full length); dynamically-rank operands under jit where x.ndim changed.","solutions":["Supply one rep per dimension: for a 2-D array pass a length-2 sequence","Prefer jnp.tile (which mirrors numpy semantics) if you want numpy-style broadcasting of reps","Derive reps from x.ndim at runtime under jit with static shapes"],"exampleFix":"// before\nx = jnp.zeros((4, 3))\ny = lax.tile(x, [2])            # wrong: needs 2 entries\n// after\ny = lax.tile(x, [2, 1])         # tile dim0 twice, dim1 once","handlingStrategy":"type-guard","validationCode":"reps = tuple(reps)\nif len(reps) < x.ndim: reps = (1,) * (x.ndim - len(reps)) + tuple(reps)\nassert len(reps) == x.ndim","typeGuard":"def tile_reps_valid(x, reps) -> bool:\n    return len(tuple(reps)) == x.ndim","tryCatchPattern":null,"preventionTips":["Use jnp.tile for numpy-like semantics","Always pass one rep per dim to lax.tile"],"tags":["jax","tile","shape-validation"],"backgroundTag":"invalid-tile-configuration","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}