code: def sdr(
      estimate: torch.Tensor,
      reference: torch.Tensor,
      mask: Optional[torch.Tensor] = None,
      epsilon: float = 1e-8,
  ) -> torch.Tensor:
      """Computes source-to-distortion ratio.
  
      1. scale the reference signal with power(s_est * s_ref) / powr(s_ref * s_ref)
      2. compute SNR between adjusted estimate and reference.
  
      Args:
          estimate (torch.Tensor): Estimtaed signal.
              Shape: [batch, speakers (can be 1), time frame]
          reference (torch.Tensor): Reference signal.
              Shape: [batch, speakers, time frame]
          mask (torch.Tensor or None, optional): Binary mask to indicate padded value (0) or valid value (1).
              Shape: [batch, 1, time frame]
          epsilon (float, optional): constant value used to stabilize division.
  
      Returns:
          torch.Tensor: scale-invariant source-to-distortion ratio.
          Shape: [batch, speaker]
  
      References:
          - Single-channel multi-speaker separation using deep clustering
            Y. Isik, J. Le Roux, Z. Chen, S. Watanabe, and J. R. Hershey,
          - Conv-TasNet: Surpassing Ideal Time--Frequency Magnitude Masking for Speech Separation
            Luo, Yi and Mesgarani, Nima
            https://arxiv.org/abs/1809.07454
  
      Notes:
          This function is tested to produce the exact same result as
          https://github.com/naplab/Conv-TasNet/blob/e66d82a8f956a69749ec8a4ae382217faa097c5c/utility/sdr.py#L34-L56
      """
      reference_pow = reference.pow(2).mean(axis=2, keepdim=True)
      mix_pow = (estimate * reference).mean(axis=2, keepdim=True)
      scale = mix_pow / (reference_pow + epsilon)
  
      reference = scale * reference
      error = estimate - reference
  
      reference_pow = reference.pow(2)
      error_pow = error.pow(2)
  
      if mask is None:
          reference_pow = reference_pow.mean(axis=2)
          error_pow = error_pow.mean(axis=2)
      else:
          denom = mask.sum(axis=2)
          reference_pow = (mask * reference_pow).sum(axis=2) / denom
          error_pow = (mask * error_pow).sum(axis=2) / denom
  
      return 10 * torch.log10(reference_pow) - 10 * torch.log10(
          error_pow
      )
  
file_path: audio/examples/source_separation/utils/metrics.py
imports: import math
  from itertools import permutations
  from typing import Optional
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: sdr(estimate, reference, mask, epsilon) and returns: unknown