code: def _get_spline1d_code(mode, poles, n_boundary):
      """Generates the code required for IIR filtering of a single 1d signal.
  
      Prefiltering is done by causal filtering followed by anti-causal filtering.
      Multiple boundary conditions have been implemented.
      """
      code = [
          """
      __device__ void spline_prefilter1d(
          T* __restrict__ c, idx_t signal_length, idx_t element_stride)
      {{"""
      ]
  
      # variables common to all boundary modes
      code.append(
          """
          idx_t i, n = signal_length;
          P z, z_i;"""
      )
  
      # retrieve the spline boundary extension mode to use
      mode = _get_spline_mode(mode)
  
      if mode == "mirror":
          # variables specific to mirror boundary mode
          code.append(
              """
          P z_n_1;"""
          )
      elif mode == "reflect":
          # variables specific to reflect boundary mode
          code.append(
              """
          P z_n;
          T c0;"""
          )
  
      for pole in poles:
          code.append(
              f"""
          // select the current pole
          z = {pole};"""
          )
  
          # initialize and apply the causal filter
          code.append(_causal_init_code(mode))
          code.append(
              """
          // apply the causal filter for the current pole
          for (i = 1; i < n; ++i) {{
              c[i * element_stride] += z * c[(i - 1) * element_stride];
          }}"""
          )
          code.append(
              """
          #ifdef __HIP_DEVICE_COMPILE__
          __syncthreads();
          #endif
          """
          )
          # initialize and apply the anti-causal filter
          code.append(_anticausal_init_code(mode))
          code.append(
              """
          // apply the anti-causal filter for the current pole
          for (i = n - 2; i >= 0; --i) {{
              c[i * element_stride] = z * (c[(i + 1) * element_stride] -
                                           c[i * element_stride]);
          }}"""
          )
  
      code += [
          """
      }}"""
      ]
      return textwrap.dedent("\n".join(code)).format(
          n_boundary=n_boundary
      )
  
file_path: cupy/cupyx/scipy/ndimage/_spline_prefilter_core.py
imports: import functools
  import math
  import operator
  import textwrap
  import cupy
label_desc: Use image node_id 6 for calling a global function with example usage: _get_spline1d_code(mode, poles, n_boundary) and returns: textwrap