{"record":{"id":"c85341703f9a20c4","repo":"jax-ml/jax","slug":"wrong-number-of-strides-for-spatial-dimensions","errorCode":null,"errorMessage":"Wrong number of strides for spatial dimensions","messagePattern":"Wrong number of strides for spatial dimensions","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax_reference.py","lineNumber":457,"sourceCode":"                 in zip(out_shape, window_strides, filter_shape, in_shape)]\n    if padding.upper() == 'SAME':\n      return [\n          (pad_size // 2, pad_size - pad_size // 2) for pad_size in pad_sizes\n      ]\n    else:\n      return [\n          (pad_size - pad_size // 2, pad_size // 2) for pad_size in pad_sizes\n      ]\n  else:\n    return [(0, 0)] * len(in_shape)\n\ndef _conv_view(lhs, rhs_shape, window_strides, pads, pad_value):\n  \"\"\"Compute the view (and its axes) of a convolution or window reduction.\"\"\"\n  if (_min(lhs.ndim, len(rhs_shape)) < 2 or lhs.ndim != len(rhs_shape)\n      or lhs.shape[1] != rhs_shape[1]):\n    raise ValueError('Dimension mismatch')\n  if len(window_strides) != len(rhs_shape) - 2:\n    raise ValueError('Wrong number of strides for spatial dimensions')\n  if len(pads) != len(rhs_shape) - 2:\n    raise ValueError('Wrong number of pads for spatial dimensions')\n\n  lhs = _pad(lhs, [(0, 0)] * 2 + list(pads), pad_value)\n  in_shape = lhs.shape[2:]\n  filter_shape = rhs_shape[2:]\n  dim = len(filter_shape)  # number of 'spatial' dimensions in convolution\n\n  out_strides = np.multiply(window_strides, lhs.strides[2:])\n  view_strides = lhs.strides[:1] + tuple(out_strides) + lhs.strides[1:]\n\n  out_shape = np.floor_divide(\n      np.subtract(in_shape, filter_shape), window_strides) + 1\n  view_shape = lhs.shape[:1] + tuple(out_shape) + rhs_shape[1:]\n\n  view = np.lib.stride_tricks.as_strided(lhs, view_shape, view_strides)\n\n  view_axes = list(range(view.ndim))","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax_reference.py#L439-L475","documentation":"In the NumPy reference implementation, the number of window strides must equal the number of spatial dimensions (rhs rank minus 2). Passing one stride per non-spatial axis, or vice versa, triggers this ValueError.","triggerScenarios":"lax_reference._conv/reduce_window with len(window_strides) != len(rhs_shape) - 2, e.g. 4 strides for a 2-spatial-dim conv.","commonSituations":"Passing full-rank strides (including batch/channel) to the reference path which expects only spatial strides.","solutions":["Pass strides only for spatial dimensions (drop batch/channel entries)","Check padding count matches too (len(pads) == spatial dims)"],"exampleFix":"# before\nlax_reference.reduce_window(x, dims, (1,1,1,1), pads)  # 4 strides, 2 spatial\n# after\nlax_reference.reduce_window(x, dims, (1,1), pads)","handlingStrategy":"validation","validationCode":"assert len(window_strides) == len(rhs_shape) - 2","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reference path strides are spatial-only"],"tags":["jax","numpy-reference","strides","shape-validation","convolution"],"backgroundTag":"convolution-shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}