code: def getTheLargestComponent(
      affinity_mat: torch.Tensor, seg_index: int, device: torch.device
  ) -> torch.Tensor:
      """
      Find the largest affinity_mat connected components for each given node.
      This is for checking whether the affinity_mat is fully connected.
  
      Args:
          affinity_mat (Tensor):
              A square matrix (tensor) containing normalized cosine distance values
          seg_index (int):
              The segment index that is targeted to be explored.
  
      Returns:
          connected_nodes (Tensor):
              A tensor containing booleans that indicate whether the node is connected.
      """
      num_of_segments = affinity_mat.shape[0]
  
      connected_nodes = torch.zeros(
          num_of_segments, dtype=torch.bool
      ).to(device)
      nodes_to_explore = torch.zeros(
          num_of_segments, dtype=torch.bool
      ).to(device)
  
      nodes_to_explore[seg_index] = True
      nodes_to_explore = nodes_to_explore.to(device)
      for k in range(num_of_segments):
          last_num_component = connected_nodes.sum()
          torch.logical_or(
              connected_nodes, nodes_to_explore, out=connected_nodes
          )
          if last_num_component >= connected_nodes.sum():
              break
  
          indices = (
              (nodes_to_explore == torch.tensor(True))
              .nonzero()
              .t()
              .squeeze()
          )
          if len(indices.size()) == 0:
              indices = indices.unsqueeze(0)
          for i in indices:
              neighbors = affinity_mat[i].to(device)
              torch.logical_or(
                  nodes_to_explore,
                  neighbors.squeeze(0),
                  out=nodes_to_explore,
              )
      return connected_nodes
  
imports: from typing import Dict, List, Tuple
  import torch
  from torch.linalg import eigh, eigvalsh
label_desc: Use image node_id 6 for calling a global function with example usage: getTheLargestComponent(affinity_mat, seg_index, device) and returns: connected_nodes