{"record":{"id":"07a968d6d41f1858","repo":"jax-ml/jax","slug":"in-arange-with-non-constant-arguments-all-of-start","errorCode":null,"errorMessage":"In arange with non-constant arguments all of start, stop, and step must be either dimension expressions or integers: start={start}, stop={stop}, step={step}","messagePattern":"In arange with non-constant arguments all of start, stop, and step must be either dimension expressions or integers: start=(.+?), stop=(.+?), step=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":6007,"sourceCode":"                lax.mul(lax.convert_element_type(step, working_dtype),\n                        lax.broadcasted_iota(working_dtype, (size,), 0,\n                                             out_sharding=out_sharding))),\n        dtype)\n  elif start == 0:\n    # arange(M) or arange(0, M)\n    size = max(0, int(np.ceil(stop)))\n    return lax.broadcasted_iota(dtype, (size,), 0, out_sharding=out_sharding)\n  else:\n    # arange(N, M)\n    size = max(0, int(np.ceil(stop - start)))\n    return lax.add(lax.convert_element_type(start, dtype),\n                    lax.broadcasted_iota(dtype, (size,), 0, out_sharding=out_sharding))\n\ndef _arange_dynamic(\n    start: DimSize, stop: DimSize, step: DimSize, dtype: DTypeLike) -> Array:\n  # Here if at least one of start, stop, step are dynamic.\n  if any(not core.is_dim(v) for v in (start, stop, step)):\n    raise ValueError(\n        \"In arange with non-constant arguments all of start, stop, and step \"\n        f\"must be either dimension expressions or integers: start={start}, \"\n        f\"stop={stop}, step={step}\")\n  # Must resolve statically if step is {<0, ==0, >0}\n  try:\n    if step == 0:\n      raise ValueError(\"arange has step == 0\")\n    step_gt_0 = (step > 0)\n  except core.InconclusiveDimensionOperation as e:\n    raise core.InconclusiveDimensionOperation(\n        f\"In arange with non-constant arguments the step ({step}) must \" +\n        f\"be resolved statically if it is > 0 or < 0.\\nDetails: {e}\")\n  gap = step if step_gt_0 else - step\n  distance = (stop - start) if step_gt_0 else (start - stop)\n  size = core.max_dim(0, distance + gap - 1) // gap\n  return (array(start, dtype=dtype) +\n          array(step, dtype=dtype) * lax.iota(dtype, size))\n","sourceCodeStart":5989,"sourceCodeEnd":6025,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L5989-L6025","documentation":"When jnp.arange falls back to the dynamic (non-constant argument) path, all of start, stop, and step must be either static integers or symbolic dimension expressions (polynomials over dimension variables). Mixing a dimension expression with a non-dimension value (e.g. a traced float) raises this ValueError.","triggerScenarios":"Calling jnp.arange with a symbolic dimension bound (from jax.export or shape polymorphism) mixed with a non-dim start/step, e.g. jnp.arange(n, step=0.5) where n is a symbolic dimension; or arange(dim, 2*dim, 0.1).","commonSituations":"Shape-polymorphic jax.jit/export code that iterates a range over a batch dimension with a float step; migrating dynamic-shape code where a tracer leaks into arange bounds.","solutions":["Keep all three arguments as integers/dimension expressions when any is symbolic: use step=1 (or int step)","Re-express float-step ranges via linspace on an integer range, or scale after: jnp.arange(n) * 0.1","Mark the bound static (e.g. pass a Python int) if the size is actually known"],"exampleFix":"// before\nxs = jnp.arange(n, step=0.5)  # n symbolic dim\n// after\nxs = jnp.arange(n) * 0.5","handlingStrategy":"validation","validationCode":"from jax._src import core\nif any(core.is_symbolic_dim(v) for v in (start, stop, step)):\n    assert all(core.is_dim(v) for v in (start, stop, step)), 'mixed symbolic/non-symbolic arange args'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep integer steps (ideally 1) in shape-polymorphic arange","Scale to floats after generating an integer range"],"tags":["jax","arange","symbolic-dim","shape-polymorphism","valueerror"],"backgroundTag":"symbolic-dimension-constraint","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}