{"record":{"id":"9435be741a7c5727","repo":"jax-ml/jax","slug":"mode-must-be-one-of-full-same-valid-9435be","errorCode":null,"errorMessage":"mode must be one of ['full', 'same', 'valid']","messagePattern":"mode must be one of \\['full', 'same', 'valid'\\]","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/signal.py","lineNumber":164,"sourceCode":"    out_shape = full_shape\n  elif mode == \"same\":\n    out_shape = in1.shape\n  elif mode == \"valid\":\n    out_shape = tuple(s1 - s2 + 1 for s1, s2 in zip(in1.shape, in2.shape))\n  else:\n    raise ValueError(f\"Unrecognized {mode=}\")\n\n  start_indices = tuple((full_size - out_size) // 2\n                        for full_size, out_size in zip(full_shape, out_shape))\n  return lax.dynamic_slice(conv, start_indices, out_shape)\n\n\n# Note: we do not reuse the code from jax.numpy.convolve here, because the handling\n# of padding differs slightly between the two implementations (particularly for\n# mode='same').\ndef _convolve_nd(in1: Array, in2: Array, mode: ModeString, *, precision: PrecisionLike) -> Array:\n  if mode not in [\"full\", \"same\", \"valid\"]:\n    raise ValueError(\"mode must be one of ['full', 'same', 'valid']\")\n  if in1.ndim != in2.ndim:\n    raise ValueError(\"in1 and in2 must have the same number of dimensions\")\n  if in1.size == 0 or in2.size == 0:\n    raise ValueError(f\"zero-size arrays not supported in convolutions, got shapes {in1.shape} and {in2.shape}.\")\n  in1, in2 = promote_dtypes_inexact(in1, in2)\n\n  no_swap = all(s1 >= s2 for s1, s2 in zip(in1.shape, in2.shape))\n  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':","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/signal.py#L146-L182","documentation":"_convolve_nd (backing convolve, convolve2d, correlate2d) requires mode to be exactly 'full', 'same', or 'valid' before processing.","triggerScenarios":"convolve2d(x, y, mode='same ' ), correlate2d(..., mode='Valid'), or a mode from an unvalidated config.","commonSituations":"Typos/case; passing numpy string types or enum objects from other frameworks.","solutions":["Use exact lowercase strings 'full'/'same'/'valid'","Sanitize mode strings from configs early"],"exampleFix":"# before\nsignal.convolve2d(a, b, mode='Same')\n# after\nsignal.convolve2d(a, b, mode='same')","handlingStrategy":"validation","validationCode":"assert mode in ('full','same','valid'), mode","typeGuard":"def is_mode(m: str) -> bool: return m in ('full', 'same', 'valid')","tryCatchPattern":null,"preventionTips":["Normalize mode with mode.lower().strip() before passing"],"tags":["jax","scipy","signal","convolution","argument-validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}