code: def _generate_boundary_condition_ops(
      mode, ix, xsize, int_t="int", float_ix=False
  ):
      min_func = "fmin" if float_ix else "min"
      max_func = "fmax" if float_ix else "max"
      if mode in ["reflect", "grid-mirror"]:
          ops = """
          if ({ix} < 0) {{
              {ix} = - 1 -{ix};
          }}
          {ix} %= {xsize} * 2;
          {ix} = {min}({ix}, 2 * {xsize} - 1 - {ix});""".format(
              ix=ix, xsize=xsize, min=min_func
          )
      elif mode == "mirror":
          ops = """
          if ({xsize} == 1) {{
              {ix} = 0;
          }} else {{
              if ({ix} < 0) {{
                  {ix} = -{ix};
              }}
              {ix} = 1 + ({ix} - 1) % (({xsize} - 1) * 2);
              {ix} = {min}({ix}, 2 * {xsize} - 2 - {ix});
          }}""".format(
              ix=ix, xsize=xsize, min=min_func
          )
      elif mode == "nearest":
          ops = """
          {ix} = {min}({max}(({T}){ix}, ({T})0), ({T})({xsize} - 1));""".format(
              ix=ix,
              xsize=xsize,
              min=min_func,
              max=max_func,
              # force using 64-bit signed integer for ptrdiff_t,
              # see cupy/cupy#6048
              T=("int" if int_t == "int" else "long long"),
          )
      elif mode == "grid-wrap":
          ops = """
          {ix} %= {xsize};
          while ({ix} < 0) {{
              {ix} += {xsize};
          }}""".format(
              ix=ix, xsize=xsize
          )
      elif mode == "wrap":
          ops = """
          if ({ix} < 0) {{
              {ix} += ({sz} - 1) * (({int_t})(-{ix} / ({sz} - 1)) + 1);
          }} else if ({ix} > ({sz} - 1)) {{
              {ix} -= ({sz} - 1) * ({int_t})({ix} / ({sz} - 1));
          }};""".format(
              ix=ix, sz=xsize, int_t=int_t
          )
      elif mode in ["constant", "grid-constant"]:
          ops = """
          if (({ix} < 0) || {ix} >= {xsize}) {{
              {ix} = -1;
          }}""".format(
              ix=ix, xsize=xsize
          )
      return ops
  
file_path: cupy/cupyx/scipy/ndimage/_util.py
imports: import warnings
  import numpy
  import cupy
label_desc: Use image node_id 10 for calling a global function with example usage: _generate_boundary_condition_ops(mode, ix, xsize, int_t, float_ix) and returns: ops