code: 
  
  
  
  
  
  
  import unittest
  
  import numpy as np
  
  from transformers.testing_utils import require_torch, require_vision
  from transformers.utils import is_torch_available, is_vision_available
  
  from ...test_image_processing_common import ImageProcessingSavingTestMixin
  
  
  if is_torch_available():
   import torch
  
  if is_vision_available():
   from PIL import Image
  
   from transformers import TvltImageProcessor
  
  
  def 						_A     (       SCREAMING_SNAKE_CASE__						:			Optional[Any]  ,						SCREAMING_SNAKE_CASE__						:			str=10  ,						SCREAMING_SNAKE_CASE__						:			Tuple=10  ,						SCREAMING_SNAKE_CASE__						:			int=False  ,						SCREAMING_SNAKE_CASE__						:			Any=False ):
      UpperCamelCase :Any										=     []
      for i in range(image_processor_tester.num_frames ):
          video.append(np.random.randint(255  ,						size=(image_processor_tester.num_channels, width, height)  ,						dtype=np.uinta ) )
  
      if not numpify and not torchify:
          # PIL expects the channel dimension as last dimension
          UpperCamelCase :Optional[Any]										=     [Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE__  ,						0  ,						-1 ) ) for frame in video]
  
      if torchify:
          UpperCamelCase :Dict										=     [torch.from_numpy(SCREAMING_SNAKE_CASE__ ) for frame in video]
  
      return video
  
  
  def 						_A     (       SCREAMING_SNAKE_CASE__						:			Dict  ,						SCREAMING_SNAKE_CASE__						:			Dict=False  ,						SCREAMING_SNAKE_CASE__						:			Optional[Any]=False  ,						SCREAMING_SNAKE_CASE__						:			int=False ):
      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
      UpperCamelCase :str										=     []
      for i in range(image_processor_tester.batch_size ):
          if equal_resolution:
              UpperCamelCase :str										=     image_processor_tester.max_resolution
          else:
              UpperCamelCase							,     UpperCamelCase :List[str]										=     np.random.choice(
                  np.arange(image_processor_tester.min_resolution  ,						image_processor_tester.max_resolution )  ,						2 )
              UpperCamelCase :Optional[Any]										=     prepare_video(
                  image_processor_tester=SCREAMING_SNAKE_CASE__  ,						width=SCREAMING_SNAKE_CASE__  ,						height=SCREAMING_SNAKE_CASE__  ,						numpify=SCREAMING_SNAKE_CASE__  ,						torchify=SCREAMING_SNAKE_CASE__  ,						)
          video_inputs.append(SCREAMING_SNAKE_CASE__ )
  
      return video_inputs
  
  
  
  
  
  
  
  class     UpperCAmelCase_		(      unittest.TestCase				):
  
  
  
        """simple docstring"""
        def __init__(       self					,       SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_=7					,       SCREAMING_SNAKE_CASE_=3					,       SCREAMING_SNAKE_CASE_=4					,       SCREAMING_SNAKE_CASE_=18					,       SCREAMING_SNAKE_CASE_=30					,       SCREAMING_SNAKE_CASE_=400					,       SCREAMING_SNAKE_CASE_=True					,       SCREAMING_SNAKE_CASE_=None					,       SCREAMING_SNAKE_CASE_=True					,       SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5]					,       SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5]					,       SCREAMING_SNAKE_CASE_=True					,       SCREAMING_SNAKE_CASE_=None					,       )       ->   str:
            UpperCamelCase :List[str]										=     size if size is not None else {'''shortest_edge''': 18}
            UpperCamelCase :Optional[int]										=     crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
  
            UpperCamelCase :List[Any]										=     parent
            UpperCamelCase :Any										=     batch_size
            UpperCamelCase :List[str]										=     num_channels
            UpperCamelCase :int										=     num_frames
            UpperCamelCase :Any										=     image_size
            UpperCamelCase :Union[str, Any]										=     min_resolution
            UpperCamelCase :str										=     max_resolution
            UpperCamelCase :Any										=     do_resize
            UpperCamelCase :str										=     size
            UpperCamelCase :Union[str, Any]										=     do_normalize
            UpperCamelCase :str										=     image_mean
            UpperCamelCase :Tuple										=     image_std
            UpperCamelCase :Dict										=     do_center_crop
            UpperCamelCase :Any										=     crop_size
  
  
  
  
        def 					UpperCAmelCase		(       self				)       ->   Dict:
            return {
                "image_mean": self.image_mean,
                "image_std": self.image_std,
                "do_normalize": self.do_normalize,
                "do_resize": self.do_resize,
                "size": self.size,
                "do_center_crop": self.do_center_crop,
                "crop_size": self.crop_size,
            }
  
  
  
  
  
  
  
  @require_torch
  @require_vision
  class     UpperCAmelCase_		(      lowercase,			unittest.TestCase				):
  
  
  
        """simple docstring"""
        UpperCamelCase_       :      Any     =TvltImageProcessor if is_vision_available() else None
        def 					UpperCAmelCase		(       self				)       ->   Optional[Any]:
            UpperCamelCase :Optional[int]										=     TvltImageProcessorTester(self				)
        @property
        def 					UpperCAmelCase		(       self				)       ->   Optional[Any]:
            return self.image_processor_tester.prepare_image_processor_dict()
        def 					UpperCAmelCase		(       self				)       ->   int:
            UpperCamelCase :Dict										=     self.image_processing_class(**self.image_processor_dict				)
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''image_mean'''				)				)
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''image_std'''				)				)
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''do_normalize'''				)				)
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''do_resize'''				)				)
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''do_center_crop'''				)				)
            self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,       '''size'''				)				)
        def 					UpperCAmelCase		(       self				)       ->   List[Any]:
            # Initialize image_processor
            UpperCamelCase :List[str]										=     self.image_processing_class(**self.image_processor_dict				)
            # create random PIL videos
            UpperCamelCase :Tuple										=     prepare_video_inputs(self.image_processor_tester					,       equal_resolution=SCREAMING_SNAKE_CASE_				)
            for video in video_inputs:
                self.assertIsInstance(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				)
                self.assertIsInstance(video[0]					,       Image.Image				)
  
            # Test not batched input
            UpperCamelCase :List[Any]										=     image_processor(video_inputs[0]					,       return_tensors='''pt'''				).pixel_values
            self.assertEqual(
                encoded_videos.shape					,       (
                    1,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )					,       )
  
            # Test batched
            UpperCamelCase :List[Any]										=     image_processor(SCREAMING_SNAKE_CASE_					,       return_tensors='''pt'''				).pixel_values
            self.assertEqual(
                encoded_videos.shape					,       (
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )					,       )
        def 					UpperCAmelCase		(       self				)       ->   Union[str, Any]:
            # Initialize image_processor
            UpperCamelCase :List[Any]										=     self.image_processing_class(**self.image_processor_dict				)
            # create random numpy tensors
            UpperCamelCase :Dict										=     prepare_video_inputs(self.image_processor_tester					,       equal_resolution=SCREAMING_SNAKE_CASE_					,       numpify=SCREAMING_SNAKE_CASE_				)
            for video in video_inputs:
                self.assertIsInstance(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				)
                self.assertIsInstance(video[0]					,       np.ndarray				)
  
            # Test not batched input
            UpperCamelCase :Optional[Any]										=     image_processor(video_inputs[0]					,       return_tensors='''pt'''				).pixel_values
            self.assertEqual(
                encoded_videos.shape					,       (
                    1,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )					,       )
  
            # Test batched
            UpperCamelCase :Union[str, Any]										=     image_processor(SCREAMING_SNAKE_CASE_					,       return_tensors='''pt'''				).pixel_values
            self.assertEqual(
                encoded_videos.shape					,       (
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )					,       )
  
  
  
  
        def 					UpperCAmelCase		(       self				)       ->   Any:
            # Initialize image_processor
            UpperCamelCase :Optional[Any]										=     self.image_processing_class(**self.image_processor_dict				)
            # create random PyTorch tensors
            UpperCamelCase :List[str]										=     prepare_video_inputs(self.image_processor_tester					,       equal_resolution=SCREAMING_SNAKE_CASE_					,       torchify=SCREAMING_SNAKE_CASE_				)
            for video in video_inputs:
                self.assertIsInstance(SCREAMING_SNAKE_CASE_					,       SCREAMING_SNAKE_CASE_				)
                self.assertIsInstance(video[0]					,       torch.Tensor				)
  
            # Test not batched input
            UpperCamelCase :Optional[int]										=     image_processor(video_inputs[0]					,       return_tensors='''pt'''				).pixel_values
            self.assertEqual(
                encoded_videos.shape					,       (
                    1,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )					,       )
  
            # Test batched
            UpperCamelCase :Any										=     image_processor(SCREAMING_SNAKE_CASE_					,       return_tensors='''pt'''				).pixel_values
            self.assertEqual(
                encoded_videos.shape					,       (
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )					,       )
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  from __future__ import annotations
  
  from typing import Generic, TypeVar
  
  __snake_case							      =						TypeVar("""T""")
  
  
  
  
  
  
  
  class     UpperCAmelCase_		(      lowercase				):
  
  
  
        """simple docstring"""
        pass
  
  
  
  
  
  
  
  class     UpperCAmelCase_		(      lowercase				):
  
  
  
        """simple docstring"""
        pass
  
  
  
  
  
  
  
  class     UpperCAmelCase_		(      Generic[T]				):
  
  
  
        """simple docstring"""
        def __init__(       self					,       SCREAMING_SNAKE_CASE_ = 10				)       ->   List[str]:
            UpperCamelCase :list[T]										=     []
            UpperCamelCase :Any										=     limit
        def __bool__(       self				)       ->   bool:
            return bool(self.stack				)
        def __str__(       self				)       ->   str:
            return str(self.stack				)
        def 					UpperCAmelCase		(       self					,       SCREAMING_SNAKE_CASE_				)       ->   None:
            if len(self.stack				) >= self.limit:
                raise StackOverflowError
            self.stack.append(SCREAMING_SNAKE_CASE_				)
        def 					UpperCAmelCase		(       self				)       ->   T:
            if not self.stack:
                raise StackUnderflowError
            return self.stack.pop()
        def 					UpperCAmelCase		(       self				)       ->   T:
            if not self.stack:
                raise StackUnderflowError
            return self.stack[-1]
        def 					UpperCAmelCase		(       self				)       ->   bool:
            return not bool(self.stack				)
        def 					UpperCAmelCase		(       self				)       ->   bool:
            return self.size() == self.limit
        def 					UpperCAmelCase		(       self				)       ->   int:
            return len(self.stack				)
  
  
  
  
        def __contains__(       self					,       SCREAMING_SNAKE_CASE_				)       ->   bool:
            return item in self.stack
  
  
  
  
  
  
  
  def 						_A     (       ):
      UpperCamelCase :Stack[int]										=     Stack(10 )
      assert bool(SCREAMING_SNAKE_CASE__ ) is False
      assert stack.is_empty() is True
      assert stack.is_full() is False
      assert str(SCREAMING_SNAKE_CASE__ ) == "[]"
  
      try:
          UpperCamelCase :Optional[int]										=     stack.pop()
          raise AssertionError  # This should not happen
      except StackUnderflowError:
          assert True  # This should happen
  
      try:
          UpperCamelCase :Union[str, Any]										=     stack.peek()
          raise AssertionError  # This should not happen
      except StackUnderflowError:
          assert True  # This should happen
  
      for i in range(10 ):
          assert stack.size() == i
          stack.push(SCREAMING_SNAKE_CASE__ )
  
      assert bool(SCREAMING_SNAKE_CASE__ )
      assert not stack.is_empty()
      assert stack.is_full()
      assert str(SCREAMING_SNAKE_CASE__ ) == str(list(range(10 ) ) )
      assert stack.pop() == 9
      assert stack.peek() == 8
  
      stack.push(100 )
      assert str(SCREAMING_SNAKE_CASE__ ) == str([0, 1, 2, 3, 4, 5, 6, 7, 8, 100] )
  
      try:
          stack.push(200 )
          raise AssertionError  # This should not happen
      except StackOverflowError:
          assert True  # This should happen
  
      assert not stack.is_empty()
      assert stack.size() == 10
  
      assert 5 in stack
      assert 55 not in stack
  
  
  if __name__ == "__main__":
   test_stack()
  
  
  
  
  
  