


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 			_lowercase (							unittest.TestCase):


       """simple docstring"""




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


             '''simple docstring'''



             lowerCamelCase__		:				Optional[int]    =  size if size is not None else {"shortest_edge": 18}
             lowerCamelCase__		:				int    =  crop_size if crop_size is not None else {"height": 18, "width": 18}

             lowerCamelCase__		:				Tuple    =  parent
             lowerCamelCase__		:				List[str]    =  batch_size
             lowerCamelCase__		:				Optional[Any]    =  num_channels
             lowerCamelCase__		:				str    =  num_frames
             lowerCamelCase__		:				List[Any]    =  image_size
             lowerCamelCase__		:				Optional[Any]    =  min_resolution
             lowerCamelCase__		:				Optional[int]    =  max_resolution
             lowerCamelCase__		:				Tuple    =  do_resize
             lowerCamelCase__		:				Union[str, Any]    =  size
             lowerCamelCase__		:				List[str]    =  do_normalize
             lowerCamelCase__		:				Tuple    =  image_mean
             lowerCamelCase__		:				List[str]    =  image_std
             lowerCamelCase__		:				List[Any]    =  crop_size





       def 						lowerCAmelCase     (   self							:			Optional[Any]       ):


             '''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 			_lowercase (							lowercase__							,  unittest.TestCase):


       """simple docstring"""




       A__											=			VivitImageProcessor if is_vision_available() else None





       def 						lowerCAmelCase     (   self							:			Optional[int]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Optional[Any]    =  VivitImageProcessingTester(self       )





       @property
       def 						lowerCAmelCase     (   self							:			List[Any]       ):


             '''simple docstring'''



             return self.image_processor_tester.prepare_image_processor_dict()





       def 						lowerCAmelCase     (   self							:			List[str]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Any    =  self.image_processing_class(**self.image_processor_dict       )
             self.assertTrue(hasattr(__lowerCamelCase					,      "image_mean"       )       )
             self.assertTrue(hasattr(__lowerCamelCase					,      "image_std"       )       )
             self.assertTrue(hasattr(__lowerCamelCase					,      "do_normalize"       )       )
             self.assertTrue(hasattr(__lowerCamelCase					,      "do_resize"       )       )
             self.assertTrue(hasattr(__lowerCamelCase					,      "do_center_crop"       )       )
             self.assertTrue(hasattr(__lowerCamelCase					,      "size"       )       )





       def 						lowerCAmelCase     (   self							:			Optional[int]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Optional[int]    =  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}       )

             lowerCamelCase__		:				Tuple    =  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 						lowerCAmelCase     (   self							:			List[str]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Optional[int]    =  self.image_processing_class(**self.image_processor_dict       )
             # create random PIL videos
             lowerCamelCase__		:				Any    =  prepare_video_inputs(self.image_processor_tester					,      equal_resolution=__lowerCamelCase       )
             for video in video_inputs:
                   self.assertIsInstance(__lowerCamelCase					,      __lowerCamelCase       )
                   self.assertIsInstance(video[0]					,      Image.Image       )

             # Test not batched input
             lowerCamelCase__		:				Optional[Any]    =  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
             lowerCamelCase__		:				List[str]    =  image_processing(__lowerCamelCase					,      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 						lowerCAmelCase     (   self							:			int       ):


             '''simple docstring'''



             lowerCamelCase__		:				List[str]    =  self.image_processing_class(**self.image_processor_dict       )
             # create random numpy tensors
             lowerCamelCase__		:				str    =  prepare_video_inputs(self.image_processor_tester					,      equal_resolution=__lowerCamelCase					,      numpify=__lowerCamelCase       )
             for video in video_inputs:
                   self.assertIsInstance(__lowerCamelCase					,      __lowerCamelCase       )
                   self.assertIsInstance(video[0]					,      np.ndarray       )

             # Test not batched input
             lowerCamelCase__		:				Any    =  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
             lowerCamelCase__		:				List[Any]    =  image_processing(__lowerCamelCase					,      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 						lowerCAmelCase     (   self							:			Optional[int]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Tuple    =  self.image_processing_class(**self.image_processor_dict       )
             # create random PyTorch tensors
             lowerCamelCase__		:				List[Any]    =  prepare_video_inputs(self.image_processor_tester					,      equal_resolution=__lowerCamelCase					,      torchify=__lowerCamelCase       )
             for video in video_inputs:
                   self.assertIsInstance(__lowerCamelCase					,      __lowerCamelCase       )
                   self.assertIsInstance(video[0]					,      torch.Tensor       )

             # Test not batched input
             lowerCamelCase__		:				Any    =  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
             lowerCamelCase__		:				Any    =  image_processing(__lowerCamelCase					,      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       lowercase_		(		_A			:    int    ,					_A			:    int						):

      """simple docstring"""




      while a != 0:
            lowerCamelCase__    ,   lowerCamelCase__		:				Optional[Any]    =  b % a, a
      return b


def       lowercase_		(		_A			:    int    ,					_A			:    int						):

      """simple docstring"""




      if gcd(_A    ,					_A						) != 1:
            lowerCamelCase__		:				List[str]    =  F"mod inverse of {a!r} and {m!r} does not exist"
            raise ValueError(_A						)
      lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__		:				Tuple    =  1, 0, a
      lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__		:				Optional[int]    =  0, 1, m
      while va != 0:
            lowerCamelCase__		:				Tuple    =  ua // va
            lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__		:				str    =  (ua - q * va), (ua - q * va), (ua - q * va), va, va, va
      return ua % m


