docstr: sinusoidal waveform is properly compressed by factor
docstr_tok: ["sinusoidal","waveform","is","properly","compressed","by","factor"]
code: def test_speed_accuracy(self, factor, use_lengths):
      """sinusoidal waveform is properly compressed by factor"""
      n_to_trim = 20
  
      sample_rate = 1000
      freq = 2
      times = torch.arange(0, 5, 1.0 / sample_rate)
      waveform = (
          torch.cos(2 * math.pi * freq * times)
          .unsqueeze(0)
          .to(self.device, self.dtype)
      )
  
      if use_lengths:
          lengths = torch.tensor([waveform.size(1)])
      else:
          lengths = None
  
      speed = T.Speed(sample_rate, factor).to(self.device, self.dtype)
      output, output_lengths = speed(waveform, lengths)
  
      if use_lengths:
          self.assertEqual(output.size(1), output_lengths[0])
      else:
          self.assertEqual(None, output_lengths)
  
      new_times = torch.arange(0, 5 / factor, 1.0 / sample_rate)
      expected_waveform = (
          torch.cos(2 * math.pi * freq * factor * new_times)
          .unsqueeze(0)
          .to(self.device, self.dtype)
      )
  
      self.assertEqual(
          expected_waveform[..., n_to_trim:-n_to_trim],
          output[..., n_to_trim:-n_to_trim],
          atol=1e-1,
          rtol=1e-4,
      )
  
imports: import math
  import random
  from unittest.mock import patch
  import numpy
  import torch
  import torchaudio.transforms
  from parameterized import param, parameterized
  from scipy import signal
  from torchaudio.functional import lfilter, preemphasis
  from torchaudio.functional.functional import _get_sinc_resample_kernel
  from torchaudio_unittest.common_utils import get_spectrogram, get_whitenoise, nested_params, TestBaseMixin
  from torchaudio_unittest.common_utils.psd_utils import psd_numpy
label_desc: Use image node_id 11 for calling the TransformsTestBase obj's underlying member method code with example usage: obj.test_speed_accuracy(factor, use_lengths) without return types