{"record":{"id":"fa982c66560e852b","repo":"jax-ml/jax","slug":"mode-must-be-one-of-same-full-valid","errorCode":null,"errorMessage":"mode must be one of ['same', 'full', 'valid']","messagePattern":"mode must be one of \\['same', 'full', 'valid'\\]","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/signal.py","lineNumber":106,"sourceCode":"    as the first input:\n\n    >>> with jax.numpy.printoptions(precision=3):\n    ...   print(jax.scipy.signal.fftconvolve(x, y, mode='same'))\n    [3. 6. 7. 6. 3.]\n\n    Specifying ``mode = 'valid'`` returns only the portion where the two arrays\n    fully overlap:\n\n    >>> with jax.numpy.printoptions(precision=3):\n    ...   print(jax.scipy.signal.fftconvolve(x, y, mode='valid'))\n    [6. 7. 6.]\n  \"\"\"\n  check_arraylike('fftconvolve', in1, in2)\n  in1, in2 = promote_dtypes_inexact(in1, in2)\n  if in1.ndim != in2.ndim:\n    raise ValueError(\"in1 and in2 should have the same dimensionality\")\n  if mode not in [\"same\", \"full\", \"valid\"]:\n    raise ValueError(\"mode must be one of ['same', 'full', 'valid']\")\n  _fftconvolve = partial(_fftconvolve_unbatched, mode=mode)\n  if axes is None:\n    return _fftconvolve(in1, in2)\n  axes = _ensure_index_tuple(axes)\n  axes = tuple(canonicalize_axis(ax, in1.ndim) for ax in axes)\n  mapped_axes = set(range(in1.ndim)) - set(axes)\n  if any(in1.shape[i] != in2.shape[i] for i in mapped_axes):\n    raise ValueError(f\"mapped axes must have same shape; got {in1.shape=} {in2.shape=} {axes=}\")\n  for ax in sorted(mapped_axes):\n    _fftconvolve = api.vmap(_fftconvolve, in_axes=ax, out_axes=ax)\n  return _fftconvolve(in1, in2)\n\ndef _fftconvolve_unbatched(in1: Array, in2: Array, mode: str) -> Array:\n  full_shape = tuple(s1 + s2 - 1 for s1, s2 in zip(in1.shape, in2.shape))\n\n  # TODO(jakevdp): potentially use next_fast_len to evaluate with a more efficient shape.\n  fft_shape = full_shape  # tuple(next_fast_len(s) for s in full_shape)\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/signal.py#L88-L124","documentation":"fftconvolve supports only boundary modes 'same', 'full', 'valid'; the mode string is validated before any FFT work.","triggerScenarios":"Passing mode='circul', mode='Same', or a scipy-unrecognized mode name.","commonSituations":"Typos and case-sensitivity issues; passing mode through from user settings unvalidated.","solutions":["Use 'full', 'same', or 'valid' exactly","Normalize/validate mode in a config layer"],"exampleFix":"# before\nsignal.fftconvolve(x, y, mode='SAME')\n# after\nsignal.fftconvolve(x, y, 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":["Centralize mode constants"],"tags":["jax","scipy","signal","argument-validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}