docstr: Test metric on batches where examples have different length.
          
docstr_tok: ["Test","metric","on","batches","where","examples","have","different","length","."]
code: def test_input_length(self):
      """Test metric on batches where examples have different length."""
      ref_metric = SignalNoiseRatio()
      wrapped_metric = AudioMetricWrapper(metric=SignalNoiseRatio())
  
      num_resets = 5
      num_batches = 10
      batch_size = 8
      num_channels = 2
      num_samples = 200
  
      batch_shape = (batch_size, num_channels, num_samples)
  
      for nr in range(num_resets):
          for nb in range(num_batches):
              target = torch.rand(*batch_shape)
              preds = target + torch.rand(1) * torch.rand(*batch_shape)
  
              input_length = torch.randint(
                  low=num_samples // 2,
                  high=num_samples,
                  size=(batch_size,),
              )
  
              # test forward for a single batch
              batch_value_wrapped = wrapped_metric(
                  preds=preds, target=target, input_length=input_length
              )
  
              # compute reference value, assuming batch reduction using averaging
              batch_value_ref = 0
              for b_idx, b_len in enumerate(input_length):
                  batch_value_ref += ref_metric(
                      preds=preds[b_idx, ..., :b_len],
                      target=target[b_idx, ..., :b_len],
                  )
              batch_value_ref /= batch_size  # average
  
              assert torch.allclose(
                  batch_value_wrapped, batch_value_ref
              ), f"Metric forward not matching for batch {nb}, reset {nr}"
  
          # test compute (over num_batches)
          assert torch.allclose(
              wrapped_metric.compute(), ref_metric.compute()
          ), f"Metric compute not matching for batch {nb}, reset {nr}"
  
          ref_metric.reset()
          wrapped_metric.reset()
  
imports: import dataclasses
  import io
  import random
  import string
  from copy import deepcopy
  from typing import List
  from unittest.mock import Mock, patch
  import pytest
  import torch
  from torchmetrics.audio.snr import SignalNoiseRatio
  from nemo.collections.asr.metrics.audio import AudioMetricWrapper
  from nemo.collections.asr.metrics.wer import WER, word_error_rate, word_error_rate_detail, word_error_rate_per_utt
  from nemo.collections.asr.parts.submodules.ctc_decoding import CTCBPEDecoding, CTCBPEDecodingConfig, CTCDecoding, CTCDecodingConfig
  from nemo.collections.asr.parts.submodules.rnnt_decoding import RNNTBPEDecoding, RNNTDecoding
  from nemo.collections.asr.parts.utils.rnnt_utils import Hypothesis
  from nemo.collections.common.tokenizers import CharTokenizer
  from nemo.utils.config_utils import assert_dataclass_signature_match
label_desc: Use image node_id 2 for calling the TestAudioMetricWrapper obj's underlying member method code with example usage: obj.test_input_length() without return types