code: def naive_implementation_pit_scipy(
      preds: Tensor,
      target: Tensor,
      metric_func: Callable,
      eval_func: str,
  ) -> Tuple[Tensor, Tensor]:
      """Naive implementation of `Permutation Invariant Training` based on Scipy.
  
      Args:
          preds: predictions, shape[batch, spk, time]
          target: targets, shape[batch, spk, time]
          metric_func: which metric
          eval_func: min or max
  
      Returns:
          best_metric:
              shape [batch]
          best_perm:
              shape [batch, spk]
  
      """
      batch_size, spk_num = target.shape[0:2]
      metric_mtx = torch.empty(
          (batch_size, spk_num, spk_num), device=target.device
      )
      for t in range(spk_num):
          for e in range(spk_num):
              metric_mtx[:, t, e] = metric_func(
                  preds[:, e, ...], target[:, t, ...]
              )
  
      metric_mtx = metric_mtx.detach().cpu().numpy()
      best_metrics = []
      best_perms = []
      for b in range(batch_size):
          row_idx, col_idx = linear_sum_assignment(
              metric_mtx[b, ...], eval_func == "max"
          )
          best_metrics.append(metric_mtx[b, row_idx, col_idx].mean())
          best_perms.append(col_idx)
      return torch.from_numpy(np.stack(best_metrics)), torch.from_numpy(
          np.stack(best_perms)
      )
  
imports: from functools import partial
  from typing import Callable, Tuple
  import numpy
  import pytest
  import torch
  from scipy.optimize import linear_sum_assignment
  from torch import Tensor
  from torchmetrics.audio import PermutationInvariantTraining
  from torchmetrics.functional.audio import permutation_invariant_training, scale_invariant_signal_distortion_ratio, signal_noise_ratio
  from torchmetrics.functional.audio.pit import _find_best_perm_by_exhaustive_method, _find_best_perm_by_linear_sum_assignment
  from unittests import BATCH_SIZE, NUM_BATCHES, _Input
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester
label_desc: Use image node_id 1 for calling a global function with example usage: naive_implementation_pit_scipy(preds, target, metric_func, eval_func) and returns: torch,  torch