






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_image_inputs


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import ViTImageProcessor




class 			snake_case__   (							unittest.TestCase):

       '''simple docstring'''



       def __init__(							self			,						a__			,						a__=13			,						a__=3			,						a__=2_24			,						a__=30			,						a__=4_00			,						a__=True			,						a__=None			,						a__=True			,						a__=[0.5, 0.5, 0.5]			,						a__=[0.5, 0.5, 0.5]			,						) ->      Dict:






            '''simple docstring'''





            __snake_case			:int          =						size if size is not None else {'height': 18, 'width': 18}
            __snake_case			:int          =						parent
            __snake_case			:int          =						batch_size
            __snake_case			:Tuple          =						num_channels
            __snake_case			:List[Any]          =						image_size
            __snake_case			:str          =						min_resolution
            __snake_case			:Optional[Any]          =						max_resolution
            __snake_case			:str          =						do_resize
            __snake_case			:Any          =						size
            __snake_case			:Any          =						do_normalize
            __snake_case			:Dict          =						image_mean
            __snake_case			:Optional[int]          =						image_std



       def 					__lowercase						(							self    ) ->      List[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,
            }




@require_torch
@require_vision
class 			snake_case__   (							snake_case__	,    unittest.TestCase):

       '''simple docstring'''
       lowerCamelCase							:				str 				= ViTImageProcessor if is_vision_available() else None



       def 					__lowercase						(							self    ) ->      List[Any]:






            '''simple docstring'''





            __snake_case			:str          =						EfficientFormerImageProcessorTester(self    )



       @property
       def 					__lowercase						(							self    ) ->      Tuple:






            '''simple docstring'''





            return self.image_proc_tester.prepare_image_processor_dict()



       def 					__lowercase						(							self    ) ->      Any:






            '''simple docstring'''





            __snake_case			:Tuple          =						self.image_processing_class(**self.image_processor_dict    )
            self.assertTrue(hasattr(_A			,						"""image_mean"""    )    )
            self.assertTrue(hasattr(_A			,						"""image_std"""    )    )
            self.assertTrue(hasattr(_A			,						"""do_normalize"""    )    )
            self.assertTrue(hasattr(_A			,						"""do_resize"""    )    )
            self.assertTrue(hasattr(_A			,						"""size"""    )    )



       def 					__lowercase						(							self    ) ->      int:






            '''simple docstring'''





            pass



       def 					__lowercase						(							self    ) ->      Optional[Any]:






            '''simple docstring'''





            __snake_case			:int          =						self.image_processing_class(**self.image_processor_dict    )
            # create random PIL images
            __snake_case			:Optional[Any]          =						prepare_image_inputs(self.image_proc_tester			,						equal_resolution=_A    )
            for image in image_inputs:
                 self.assertIsInstance(_A			,						Image.Image    )

            # Test not batched input
            __snake_case			:Tuple          =						image_processor(image_inputs[0]			,						return_tensors="""pt"""    ).pixel_values
            self.assertEqual(
                encoded_images.shape			,						(
                    1,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size["""height"""],
                    self.image_proc_tester.size["""width"""],
                )			,						)

            # Test batched
            __snake_case			:int          =						image_processor(_A			,						return_tensors="""pt"""    ).pixel_values
            self.assertEqual(
                encoded_images.shape			,						(
                    self.image_proc_tester.batch_size,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size["""height"""],
                    self.image_proc_tester.size["""width"""],
                )			,						)



       def 					__lowercase						(							self    ) ->      Optional[int]:






            '''simple docstring'''





            __snake_case			:List[Any]          =						self.image_processing_class(**self.image_processor_dict    )
            # create random numpy tensors
            __snake_case			:Union[str, Any]          =						prepare_image_inputs(self.image_proc_tester			,						equal_resolution=_A			,						numpify=_A    )
            for image in image_inputs:
                 self.assertIsInstance(_A			,						np.ndarray    )

            # Test not batched input
            __snake_case			:List[str]          =						image_processor(image_inputs[0]			,						return_tensors="""pt"""    ).pixel_values
            self.assertEqual(
                encoded_images.shape			,						(
                    1,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size["""height"""],
                    self.image_proc_tester.size["""width"""],
                )			,						)

            # Test batched
            __snake_case			:Union[str, Any]          =						image_processor(_A			,						return_tensors="""pt"""    ).pixel_values
            self.assertEqual(
                encoded_images.shape			,						(
                    self.image_proc_tester.batch_size,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size["""height"""],
                    self.image_proc_tester.size["""width"""],
                )			,						)



       def 					__lowercase						(							self    ) ->      List[Any]:






            '''simple docstring'''





            __snake_case			:Dict          =						self.image_processing_class(**self.image_processor_dict    )
            # create random PyTorch tensors
            __snake_case			:Optional[Any]          =						prepare_image_inputs(self.image_proc_tester			,						equal_resolution=_A			,						torchify=_A    )
            for image in image_inputs:
                 self.assertIsInstance(_A			,						torch.Tensor    )

            # Test not batched input
            __snake_case			:Union[str, Any]          =						image_processor(image_inputs[0]			,						return_tensors="""pt"""    ).pixel_values
            self.assertEqual(
                encoded_images.shape			,						(
                    1,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size["""height"""],
                    self.image_proc_tester.size["""width"""],
                )			,						)

            # Test batched
            __snake_case			:List[str]          =						image_processor(_A			,						return_tensors="""pt"""    ).pixel_values
            self.assertEqual(
                encoded_images.shape			,						(
                    self.image_proc_tester.batch_size,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size["""height"""],
                    self.image_proc_tester.size["""width"""],
                )			,						)










def   UpperCamelCase  (       snake_case__     :   str  ):




     '''simple docstring'''






     __snake_case			:List[Any]          =						hex_num.strip()
     if not hex_num:
          raise ValueError("""No value was passed to the function"""  )

     __snake_case			:str          =						hex_num[0] == """-"""
     if is_negative:
          __snake_case			:List[Any]          =						hex_num[1:]

     try:
          __snake_case			:Tuple          =						int(snake_case__	,16  )
     except ValueError:
          raise ValueError("""Invalid value was passed to the function"""  )

     __snake_case			:int          =						""""""
     while int_num > 0:
          __snake_case			:Optional[int]          =						str(int_num % 2  ) + bin_str
          int_num >>= 1

     return int(("""-""" + bin_str) if is_negative else bin_str  )


if __name__ == "__main__":
     import doctest

     doctest.testmod()


