code: def label(input, structure=None, output=None):
      """Labels features in an array.
  
      Args:
          input (cupy.ndarray): The input array.
          structure (array_like or None): A structuring element that defines
              feature connections. ```structure``` must be centersymmetric. If
              None, structure is automatically generated with a squared
              connectivity equal to one.
          output (cupy.ndarray, dtype or None): The array in which to place the
              output.
      Returns:
          label (cupy.ndarray): An integer array where each unique feature in
          ```input``` has a unique label in the array.
  
          num_features (int): Number of features found.
  
      .. warning::
  
          This function may synchronize the device.
  
      .. seealso:: :func:`scipy.ndimage.label`
      """
      if not isinstance(input, cupy.ndarray):
          raise TypeError("input must be cupy.ndarray")
      if input.dtype.char in "FD":
          raise TypeError("Complex type not supported")
      if structure is None:
          structure = _generate_binary_structure(input.ndim, 1)
      elif isinstance(structure, cupy.ndarray):
          structure = cupy.asnumpy(structure)
      structure = numpy.array(structure, dtype=bool)
      if structure.ndim != input.ndim:
          raise RuntimeError("structure and input must have equal rank")
      for i in structure.shape:
          if i != 3:
              raise ValueError(
                  "structure dimensions must be equal to 3"
              )
  
      if isinstance(output, cupy.ndarray):
          if output.shape != input.shape:
              raise ValueError("output shape not correct")
          caller_provided_output = True
      else:
          caller_provided_output = False
          if output is None:
              output = cupy.empty(input.shape, numpy.int32)
          else:
              output = cupy.empty(input.shape, output)
  
      if input.size == 0:
          # empty
          maxlabel = 0
      elif input.ndim == 0:
          # 0-dim array
          maxlabel = 0 if input.item() == 0 else 1
          output.fill(maxlabel)
      else:
          if output.dtype != numpy.int32:
              y = cupy.empty(input.shape, numpy.int32)
          else:
              y = output
          maxlabel = _label(input, structure, y)
          if output.dtype != numpy.int32:
              _core.elementwise_copy(y, output)
  
      if caller_provided_output:
          return maxlabel
      else:
          return output, maxlabel
  
imports: import warnings
  import numpy
  import cupy
  from cupy import _core
  from cupy import _util
label_desc: Use image node_id 1 for calling a global function with example usage: label(input, structure, output) and returns: maxlabel, output,  maxlabel