{"record":{"id":"746959fbaf98ff9d","repo":"jax-ml/jax","slug":"unsupported-mode-mode-746959","errorCode":null,"errorMessage":"unsupported mode: {mode}","messagePattern":"unsupported mode: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/signal.py","lineNumber":190,"sourceCode":"  swap = all(s1 <= s2 for s1, s2 in zip(in1.shape, in2.shape))\n  if not (no_swap or swap):\n    raise ValueError(\"One input must be smaller than the other in every dimension.\")\n\n  shape_o = in2.shape\n  if swap:\n    in1, in2 = in2, in1\n  shape = in2.shape\n  in2 = jnp.flip(in2)\n\n  if mode == 'valid':\n    padding = [(0, 0) for s in shape]\n  elif mode == 'same':\n    padding = [(s - 1 - (s_o - 1) // 2, s - s_o + (s_o - 1) // 2)\n               for (s, s_o) in zip(shape, shape_o)]\n  elif mode == 'full':\n    padding = [(s - 1, s - 1) for s in shape]\n  else:\n    raise ValueError(f'unsupported mode: {mode}')\n\n  strides = tuple(1 for s in shape)\n  result = lax.conv_general_dilated(in1[None, None], in2[None, None], strides,\n                                    padding, precision=precision)\n  return result[0, 0]\n\n\ndef convolve(in1: Array, in2: Array, mode: ModeString = 'full', method: str = 'auto',\n             precision: PrecisionLike = None) -> Array:\n  \"\"\"Convolution of two N-dimensional arrays.\n\n  JAX implementation of :func:`scipy.signal.convolve`.\n\n  Args:\n    in1: left-hand input to the convolution.\n    in2: right-hand input to the convolution. Must have ``in1.ndim == in2.ndim``.\n    mode: controls the size of the output. Available operations are:\n","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/signal.py#L172-L208","documentation":"Defensive unreachable-in-practice branch in _convolve_nd: after handling 'same' and 'full' (with 'valid' handled earlier), any other mode string reaches this raise. In practice you only hit it by bypassing the public wrappers or passing a non-standard mode, since the top-of-function check restricts mode to full/same/valid.","triggerScenarios":"Directly calling the private _convolve_nd with an arbitrary mode string; passing a mode variable that is not one of 'full', 'same', 'valid' (which normally trips the earlier check at function entry).","commonSituations":"Typos like 'Same' or 'SAME' (case-sensitive); passing a tf-style padding string from ported code.","solutions":["Use exactly one of 'full', 'same', 'valid' (lowercase)","Validate/normalize the mode variable against the allowed set before calling convolve/convolve2d/correlate2d"],"exampleFix":"// before\njax.scipy.signal.convolve2d(x, k, mode='SAME')\n// after\njax.scipy.signal.convolve2d(x, k, mode='same')","handlingStrategy":"validation","validationCode":"MODES = ('full', 'same', 'valid')\nmode = mode if mode in MODES else 'full'  # or raise early with your own message","typeGuard":"def is_valid_mode(m: str) -> bool:\n    return m in ('full', 'same', 'valid')","tryCatchPattern":"try:\n    convolve2d(x, k, mode=mode)\nexcept ValueError as e:\n    if 'mode' in str(e):\n        mode = 'full'  # fallback","preventionTips":["Normalize mode strings to lowercase at config boundaries","Keep mode constants in one place instead of free-form strings"],"tags":["jax","scipy","convolution","invalid-argument-value"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}