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).
  
      Returns
      -------
      convolve : array
          An N-dimensional array containing a subset of the discrete linear
          convolution of `in1` with `in2`.
  
      See Also
      --------
      choose_conv_method : chooses the fastest appropriate convolution method
      fftconvolve
  
      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:
  
      >>> import cusignal
      >>> import cupy as cp
      >>> sig = cp.repeat(cp.asarray([0., 1., 0.]), 100)
      >>> win = cusignal.hann(50)
      >>> filtered = cusignal.convolve(sig, win, mode='same') / cp.sum(win)
  
      >>> import matplotlib.pyplot as plt
      >>> fig, (ax_orig, ax_win, ax_filt) = plt.subplots(3, 1, sharex=True)
      >>> ax_orig.plot(cp.asnumpy(sig))
      >>> ax_orig.set_title('Original pulse')
      >>> ax_orig.margins(0, 0.1)
      >>> ax_win.plot(cp.asnumpy(win))
      >>> ax_win.set_title('Filter impulse response')
      >>> ax_win.margins(0, 0.1)
      >>> ax_filt.plot(cp.asnumpy(filtered))
      >>> ax_filt.set_title('Filtered signal')
      >>> ax_filt.margins(0, 0.1)
      >>> fig.tight_layout()
      >>> fig.show()
  
      """
  
      volume = cp.asarray(in1)
      kernel = cp.asarray(in2)
  
      if volume.ndim == kernel.ndim == 0:
          return volume * kernel
      elif volume.ndim != kernel.ndim:
          raise ValueError(
              "in1 and in2 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 = cp.result_type(volume, kernel)
          if result_type.kind in {"u", "i"}:
              out = cp.around(out)
          return out.astype(result_type)
      elif method == "direct":
          if volume.ndim > 1:
              raise ValueError(
                  "Direct method is only implemented for 1D"
              )
  
          swapped_inputs = (mode != "valid") and (
              kernel.size > volume.size
          )
  
          if swapped_inputs:
              volume, kernel = kernel, volume
  
          return _convolution_cuda._convolve(
              volume, kernel, True, swapped_inputs, mode
          )
  
      else:
          raise ValueError(
              "Acceptable method flags are 'auto',"
              " 'direct', or 'fft'."
          )
  
file_path: cusignal/python/cusignal/convolution/convolve.py
imports: import sys
  import cupy
  import numpy
  from ..utils.fftpack_helper import _init_nd_shape_and_axes_sorted, next_fast_len
  from .None import _convolution_cuda
  from .convolution_utils import _centered, _fftconv_faster, _inputs_swap_needed, _numeric_arrays, _timeit_fast
label_desc: Use image node_id 1 for calling a global function with example usage: convolve(in1, in2, mode, method) and returns: unknown, out, _convolution_cuda