code: def _apply_conv_mode(ret, s1, s2, mode, axes):
      """Calculate the convolution result shape based on the `mode` argument.
  
      Returns the result sliced to the correct size for the given mode.
  
      Parameters
      ----------
      ret : array
          The result array, with the appropriate shape for the 'full' mode.
      s1 : list of int
          The shape of the first input.
      s2 : list of int
          The shape of the second input.
      mode : str {'full', 'valid', 'same'}
          A string indicating the size of the output.
          See the documentation `fftconvolve` for more information.
      axes : list of ints
          Axes over which to compute the convolution.
  
      Returns
      -------
      ret : array
          A copy of `res`, sliced to the correct size for the given `mode`.
  
      """
      if mode == "full":
          return ret.copy()
      elif mode == "same":
          return _centered(ret, s1).copy()
      elif mode == "valid":
          shape_valid = [
              ret.shape[a] if a not in axes else s1[a] - s2[a] + 1
              for a in range(ret.ndim)
          ]
          return _centered(ret, shape_valid).copy()
      else:
          raise ValueError(
              "acceptable mode flags are 'valid'," " 'same', or 'full'"
          )
  
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 9 for calling a global function with example usage: _apply_conv_mode(ret, s1, s2, mode, axes) and returns: ret, _centered, _centered