{"record":{"id":"5ec4a779e998f49f","repo":"jax-ml/jax","slug":"stride-and-stride-axis-must-be-both-specified-or-n","errorCode":null,"errorMessage":"stride and stride_axis must be both specified or not.","messagePattern":"stride and stride_axis must be both specified or not\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/primitives.py","lineNumber":133,"sourceCode":"\n\nroll_p = jax_core.Primitive(\"roll\")\n\n\ndef 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","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/primitives.py#L115-L151","documentation":"Mosaic roll supports an optional strided mode, but the stride and stride_axis keyword arguments are coupled: they describe one stride specification and must be supplied together or both omitted. Supplying only one of them is contradictory and rejected.","triggerScenarios":"roll(x, shift, axis) with stride=4 but no stride_axis, or stride_axis=1 but no stride.","commonSituations":"Copy-pasting partial kwargs between roll call sites; refactoring where a stride parameter is threaded through but stride_axis is dropped by mistake; optional-argument plumbing with None defaults where one gets set conditionally.","solutions":["Pass both stride and stride_axis together, or pass neither","Audit helper wrappers that build kwargs dynamically to ensure the two are set jointly","If you do not need strided rolling, remove the stray argument"],"exampleFix":"# before\ny = roll(x, 2, axis=1, stride=8)\n\n# after\ny = roll(x, 2, axis=1, stride=8, stride_axis=0)","handlingStrategy":"validation","validationCode":"assert (stride is None) == (stride_axis is None), \"pass both or neither\"\nkwargs = {} if stride is None else dict(stride=stride, stride_axis=stride_axis)\ny = roll(x, shift, axis=axis, **kwargs)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build strided-roll kwargs as a pair","Keep stride and stride_axis adjacent in code and configs"],"tags":["jax","pallas","mosaic","roll","argument-validation","kwargs-pairing"],"backgroundTag":"paired-arguments-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}