{"record":{"id":"1e4edea04b8a2266","repo":"jax-ml/jax","slug":"arange-has-step-0","errorCode":null,"errorMessage":"arange has step == 0","messagePattern":"arange has step == 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":6014,"sourceCode":"    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\n\n@export\ndef meshgrid(*xi: ArrayLike, copy: bool = True, sparse: bool = False,\n             indexing: str = 'xy') -> tuple[Array, ...]:\n  \"\"\"Construct N-dimensional grid arrays from N 1-dimensional vectors.\n\n  JAX implementation of :func:`numpy.meshgrid`.","sourceCodeStart":5996,"sourceCodeEnd":6032,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L5996-L6032","documentation":"In jnp.arange's dynamic path, a step that statically evaluates to exactly zero raises this ValueError because an arange with zero step has infinite/undefined length. The check must resolve statically; a symbolic step whose sign can't be decided instead raises InconclusiveDimensionOperation.","triggerScenarios":"jnp.arange(0, 10, 0) directly, or step computed as a difference that is zero, e.g. step = stop - stop, or step = arr.shape[0] - arr.shape[0] in dynamic-shape code.","commonSituations":"Step derived from user configuration where an extreme setting collapses it to zero (step = 1/n with overflow, or delta = end - start where end == start); adaptive-sampling loops passing a zero increment.","solutions":["Guard the step before calling: if step == 0: raise/handle, else arange","Use a small nonzero epsilon if a degenerate range is intended: step or 1e-9 (with awareness of length explosion)","Fix the step computation so it cannot collapse to zero (validate end != start)"],"exampleFix":"// before\nxs = jnp.arange(start, stop, stop - start * 2)  # zero when stop == 0... e.g. step=0\n// after\nstep = stop - start\nxs = jnp.arange(start, stop, step) if step != 0 else jnp.array([start])","handlingStrategy":"validation","validationCode":"if step == 0:\n    raise ValueError('zero step')\nxs = jnp.arange(start, stop, step)","typeGuard":null,"tryCatchPattern":"try:\n    xs = jnp.arange(start, stop, step)\nexcept ValueError as e:\n    if 'step == 0' in str(e):\n        xs = jnp.array([start])\n    else:\n        raise","preventionTips":["Guard degenerate ranges where step collapses to zero","Validate end != start before computing a difference-based step"],"tags":["jax","arange","zero-step","valueerror"],"backgroundTag":"zero-step-range","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}