docstr: Utility to test the uniform clip sampler
docstr_tok: ["Utility","to","test","the","uniform","clip","sampler"]
code: def test_uniform_clip_sampler(
      self,
      backpad_last: bool,
      fps: int,
      window_size: int,
      stride_frames: Optional[int],
      video_length: float,
      expected_number_of_clips: int,
  ):
      """
      Utility to test the uniform clip sampler
      """
      sampler = UniformClipSampler(
          window_size / fps,
          stride_frames / fps if stride_frames is not None else None,
          backpad_last=backpad_last,
      )
      predicted_n_clips = _num_clips(
          video_length,
          fps,
          stride_frames=stride_frames
          if stride_frames is not None
          else window_size,
          window_size_frames=window_size,
          backpad_last=backpad_last,
      )
      self.assertEqual(predicted_n_clips, expected_number_of_clips)
  
      s_prime = (
          stride_frames if stride_frames is not None else window_size
      )
      expected_start_end_times = [
          ((i * s_prime) / fps, ((i * s_prime + window_size) / fps))
          for i in range(expected_number_of_clips)
      ]
      if expected_start_end_times[-1][1] - video_length > 1e-6:
          expected_start_end_times[-1] = (
              video_length - window_size / fps,
              video_length,
          )
  
      self.assertTrue(
          (
              expected_start_end_times[-1][0] + (s_prime / fps)
              > video_length
              or expected_start_end_times[-1][-1] + (s_prime / fps)
              > video_length
          )
      )
      if len(expected_start_end_times) >= 2:
          self.assertNotAlmostEqual(
              expected_start_end_times[-2][0],
              expected_start_end_times[-1][0],
          )
          self.assertNotAlmostEqual(
              expected_start_end_times[-2][1],
              expected_start_end_times[-1][1],
          )
  
      start_end_times = []
  
      last_clip_time = None
      annotation = {}
      while True:
          clip = sampler(last_clip_time, video_length, annotation)
          last_clip_time = copy.deepcopy(clip.clip_end_sec)
          n_frames = (clip.clip_end_sec - clip.clip_start_sec) * fps
          int_n_frames = int(np.round(float(n_frames)))
          self.assertAlmostEqual(float(int_n_frames), float(n_frames))
          self.assertEqual(int_n_frames, window_size)
  
          start_end_times.append(
              (float(clip.clip_start_sec), float(clip.clip_end_sec))
          )
          if clip.is_last_clip:
              break
  
          # just in case we get an infinite loop
          if len(start_end_times) > 2 * expected_number_of_clips:
              break
  
      self.assertEqual(len(start_end_times), expected_number_of_clips)
      for (start, end), (expected_start, expected_end) in zip(
          start_end_times, expected_start_end_times
      ):
          self.assertAlmostEqual(float(start), expected_start)
          self.assertAlmostEqual(float(end), expected_end)
  
file_path: pytorchvideo/tests/test_uniform_clip_sampler.py
imports: import copy
  import unittest
  from typing import Optional
  import numpy
  from parameterized import parameterized
  from pytorchvideo.data.clip_sampling import UniformClipSampler
label_desc: Use image node_id 1 for calling the TestUniformClipSampler obj's underlying member method code with example usage: obj.test_uniform_clip_sampler(backpad_last, fps, window_size, stride_frames, video_length, expected_number_of_clips) without return types