code: def _label(x, structure, y):
      elems = numpy.where(structure != 0)
      vecs = [elems[dm] - 1 for dm in range(x.ndim)]
      offset = vecs[0]
      for dm in range(1, x.ndim):
          offset = offset * 3 + vecs[dm]
      indxs = numpy.where(offset < 0)[0]
      dirs = [[vecs[dm][dr] for dm in range(x.ndim)] for dr in indxs]
      dirs = cupy.array(dirs, dtype=numpy.int32)
      ndirs = indxs.shape[0]
      y_shape = cupy.array(y.shape, dtype=numpy.int32)
      count = cupy.zeros(2, dtype=numpy.int32)
      _kernel_init()(x, y)
      _kernel_connect()(y_shape, dirs, ndirs, x.ndim, y, size=y.size)
      _kernel_count()(y, count, size=y.size)
      maxlabel = int(count[0])
      labels = cupy.empty(maxlabel, dtype=numpy.int32)
      _kernel_labels()(y, count, labels, size=y.size)
      _kernel_finalize()(maxlabel, cupy.sort(labels), y, size=y.size)
      return maxlabel
  
imports: import warnings
  import numpy
  import cupy
  from cupy import _core
  from cupy import _util
label_desc: Use image node_id 3 for calling a global function with example usage: _label(x, structure, y) and returns: maxlabel