docstr: Test SDR calculation with weighting for channels
          
docstr_tok: ["Test","SDR","calculation","with","weighting","for","channels"]
code: def test_sdr_weighted(self, num_channels: int):
      """Test SDR calculation with weighting for channels"""
      batch_size = 8
      num_samples = 50
      num_batches = 10
      random_seed = 42
      atol = 1e-6
  
      _rng = np.random.default_rng(seed=random_seed)
  
      channel_weight = _rng.uniform(
          low=0.01, high=1.0, size=num_channels
      )
      channel_weight = channel_weight / np.sum(channel_weight)
      sdr_loss = SDRLoss(weight=channel_weight)
  
      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.001, high=10) * _rng.normal(
              size=target.shape
          )
          # Estimate
          estimate = target + noise
  
          # Tensors for testing the loss
          tensor_estimate = torch.tensor(estimate)
          tensor_target = torch.tensor(target)
  
          # Reference SDR
          golden_sdr = 0
          for b in range(batch_size):
              sdr = [
                  calculate_sdr_numpy(
                      estimate=estimate[b, m, :], target=target[b, m, :]
                  )
                  for m in range(num_channels)
              ]
              # weighted sum
              sdr = np.sum(np.array(sdr) * channel_weight)
              golden_sdr += sdr
          golden_sdr /= batch_size  # average over batch
  
          # Calculate SDR
          uut_sdr_loss = sdr_loss(
              estimate=tensor_estimate, target=tensor_target
          )
  
          # Compare
          assert np.allclose(
              uut_sdr_loss.cpu().detach().numpy(),
              -golden_sdr,
              atol=atol,
          ), f"SDRLoss not matching for example {n}"
  
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 2 for calling the TestAudioLosses obj's underlying member method code with example usage: obj.test_sdr_weighted(num_channels) without return types