jax-ml/jax · error · ValueError
Unrecognized {mode=}
Error message
Unrecognized {mode=} What it means
Defensive fallthrough in _fftconvolve_unbatched when mode is not 'full'/'same'/'valid' after slicing logic. Normally unreachable because fftconvolve validates mode earlier; it can fire via direct internal calls or monkeypatching.
Source
Thrown at jax/_src/scipy/signal.py:152
if (all(s1 == 1 or s2 == 1 for s1, s2 in zip(in1.shape, in2.shape))):
conv = in1 * in2
else:
if jnp.iscomplexobj(in1):
fft, ifft = jnp.fft.fftn, jnp.fft.ifftn
else:
fft, ifft = jnp.fft.rfftn, jnp.fft.irfftn
sp1 = fft(in1, fft_shape)
sp2 = fft(in2, fft_shape)
conv = ifft(sp1 * sp2, fft_shape)
if mode == "full":
out_shape = full_shape
elif mode == "same":
out_shape = in1.shape
elif mode == "valid":
out_shape = tuple(s1 - s2 + 1 for s1, s2 in zip(in1.shape, in2.shape))
else:
raise ValueError(f"Unrecognized {mode=}")
start_indices = tuple((full_size - out_size) // 2
for full_size, out_size in zip(full_shape, out_shape))
return lax.dynamic_slice(conv, start_indices, out_shape)
# Note: we do not reuse the code from jax.numpy.convolve here, because the handling
# of padding differs slightly between the two implementations (particularly for
# mode='same').
def _convolve_nd(in1: Array, in2: Array, mode: ModeString, *, precision: PrecisionLike) -> Array:
if mode not in ["full", "same", "valid"]:
raise ValueError("mode must be one of ['full', 'same', 'valid']")
if in1.ndim != in2.ndim:
raise ValueError("in1 and in2 must have the same number of dimensions")
if in1.size == 0 or in2.size == 0:
raise ValueError(f"zero-size arrays not supported in convolutions, got shapes {in1.shape} and {in2.shape}.")
in1, in2 = promote_dtypes_inexact(in1, in2)
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Call the public fftconvolve/convolve instead of private helpers
- Validate mode against ['full','same','valid'] before any internal pass-through
Example fix
# before out = _fftconvolve_unbatched(in1, in2, mode='circul') # after out = jax.scipy.signal.fftconvolve(in1, in2, mode='same')
Defensive patterns
Strategy: validation
Validate before calling
assert mode in ('full','same','valid'), mode Type guard
def is_mode(m: str) -> bool: return m in ('full', 'same', 'valid') Prevention
- Never call private _fftconvolve_unbatched directly
When it happens
Trigger: Calling the private _fftconvolve_unbatched with an unchecked mode; bypassing the public API validation.
Common situations: Internal code reuse where mode is passed through from another function without revalidation.
Related errors
- mode must be one of ['same', 'full', 'valid']
- mode must be one of ['full', 'same', 'valid']
- Unsupported method: {method}
- ind must be a positive integer; got {ind=}
- Expected kind to be on of: {valid_kind}; got {kind}
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/58f751992d4e176f.
Report an issue: GitHub.