{"record":{"id":"200946a7ce2d8c30","repo":"jax-ml/jax","slug":"dimension-mismatch","errorCode":null,"errorMessage":"Dimension mismatch","messagePattern":"Dimension mismatch","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax_reference.py","lineNumber":455,"sourceCode":"    pad_sizes = [_max((out_size - 1) * stride + filter_size - in_size, 0)\n                 for out_size, stride, filter_size, in_size\n                 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)","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax_reference.py#L437-L473","documentation":"In jax.lax_reference (the pure-NumPy eager backend), _conv_view validates convolution/window-reduction inputs: lhs must be at least 2-D, match rhs rank, and lhs.shape[1] must equal rhs.shape[1] (channel dims). A violation raises 'Dimension mismatch'.","triggerScenarios":"Calling lax_reference.reduce_window or _conv with a 1-D input, mismatched ranks, or a rhs whose channel dim differs from the lhs channel dim (e.g. NumPy conv path used with wrong filter layout).","commonSituations":"Using jax operations outside jit/tracing (lax_reference fallback) with data shaped for another framework (e.g. filters in HWIO vs OIHW).","solutions":["Reshape operands to expected NHWC/OIHW layout with matching channel dimension","Verify lhs.ndim == len(rhs_shape) >= 2 and lhs.shape[1] == rhs_shape[1] before calling","Run under jit where the XLA path gives detailed shape errors"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert lhs.ndim >= 2 and lhs.ndim == len(rhs_shape) and lhs.shape[1] == rhs_shape[1]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use NHWC/OIHW consistently","Prefer jit path for better error messages"],"tags":["jax","numpy-reference","convolution","shape-validation"],"backgroundTag":"convolution-shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}