docstr: Apply the prepared filter to the specified axis of a nD signal x
docstr_tok: ["Apply","the","prepared","filter","to","the","specified","axis","of","a","nD","signal","x"]
code: def apply_filter(
      self,
      x,
      axis,
  ):
      """Apply the prepared filter to the specified axis of a nD signal x"""
  
      x = cp.asarray(x, self._output_type)
  
      output_len = _output_len(
          self._h_len_orig, x.shape[axis], self._up, self._down
      )
      output_shape = list(x.shape)
      output_shape[axis] = output_len
      out = cp.empty(output_shape, dtype=self._output_type, order="C")
      axis = axis % x.ndim
  
      # Precompute variables on CPU
      x_shape_a = x.shape[axis]
      h_per_phase = len(self._h_trans_flip) // self._up
      padded_len = (
          x.shape[axis] + (len(self._h_trans_flip) // self._up) - 1
      )
  
      if out.ndim > 1:
          threadsperblock = (8, 8)
          blocks = ceil(out.shape[0] / threadsperblock[0])
          blockspergrid_x = (
              blocks if blocks < _get_max_gdx() else _get_max_gdx()
          )
  
          blocks = ceil(out.shape[1] / threadsperblock[1])
          blockspergrid_y = (
              blocks if blocks < _get_max_gdy() else _get_max_gdy()
          )
  
          blockspergrid = (blockspergrid_x, blockspergrid_y)
  
      else:
          threadsperblock, blockspergrid = _get_tpb_bpg()
  
      if out.ndim == 1:
          k_type = "upfirdn1D"
  
          _populate_kernel_cache(out.dtype, k_type)
  
          kernel = _get_backend_kernel(
              out.dtype,
              blockspergrid,
              threadsperblock,
              k_type,
          )
      elif out.ndim == 2:
          k_type = "upfirdn2D"
  
          _populate_kernel_cache(out.dtype, k_type)
  
          kernel = _get_backend_kernel(
              out.dtype,
              blockspergrid,
              threadsperblock,
              k_type,
          )
      else:
          raise NotImplementedError("upfirdn() requires ndim <= 2")
  
      kernel(
          x,
          self._h_trans_flip,
          self._up,
          self._down,
          axis,
          x_shape_a,
          h_per_phase,
          padded_len,
          out,
      )
  
      _print_atts(kernel)
  
      return out
  
imports: from math import ceil
  import cupy
  import numpy
  from ..utils._caches import _cupy_kernel_cache
  from ..utils.helper_tools import _get_function, _get_max_gdx, _get_max_gdy, _get_tpb_bpg, _print_atts
label_desc: Use image node_id 2 for calling the _UpFIRDn obj's underlying member method code with example usage: obj.apply_filter(x, axis) and returns: out