code: def _find_best_perm_by_exhaustive_method(
      metric_mtx: Tensor,
      eval_func: Callable,
  ) -> Tuple[Tensor, Tensor]:
      """Solves the linear sum assignment problem using exhaustive method.
  
      This is done by exhaustively calculating the metric values of all possible permutations, and returns the best metric
      values and the corresponding permutations.
  
      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]``
  
      """
      # create/read/cache the permutations and its indexes
      # reading from cache would be much faster than creating in CPU then moving to GPU
      batch_size, spk_num = metric_mtx.shape[:2]
      ps = _gen_permutations(
          spk_num=spk_num, device=metric_mtx.device
      )  # [perm_num, spk_num]
  
      # find the metric of each permutation
      perm_num = ps.shape[0]
      # shape of [batch_size, spk_num, perm_num]
      bps = ps.T[None, ...].expand(batch_size, spk_num, perm_num)
      # shape of [batch_size, spk_num, perm_num]
      metric_of_ps_details = torch.gather(metric_mtx, 2, bps)
      # shape of [batch_size, perm_num]
      metric_of_ps = metric_of_ps_details.mean(dim=1)
  
      # find the best metric and best permutation
      best_metric, best_indexes = eval_func(metric_of_ps, dim=1)
      best_indexes = best_indexes.detach()
      best_perm = ps[best_indexes, :]
      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 3 for calling a global function with example usage: _find_best_perm_by_exhaustive_method(metric_mtx, eval_func) and returns: best_metric,  best_perm