code: def connected_components(
      edgelist: Scores, max_components: int
  ) -> Generator[Scores, None, None]:
      if len(edgelist) == 0:
          raise StopIteration()
  
      unlabeled_edgelist = edgelist
  
      # we are going to keep track of the connected components
      # with another field in the record array of the edgelist.
      # unfortunately, it's not straightforward to add another
      # field to a memmapped record array so, we are going to
      # have to create a new memmapped array with all the fields
      # we want and copy things over.
      with tempfile.TemporaryDirectory() as path:
          filename = path + "/unlabeled_edgelist"
          edgelist = numpy.memmap(
              filename,
              dtype=(
                  unlabeled_edgelist.dtype.descr + [("label", "int32")]
              ),
              mode="w+",
              shape=unlabeled_edgelist.shape,
          )
  
          if hasattr(unlabeled_edgelist, "filename"):
              assert isinstance(unlabeled_edgelist, numpy.memmap)
              copy_mmap_record_arrays(
                  unlabeled_edgelist, edgelist, ["pairs", "score"]
              )
          else:
              copy_to_mmap_record_array(
                  unlabeled_edgelist, edgelist, ["pairs", "score"]
              )
  
          yield from _connected_components(edgelist, max_components)
  
          edgelist._mmap.close()
  
imports: from __future__ import annotations
  import array
  import itertools
  import logging
  import tempfile
  from collections import defaultdict
  from typing import Generator, Iterable, Sequence, cast
  import numpy
  import numpy.typing
  import scipy.cluster.hierarchy
  from dedupe._typing import ArrayLinks, Clusters, RecordID, Scores, TupleLinks
label_desc: Use image node_id 1 for calling a global function with example usage: connected_components(edgelist, max_components) without return types