code: def _kernel_finalize():
      return _core.ElementwiseKernel(
          "int32 maxlabel",
          "raw int32 labels, raw Y y",
          """
          if (y[i] < 0) {
              y[i] = 0;
              continue;
          }
          int yi = y[i];
          int j_min = 0;
          int j_max = maxlabel - 1;
          int j = (j_min + j_max) / 2;
          while (j_min < j_max) {
              if (yi == labels[j]) break;
              if (yi < labels[j]) j_max = j - 1;
              else j_min = j + 1;
              j = (j_min + j_max) / 2;
          }
          y[i] = j + 1;
          """,
          "cupyx_scipy_ndimage_label_finalize",
      )
  
imports: import warnings
  import numpy
  import cupy
  from cupy import _core
  from cupy import _util
label_desc: Use image node_id 8 for calling a global function with example usage: _kernel_finalize() and returns: _core