code: def stitch_cluster_labels(
      Y_old: torch.Tensor, Y_new: torch.Tensor
  ) -> torch.Tensor:
      """
      Run Hungarian (linear sum assignment) algorithm to find the best permutation mapping between
      the cumulated labels in history and the new clustering output labels.
  
      Args:
          Y_old (Tensor):
              Cumulated diarization labels. This will be concatenated with history embedding speaker label
              then compared with the predicted label Y_new.
          Y_new (Tensor):
              Contains predicted labels for reduced history embeddings concatenated with the predicted label.
              Permutation is not matched yet.
  
      Returns:
          mapping_array[Y] (Tensor):
              An output numpy array where the input Y_new is mapped with mapping_array.
      """
      Y_new = get_minimal_indices(Y_new)
      if len(Y_old) == 0:
          matched_output = Y_new
      else:
          P_raw, Q_raw = Y_old.to(Y_new.device), Y_new
          U_set = torch.unique(torch.cat([P_raw, Q_raw]))
          PQ = torch.cat([P_raw, Q_raw])
          a_cat_b, counts = torch.unique(PQ, return_counts=True)
          # Get a union set of old P and new Q labels
          PandQ = a_cat_b[torch.where(counts.gt(1))[0]]
          min_len = min(P_raw.shape[0], Q_raw.shape[0])
          P, Q = P_raw[:min_len], Q_raw[:min_len]
  
          if len(U_set) == 1:
              # When two speaker vectors are exactly the same: No need to encode.
              mapping_array = torch.tensor([0, 0]).to(Y_new.device)
          else:
              # Run Hungarian algorithm if there are more than one speaker in universal set U.
              mapping_array = get_lsa_speaker_mapping(
                  U_set=U_set, cmm_P=P, cmm_Q=Q, PandQ=PandQ
              )
          matched_output = mapping_array[Y_new]
      matched_output = get_minimal_indices(matched_output)
      return matched_output
  
imports: from typing import List, Tuple
  import torch
  from nemo.collections.asr.parts.utils.offline_clustering import NMESC, SpeakerClustering, SpectralClustering, get_scale_interpolated_embs, getAffinityGraphMat, getCosAffinityMatrix, split_input_data
  from nemo.collections.asr.parts.utils.optimization_utils import linear_sum_assignment
label_desc: Use image node_id 3 for calling a global function with example usage: stitch_cluster_labels(Y_old, Y_new) and returns: matched_output