{"record":{"id":"447e9cef59791982","repo":"jax-ml/jax","slug":"index-arguments-to-dynamic-update-slice-must-be-in","errorCode":null,"errorMessage":"index arguments to dynamic_update_slice must be integers of the same type, got {}","messagePattern":"index arguments to dynamic_update_slice must be integers of the same type, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/slicing.py","lineNumber":1697,"sourceCode":"  if core.getr(operand) != core.getr(update):\n    raise core.ShardingTypeError(\n        \"dynamic_update_slice operand and update must be reduced along the\"\n        \" same axes. Got operand sharding\"\n        f\" {operand.str_short(mesh_axis_types=True)} and update sharding\"\n        f\" {update.str_short(mesh_axis_types=True)}.\")\n  return core.getr(operand)\n\ndef _dynamic_update_slice_ur_rule(operand, update, *start_indices):\n  out_u, kind = _dus_unreduced_rule(operand, update)\n  return out_u, _dus_reduced_rule(operand, update), kind\n\ndef _dynamic_update_slice_dtype_rule(operand, update, *start_indices):\n  lax.check_same_dtypes(\"dynamic_update_slice\", operand, update)\n  if any(i.dtype != start_indices[0].dtype or\n         not dtypes.issubdtype(i.dtype, np.integer) for i in start_indices):\n    msg = (\"index arguments to dynamic_update_slice must be integers of the \"\n           \"same type, got {}\")\n    raise TypeError(msg.format(\", \".join(i.dtype.name for i in start_indices)))\n  return operand.dtype\n\ndef _dynamic_update_slice_jvp(primals, tangents):\n  operand, update = primals[:2]\n  start_indices = primals[2:]\n  g_operand, g_update = tangents[:2]\n  val_out = dynamic_update_slice_p.bind(operand, update, *start_indices)\n  if type(g_operand) is ad_util.Zero and type(g_update) is ad_util.Zero:\n    tangent_out = ad_util.p2tz(val_out)\n  else:\n    g_operand = ad.instantiate_zeros(g_operand)\n    g_update = ad.instantiate_zeros(g_update)\n    tangent_out = dynamic_update_slice_p.bind(g_operand, g_update, *start_indices)\n  return val_out, tangent_out\n\ndef _dynamic_update_slice_transpose_rule(t, operand, update, *start_indices):\n  assert all(not ad.is_undefined_primal(x) for x in start_indices)\n  if type(t) is ad_util.Zero:","sourceCodeStart":1679,"sourceCodeEnd":1715,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/slicing.py#L1679-L1715","documentation":"The dtype rule of dynamic_update_slice requires every start-index argument to be an integer dtype and all of them to share the same dtype (e.g. all int32). Passing mixed dtypes (int32 and int64) or float indices raises this TypeError. This mirrors XLA's requirement that all index arguments have a uniform integer type.","triggerScenarios":"Calling lax.dynamic_update_slice with start indices of mixed integer widths (one np.int32, one np.int64), or with float values like 0.5 or jnp.float32 positions.","commonSituations":"On platforms (Windows/older numpy) where the default int is int32 while loop counters or jnp.arange defaults produce int64; combining Python ints with numpy index arrays; passing positions computed in float (e.g. from an interpolation step) without casting.","solutions":["Cast all indices to one integer type before the call: start = tuple(jnp.asarray(i, dtype=jnp.int32) for i in starts).","If indices come from float math, round and cast explicitly: jnp.floor(pos).astype(jnp.int32).","Standardize on one index dtype project-wide (usually int32) to avoid mixed-width args."],"exampleFix":"# before\nstarts = (np.int64(2), np.int32(0))\nout = lax.dynamic_update_slice(buf, upd, *starts)  # TypeError\n\n# after\nstarts = tuple(int(i) for i in starts)\nout = lax.dynamic_update_slice(buf, upd, *starts)","handlingStrategy":"validation","validationCode":"idx_dtype = jnp.int32\nstarts = tuple(jnp.asarray(i, dtype=idx_dtype) for i in starts)\nout = lax.dynamic_update_slice(operand, update, *starts)","typeGuard":null,"tryCatchPattern":"try:\n    out = lax.dynamic_update_slice(operand, update, *starts)\nexcept TypeError as e:\n    if 'same type' in str(e):\n        starts = tuple(jnp.asarray(i, dtype=jnp.int32) for i in starts)\n        out = lax.dynamic_update_slice(operand, update, *starts)\n    else:\n        raise","preventionTips":["Pick one index dtype (int32) and cast all indices to it at the boundary of your module.","Avoid mixing numpy int64 counters with jnp int32 indices; convert loop variables explicitly."],"tags":["jax","lax","dtype","indices"],"backgroundTag":"dtype-mismatch-indices","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}