





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, prepare_video_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import VivitImageProcessor





class  lowerCAmelCase							(       unittest.TestCase ):







  def __init__(      self  :str   ,							_lowercase  :Any   ,							_lowercase  :List[Any]=7   ,							_lowercase  :Optional[Any]=3   ,							_lowercase  :int=10   ,							_lowercase  :Tuple=18   ,							_lowercase  :Union[str, Any]=30   ,							_lowercase  :Any=4_00   ,							_lowercase  :List[str]=True   ,							_lowercase  :Union[str, Any]=None   ,							_lowercase  :str=True   ,							_lowercase  :Union[str, Any]=[0.5, 0.5, 0.5]   ,							_lowercase  :Any=[0.5, 0.5, 0.5]   ,							_lowercase  :Dict=None   ,							):






     '''simple docstring'''





     lowercase__			       =  size if size is not None else {"shortest_edge": 18}
     lowercase__			       =  crop_size if crop_size is not None else {"height": 18, "width": 18}

     lowercase__			       =  parent
     lowercase__			       =  batch_size
     lowercase__			       =  num_channels
     lowercase__			       =  num_frames
     lowercase__			       =  image_size
     lowercase__			       =  min_resolution
     lowercase__			       =  max_resolution
     lowercase__			       =  do_resize
     lowercase__			       =  size
     lowercase__			       =  do_normalize
     lowercase__			       =  image_mean
     lowercase__			       =  image_std
     lowercase__			       =  crop_size







  def   UpperCAmelCase					(      self  :int ):






     '''simple docstring'''





     return {
         "image_mean": self.image_mean,
         "image_std": self.image_std,
         "do_normalize": self.do_normalize,
         "do_resize": self.do_resize,
         "size": self.size,
         "crop_size": self.crop_size,
     }





@require_torch
@require_vision
class  lowerCAmelCase							(       __SCREAMING_SNAKE_CASE							,							unittest.TestCase ):
  __lowerCamelCase		=      VivitImageProcessor if is_vision_available() else None







  def   UpperCAmelCase					(      self  :int ):






     '''simple docstring'''





     lowercase__			       =  VivitImageProcessingTester(self )







  @property
  def   UpperCAmelCase					(      self  :int ):






     '''simple docstring'''





     return self.image_processor_tester.prepare_image_processor_dict()







  def   UpperCAmelCase					(      self  :List[Any] ):






     '''simple docstring'''





     lowercase__			       =  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  :Any ):






     '''simple docstring'''





     lowercase__			       =  self.image_processing_class.from_dict(self.image_processor_dict )
     self.assertEqual(image_processor.size   ,							{"shortest_edge": 18} )
     self.assertEqual(image_processor.crop_size   ,							{"height": 18, "width": 18} )

     lowercase__			       =  self.image_processing_class.from_dict(self.image_processor_dict   ,							size=42   ,							crop_size=84 )
     self.assertEqual(image_processor.size   ,							{"shortest_edge": 42} )
     self.assertEqual(image_processor.crop_size   ,							{"height": 84, "width": 84} )







  def   UpperCAmelCase					(      self  :int ):






     '''simple docstring'''





     lowercase__			       =  self.image_processing_class(**self.image_processor_dict )
     # create random PIL videos
     lowercase__			       =  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
     lowercase__			       =  image_processing(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
     lowercase__			       =  image_processing(_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  :List[str] ):






     '''simple docstring'''





     lowercase__			       =  self.image_processing_class(**self.image_processor_dict )
     # create random numpy tensors
     lowercase__			       =  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
     lowercase__			       =  image_processing(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
     lowercase__			       =  image_processing(_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  :Dict ):






     '''simple docstring'''





     lowercase__			       =  self.image_processing_class(**self.image_processor_dict )
     # create random PyTorch tensors
     lowercase__			       =  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
     lowercase__			       =  image_processing(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
     lowercase__			       =  image_processing(_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 _A       (   __magic_name__  , __magic_name__  , __magic_name__  , __magic_name__	):
   if height >= 1:
      move_tower(height - 1  , __magic_name__  , __magic_name__  , __magic_name__	)
      move_disk(__magic_name__  , __magic_name__	)
      move_tower(height - 1  , __magic_name__  , __magic_name__  , __magic_name__	)


def _A       (   __magic_name__  , __magic_name__	):
   print("moving disk from"  , __magic_name__  , "to"  , __magic_name__	)


def _A       (   ):
   lowercase__			       =  int(input("Height of hanoi: "	).strip()	)
   move_tower(__magic_name__  , "A"  , "B"  , "C"	)


if __name__ == "__main__":
  main()






