{"record":{"id":"f96b4d8723938ca2","repo":"jax-ml/jax","slug":"reduce-window-got-the-wrong-number-of-window-dimen","errorCode":null,"errorMessage":"reduce_window got the wrong number of window_dimensions for operand: got operand shape {} with window_dimensions {}.","messagePattern":"reduce_window got the wrong number of window_dimensions for operand: got operand shape (.+?) with window_dimensions (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/windowed_reductions.py","lineNumber":609,"sourceCode":"    operand,\n    window_dimensions,\n    window_strides,\n    padding,\n    base_dilation,\n    window_dilation,\n):\n  lax._check_shapelike(\"reduce_window\", \"window_dimensions\", window_dimensions,\n                       non_zero_shape=True)\n  lax._check_shapelike(\"reduce_window\", \"window_strides\", window_strides,\n                       non_zero_shape=True)\n  lax._check_shapelike(\"reduce_window\", \"base_dilation\", base_dilation)\n  lax._check_shapelike(\"reduce_window\", \"window_dilation\", window_dilation)\n  if operand.ndim != len(window_dimensions):\n    msg = (\n        \"reduce_window got the wrong number of window_dimensions for \"\n        \"operand: got operand shape {} with window_dimensions {}.\"\n    )\n    raise TypeError(msg.format(operand.shape, window_dimensions))\n  if len(window_strides) != len(window_dimensions):\n    msg = (\"reduce_window got inconsistent window_strides and \"\n           \"window_dimensions: got window_strides {} and window_dimensions {}.\")\n    raise TypeError(msg.format(window_strides, window_dimensions))\n  if len(base_dilation) != len(window_dimensions):\n    msg = (\"reduce_window got inconsistent base_dilation and \"\n           \"window_dimensions: got base_dilation {} and window_dimensions {}.\")\n    raise TypeError(msg.format(base_dilation, window_dimensions))\n  if len(window_dilation) != len(window_dimensions):\n    msg = (\"reduce_window got inconsistent window_dilation and \"\n           \"window_dimensions: got window_dilation {} and window_dimensions \"\n           \"{}.\")\n    raise TypeError(msg.format(window_dilation, window_dimensions))\n\n  return reduce_window_shape_tuple(operand.shape, window_dimensions,\n                                   window_strides, padding, base_dilation,\n                                   window_dilation)\n","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/windowed_reductions.py#L591-L627","documentation":"lax.reduce_window requires len(window_dimensions) == operand.ndim. This shape-rule error fires when the window specification length doesn't match the operand rank.","triggerScenarios":"Passing window_dimensions=(3,3) for a 4-D NHWC operand (needs 4 entries like (1,3,3,1)).","commonSituations":"Converting convolution/pooling code from frameworks expecting only spatial dims; forgetting batch/channel dimensions in NHWC.","solutions":["Extend window_dimensions to include batch and channel dims, usually (1, *spatial, 1) for NHWC","Similarly fix window_strides, padding, base_dilation, window_dilation to the same length"],"exampleFix":"# before\nlax.reduce_window_max(x, (3,3), (1,1), 'VALID')  # x is (N,H,W,C)\n# after\nlax.reduce_window_max(x, (1,3,3,1), (1,1,1,1), 'VALID')","handlingStrategy":"validation","validationCode":"assert x.ndim == len(window_dimensions), f'rank {x.ndim} vs {len(window_dimensions)} dims'","typeGuard":"def window_matches(x, w): return x.ndim == len(w)","tryCatchPattern":null,"preventionTips":["Remember NHWC: window specs include batch and channel as 1s","Centralize pooling param construction in one helper"],"tags":["jax","shape-validation","reduce-window","windowing"],"backgroundTag":"jax-reduce-window-invalid-arguments","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}