code: def get_lsa_speaker_mapping(
      U_set: torch.Tensor,
      cmm_P: torch.Tensor,
      cmm_Q: torch.Tensor,
      PandQ: torch.Tensor,
  ) -> torch.Tensor:
      """
      Find a mapping that minimizes the matching cost between the label P and Q.
      One-hot encodding is employed to represent sequence and calculate the cost.
  
      Args:
          U_set (list):
              Whole set of the estimated speakers
          cmm_P (Tensor):
              Length-matched old sequence
          cmm_Q (Tensor):
              Length-matched new sequence
          PandQ (Tensor):
              Tensor containing the indices of the speakers that are in both old and new sequences
  
      Returns:
          mapping_array (np.array):
              Mapped labels that minimizes the cost
      """
      all_spks_labels = [[x] for x in range(len(U_set))]
      common_inds: List[int] = [int(x.item()) for x in PandQ]
  
      # Create tensors for one-hot encoding
      enc_P = torch.zeros((len(cmm_P), len(all_spks_labels))).to(
          cmm_P.device
      )
      enc_Q = torch.zeros((len(cmm_Q), len(all_spks_labels))).to(
          cmm_Q.device
      )
  
      # Create one-hot encoding
      enc_P[torch.arange(len(cmm_P)), cmm_P] = 1
      enc_Q[torch.arange(len(cmm_Q)), cmm_Q] = 1
  
      # Cost matrix from one-hot encoding vectors
      cost = -1 * torch.matmul(enc_P.T, enc_Q).T.to(PandQ.device)
      _, col_ind = linear_sum_assignment(cost)
  
      # If number of are speakers in each vector is not the same
      mapping_array = torch.arange(0, len(U_set)).to(PandQ.device)
      for x in range(col_ind.shape[0]):
          if x not in common_inds:
              mapping_array[x] = x
          else:
              mapping_array[x] = col_ind[x]
      return mapping_array
  
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 1 for calling a global function with example usage: get_lsa_speaker_mapping(U_set, cmm_P, cmm_Q, PandQ) and returns: mapping_array