docstr: Test SDR calculation
          
docstr_tok: ["Test","SDR","calculation"]
code: def test_sdr(self, num_channels: int):
      """Test SDR calculation"""
      test_eps = [0, 1e-16, 1e-1]
      batch_size = 8
      num_samples = 50
      num_batches = 10
      random_seed = 42
      atol = 1e-6
  
      _rng = np.random.default_rng(seed=random_seed)
  
      for remove_mean in [True, False]:
          for eps in test_eps:
              sdr_loss = SDRLoss(eps=eps, remove_mean=remove_mean)
  
              for n in range(num_batches):
                  # Generate random signal
                  target = _rng.normal(
                      size=(batch_size, num_channels, num_samples)
                  )
                  # Random noise + scaling
                  noise = _rng.uniform(low=0.01, high=1) * _rng.normal(
                      size=(batch_size, num_channels, num_samples)
                  )
                  # Estimate
                  estimate = target + noise
  
                  # DC bias for both
                  target += _rng.uniform(low=-1, high=1)
                  estimate += _rng.uniform(low=-1, high=1)
  
                  # Tensors for testing the loss
                  tensor_estimate = torch.tensor(estimate)
                  tensor_target = torch.tensor(target)
  
                  # Reference SDR
                  golden_sdr = np.zeros((batch_size, num_channels))
                  for b in range(batch_size):
                      for m in range(num_channels):
                          golden_sdr[b, m] = calculate_sdr_numpy(
                              estimate=estimate[b, m, :],
                              target=target[b, m, :],
                              remove_mean=remove_mean,
                              eps=eps,
                          )
  
                  # Calculate SDR in torch
                  uut_sdr = calculate_sdr_batch(
                      estimate=tensor_estimate,
                      target=tensor_target,
                      remove_mean=remove_mean,
                      eps=eps,
                  )
  
                  # Calculate SDR loss
                  uut_sdr_loss = sdr_loss(
                      estimate=tensor_estimate, target=tensor_target
                  )
  
                  # Compare torch SDR vs numpy
                  assert np.allclose(
                      uut_sdr.cpu().detach().numpy(),
                      golden_sdr,
                      atol=atol,
                  ), f"SDR not matching for example {n}, eps={eps}, remove_mean={remove_mean}"
  
                  # Compare SDR loss vs average of torch SDR
                  assert np.isclose(
                      uut_sdr_loss, -uut_sdr.mean(), atol=atol
                  ), f"SDRLoss not matching for example {n}, eps={eps}, remove_mean={remove_mean}"
  
file_path: NeMo/tests/collections/asr/test_asr_losses.py
imports: import numpy
  import pytest
  import torch
  from nemo.collections.asr.losses.audio_losses import SDRLoss, calculate_sdr_batch, convolution_invariant_target, scale_invariant_target
  from nemo.collections.asr.parts.utils.audio_utils import calculate_sdr_numpy, convolution_invariant_target_numpy, scale_invariant_target_numpy
label_desc: Use image node_id 1 for calling the TestAudioLosses obj's underlying member method code with example usage: obj.test_sdr(num_channels) without return types