jax-ml/jax · error · ValueError
Got {method=}; expected 'auto', 'fft', or 'direct'.
Error message
Got {method=}; expected 'auto', 'fft', or 'direct'. What it means
The public convolve/correlate 'method' parameter selects the implementation: 'fft' uses fftconvolve, 'direct'/'auto' use the spatial path. Any other string raises this error listing the accepted values.
Source
Thrown at jax/_src/scipy/signal.py:260
Specifying ``mode = 'same'`` returns a centered convolution the same size
as the first input:
>>> jax.scipy.signal.convolve(x, y, mode='same')
Array([3., 6., 7., 6., 3.], dtype=float32)
Specifying ``mode = 'valid'`` returns only the portion where the two arrays
fully overlap:
>>> jax.scipy.signal.convolve(x, y, mode='valid')
Array([6., 7., 6.], dtype=float32)
"""
if method == 'fft':
return fftconvolve(in1, in2, mode=mode)
elif method in ['direct', 'auto']:
return _convolve_nd(in1, in2, mode, precision=precision)
else:
raise ValueError(f"Got {method=}; expected 'auto', 'fft', or 'direct'.")
def convolve2d(in1: Array, in2: Array, mode: ModeString = 'full', boundary: str = 'fill',
fillvalue: float = 0, precision: PrecisionLike = None) -> Array:
"""Convolution of two 2-dimensional arrays.
JAX implementation of :func:`scipy.signal.convolve2d`.
Args:
in1: left-hand input to the convolution. Must have ``in1.ndim == 2``.
in2: right-hand input to the convolution. Must have ``in2.ndim == 2``.
mode: controls the size of the output. Available operations are:
* ``"full"``: (default) output the full convolution of the inputs.
* ``"same"``: return a centered portion of the ``"full"`` output which
is the same size as ``in1``.
* ``"valid"``: return the portion of the ``"full"`` output which do not
depend on padding at the array edges.View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Set method to exactly 'auto', 'fft', or 'direct'
- Strip/lowercase external strings before passing: method = method.strip().lower()
- Default to omitting method (defaults to 'auto') when unsure
Example fix
// before convolve(x, y, method=os.environ['CONV_METHOD']) // after convolve(x, y, method=os.environ['CONV_METHOD'].strip().lower())
Defensive patterns
Strategy: validation
Validate before calling
METHODS = ('auto', 'fft', 'direct')
assert method in METHODS, f'method must be one of {METHODS}' Type guard
def is_valid_method(m: str) -> bool:
return m in ('auto', 'fft', 'direct') Prevention
- Strip().lower() external method strings before passing
- Omit method to use the safe 'auto' default
When it happens
Trigger: jax.scipy.signal.convolve(x, y, method='fft ') (trailing space), method='FFT', or method='auto' misspelled; passing a scipy-style method default copied incorrectly.
Common situations: Config-driven code where method comes from a YAML/env string; case or whitespace mismatches; version drift from scipy APIs that accept different method names.
Related errors
- unsupported mode: {mode}
- For 'valid' mode, One input must be at least as large as the
- mode must be one of ['full', 'same', 'valid']
- in1 and in2 must have the same number of dimensions
- zero-size arrays not supported in convolutions, got shapes {
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/f8372af0bff62b08.
Report an issue: GitHub.