code: def convolve(in1, in2, mode="full", method="auto"):
      """
      Convolve two N-dimensional arrays.
  
      Convolve `in1` and `in2`, with the output size determined by the
      `mode` argument.
  
      Parameters
      ----------
      in1 : array_like
          First input.
      in2 : array_like
          Second input. Should have the same number of dimensions as `in1`.
      mode : str {'full', 'valid', 'same'}, optional
          A string indicating the size of the output:
  
          ``full``
             The output is the full discrete linear convolution
             of the inputs. (Default)
          ``valid``
             The output consists only of those elements that do not
             rely on the zero-padding. In 'valid' mode, either `in1` or `in2`
             must be at least as large as the other in every dimension.
          ``same``
             The output is the same size as `in1`, centered
             with respect to the 'full' output.
      method : str {'auto', 'direct', 'fft'}, optional
          A string indicating which method to use to calculate the convolution.
  
          ``direct``
             The convolution is determined directly from sums, the definition of
             convolution.
          ``fft``
             The Fourier Transform is used to perform the convolution by calling
             `fftconvolve`.
          ``auto``
             Automatically chooses direct or Fourier method based on an estimate
             of which is faster (default).  See Notes for more detail.
  
             .. versionadded:: 0.19.0
  
      Returns
      -------
      convolve : array
          An N-dimensional array containing a subset of the discrete linear
          convolution of `in1` with `in2`.
  
      See Also
      --------
      numpy.polymul : performs polynomial multiplication (same operation, but
                      also accepts poly1d objects)
      choose_conv_method : chooses the fastest appropriate convolution method
      fftconvolve : Always uses the FFT method.
      oaconvolve : Uses the overlap-add method to do convolution, which is
                   generally faster when the input arrays are large and
                   significantly different in size.
  
      Notes
      -----
      By default, `convolve` and `correlate` use ``method='auto'``, which calls
      `choose_conv_method` to choose the fastest method using pre-computed
      values (`choose_conv_method` can also measure real-world timing with a
      keyword argument). Because `fftconvolve` relies on floating point numbers,
      there are certain constraints that may force `method=direct` (more detail
      in `choose_conv_method` docstring).
  
      Examples
      --------
      Smooth a square pulse using a Hann window:
  
      >>> from scipy import signal
      >>> sig = np.repeat([0., 1., 0.], 100)
      >>> win = signal.windows.hann(50)
      >>> filtered = signal.convolve(sig, win, mode='same') / sum(win)
  
      >>> import matplotlib.pyplot as plt
      >>> fig, (ax_orig, ax_win, ax_filt) = plt.subplots(3, 1, sharex=True)
      >>> ax_orig.plot(sig)
      >>> ax_orig.set_title('Original pulse')
      >>> ax_orig.margins(0, 0.1)
      >>> ax_win.plot(win)
      >>> ax_win.set_title('Filter impulse response')
      >>> ax_win.margins(0, 0.1)
      >>> ax_filt.plot(filtered)
      >>> ax_filt.set_title('Filtered signal')
      >>> ax_filt.margins(0, 0.1)
      >>> fig.tight_layout()
      >>> fig.show()
  
      """
      volume = np.asarray(in1)
      kernel = np.asarray(in2)
  
      if volume.ndim == kernel.ndim == 0:
          return volume * kernel
      elif volume.ndim != kernel.ndim:
          raise ValueError(
              "volume and kernel should have the same " "dimensionality"
          )
  
      if _inputs_swap_needed(mode, volume.shape, kernel.shape):
          # Convolution is commutative; order doesn't have any effect on output
          volume, kernel = kernel, volume
  
      if method == "auto":
          method = choose_conv_method(volume, kernel, mode=mode)
  
      if method == "fft":
          out = fftconvolve(volume, kernel, mode=mode)
          result_type = np.result_type(volume, kernel)
          if result_type.kind in {"u", "i"}:
              out = np.around(out)
          return out.astype(result_type)
      elif method == "direct":
          # fastpath to faster numpy.convolve for 1d inputs when possible
          if _np_conv_ok(volume, kernel, mode):
              return np.convolve(volume, kernel, mode)
  
          return correlate(
              volume, _reverse_and_conj(kernel), mode, "direct"
          )
      else:
          raise ValueError(
              "Acceptable method flags are 'auto',"
              " 'direct', or 'fft'."
          )
  
imports: import operator
  import math
  import timeit
  from scipy.spatial import cKDTree
  from .None import sigtools, dlti
  from ._upfirdn import upfirdn, _output_len, _upfirdn_modes
  from scipy import linalg, fft
  from scipy.fft._helper import _init_nd_shape_and_axes
  from scipy._lib._util import prod
  import numpy
  from scipy.special import lambertw
  from .windows import get_window
  from ._arraytools import axis_slice, axis_reverse, odd_ext, even_ext, const_ext
  from .filter_design import cheby1, _validate_sos
  from .fir_filter_design import firwin
  from ._sosfilt import _sosfilt
  import warnings
label_desc: Use image node_id 20 for calling a global function with example usage: convolve(in1, in2, mode, method) and returns: unknown, out, correlate, np