code: def convolve(signal, kernel, mode="full"):
      """
      Computes the 1-d convolution of signal by kernel using FFTs.
      The two arguments should have the same rightmost dim, but may otherwise be
      arbitrarily broadcastable.
  
      :param torch.Tensor signal: A signal to convolve.
      :param torch.Tensor kernel: A convolution kernel.
      :param str mode: One of: 'full', 'valid', 'same'.
      :return: A tensor with broadcasted shape. Letting ``m = signal.size(-1)``
          and ``n = kernel.size(-1)``, the rightmost size of the result will be:
          ``m + n - 1`` if mode is 'full';
          ``max(m, n) - min(m, n) + 1`` if mode is 'valid'; or
          ``max(m, n)`` if mode is 'same'.
      :rtype torch.Tensor:
      """
      m = signal.size(-1)
      n = kernel.size(-1)
      if mode == "full":
          truncate = m + n - 1
      elif mode == "valid":
          truncate = max(m, n) - min(m, n) + 1
      elif mode == "same":
          truncate = max(m, n)
      else:
          raise ValueError("Unknown mode: {}".format(mode))
  
      # Compute convolution using fft.
      padded_size = m + n - 1
      # Round up for cheaper fft.
      fast_ftt_size = next_fast_len(padded_size)
      f_signal = rfft(signal, n=fast_ftt_size)
      f_kernel = rfft(kernel, n=fast_ftt_size)
      f_result = f_signal * f_kernel
      result = irfft(f_result, n=fast_ftt_size)
  
      start_idx = (padded_size - truncate) // 2
      return result[..., start_idx : start_idx + truncate]
  
imports: import math
  import torch
  from torch.fft import irfft, rfft
  from ..None import settings
label_desc: Use image node_id 9 for calling a global function with example usage: convolve(signal, kernel, mode) and returns: result