{"record":{"id":"a7aff5476f2f4be2","repo":"jax-ml/jax","slug":"stride-axis-is-out-of-range","errorCode":null,"errorMessage":"stride_axis is out of range","messagePattern":"stride_axis is out of range","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/primitives.py","lineNumber":138,"sourceCode":"def roll(\n    x: jax.Array,\n    shift: jax.Array | int,\n    axis: int,\n    *,\n    stride: int | None = None,\n    stride_axis: int | None = None,\n) -> jax.Array:\n  if isinstance(shift, int) and shift < 0:\n    raise ValueError(\"shift must be non-negative.\")\n  if axis < 0 or axis >= len(x.shape):\n    raise ValueError(\"axis is out of range.\")\n  if (stride is None) != (stride_axis is None):\n    raise ValueError(\"stride and stride_axis must be both specified or not.\")\n  if stride is not None and stride_axis is not None:\n    if stride < 0:\n      raise ValueError(\"stride must be non-negative.\")\n    if stride_axis < 0 or stride_axis >= len(x.shape):\n      raise ValueError(\"stride_axis is out of range\")\n    if axis == stride_axis:\n      raise ValueError(\"expected axis and stride_axis are different.\")\n  return roll_p.bind(\n      x, shift, axis=axis, stride=stride, stride_axis=stride_axis\n  )\n\n\n@roll_p.def_abstract_eval\ndef _roll_abstract_eval(x, shift, **_):\n  del shift\n  return x\n\n\ndef _roll_lowering_rule(\n    ctx: mlir.LoweringRuleContext, x, shift, *, axis, stride, stride_axis\n):\n  def _roll(x, shift):\n    if stride is None:","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/primitives.py#L120-L156","documentation":"In strided roll mode, stride_axis must be a valid non-negative index into x's shape. Negative or out-of-bounds stride_axis values are rejected (no negative-index normalization).","triggerScenarios":"roll(..., stride=4, stride_axis=-1) or stride_axis >= len(x.shape).","commonSituations":"Using -1 for the natural 'last dim' stride axis as you would in jnp; changing the rank of the operand so a hardcoded stride_axis no longer fits.","solutions":["Normalize: stride_axis = stride_axis % len(x.shape)","Check bounds before the call","Prefer explicit non-negative indices in Pallas code unlike jnp idioms"],"exampleFix":"# before\ny = roll(x, 2, axis=0, stride=8, stride_axis=-1)\n\n# after\ny = roll(x, 2, axis=0, stride=8, stride_axis=len(x.shape) - 1)","handlingStrategy":"validation","validationCode":"stride_axis = stride_axis % len(x.shape) if stride_axis is not None else None\nassert stride_axis is None or 0 <= stride_axis < len(x.shape)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize negative stride_axis","Avoid jnp-style -1 idioms in Pallas code"],"tags":["jax","pallas","mosaic","roll","axis-validation","shape-validation"],"backgroundTag":"axis-out-of-range","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}