{"record":{"id":"78c3e59a10fd18c4","repo":"jax-ml/jax","slug":"in1-and-in2-should-have-the-same-dimensionality","errorCode":null,"errorMessage":"in1 and in2 should have the same dimensionality","messagePattern":"in1 and in2 should have the same dimensionality","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/signal.py","lineNumber":104,"sourceCode":"\n    Specifying ``mode = 'same'`` returns a centered convolution the same size\n    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.","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/signal.py#L86-L122","documentation":"jax.scipy.signal.fftconvolve requires in1 and in2 to have equal ndim after promotion; convolution is defined per-axis so mismatched ranks are ambiguous.","triggerScenarios":"Convolving a 1D kernel with a 2D image, or a batched (N,H,W) input with an (H,W) filter.","commonSituations":"Applying 1D smoothing kernels to 2D signals without reshaping; mixing batched and unbatched operands.","solutions":["Reshape the smaller operand to match rank, e.g. kernel[None, :] for 2D, or kernel[None] for batched inputs","Use axes= parameter to convolve only specific shared axes","Squeeze irrelevant unit dims deliberately"],"exampleFix":"# before\nout = signal.fftconvolve(img2d, kernel1d, mode='same')\n# after\nout = signal.fftconvolve(img2d, kernel1d[None, :], mode='same')","handlingStrategy":"validation","validationCode":"assert jnp.asarray(in1).ndim == jnp.asarray(in2).ndim, (in1.shape, in2.shape)","typeGuard":"def same_rank(a, b) -> bool: return jnp.asarray(a).ndim == jnp.asarray(b).ndim","tryCatchPattern":null,"preventionTips":["Write a reshape helper that auto-adds leading axes to the kernel"],"tags":["jax","scipy","signal","fft","shape-mismatch"],"backgroundTag":"argument-shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}