code: def _find_best_perm_by_linear_sum_assignment(
      metric_mtx: Tensor,
      eval_func: Callable,
  ) -> Tuple[Tensor, Tensor]:
      """Solves the linear sum assignment problem.
  
      This implementation uses scipy and input is therefore transferred to cpu during calculations.
  
      Args:
          metric_mtx: the metric matrix, shape [batch_size, spk_num, spk_num]
          eval_func: the function to reduce the metric values of different the permutations
  
      Returns:
          best_metric: shape ``[batch]``
          best_perm: shape ``[batch, spk]``
  
      """
      from scipy.optimize import linear_sum_assignment
  
      mmtx = metric_mtx.detach().cpu()
      best_perm = torch.tensor(
          np.array(
              [
                  linear_sum_assignment(pwm, eval_func == torch.max)[1]
                  for pwm in mmtx
              ]
          )
      )
      best_perm = best_perm.to(metric_mtx.device)
      best_metric = torch.gather(
          metric_mtx, 2, best_perm[:, :, None]
      ).mean([-1, -2])
      return best_metric, best_perm
  
file_path: torchmetrics/src/torchmetrics/functional/audio/pit.py
imports: from itertools import permutations
  from typing import Any, Callable, Tuple
  import numpy
  import torch
  from torch import Tensor
  from typing_extensions import Literal
  from torchmetrics.utilities import rank_zero_warn
  from torchmetrics.utilities.imports import _SCIPY_AVAILABLE
label_desc: Use image node_id 2 for calling a global function with example usage: _find_best_perm_by_linear_sum_assignment(metric_mtx, eval_func) and returns: best_metric,  best_perm