'''simple docstring'''





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




    '''simple docstring'''







    def __init__(       self    ,							lowercase__    ,							lowercase__=13    ,							lowercase__=3    ,							lowercase__=224    ,							lowercase__=30    ,							lowercase__=400    ,							lowercase__=True    ,							lowercase__=None    ,							lowercase__=True    ,							lowercase__=[0.5, 0.5, 0.5]    ,							lowercase__=[0.5, 0.5, 0.5]    ,							)							-> List[str]:
         SCREAMING_SNAKE_CASE					:			int    	=       size if size is not None else {'height': 18, 'width': 18}
         SCREAMING_SNAKE_CASE					:			Tuple    	=       parent
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       batch_size
         SCREAMING_SNAKE_CASE					:			Any    	=       num_channels
         SCREAMING_SNAKE_CASE					:			Dict    	=       image_size
         SCREAMING_SNAKE_CASE					:			str    	=       min_resolution
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       max_resolution
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       do_resize
         SCREAMING_SNAKE_CASE					:			List[str]    	=       size
         SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       do_normalize
         SCREAMING_SNAKE_CASE					:			str    	=       image_mean
         SCREAMING_SNAKE_CASE					:			List[str]    	=       image_std






    def       _UpperCamelCase    (       self )							-> Tuple:
         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 				UpperCAmelCase (       _SCREAMING_SNAKE_CASE   ,    unittest.TestCase ):




    '''simple docstring'''







    snake_case__							:   int							=						ViTImageProcessor if is_vision_available() else None






    def       _UpperCamelCase    (       self )							-> Optional[int]:
         SCREAMING_SNAKE_CASE					:			Tuple    	=       EfficientFormerImageProcessorTester(self )






    @property
    def       _UpperCamelCase    (       self )							-> Optional[Any]:
         return self.image_proc_tester.prepare_image_processor_dict()






    def       _UpperCamelCase    (       self )							-> int:
         SCREAMING_SNAKE_CASE					:			List[str]    	=       self.image_processing_class(**self.image_processor_dict )
         self.assertTrue(hasattr(lowercase__    ,							'image_mean' ) )
         self.assertTrue(hasattr(lowercase__    ,							'image_std' ) )
         self.assertTrue(hasattr(lowercase__    ,							'do_normalize' ) )
         self.assertTrue(hasattr(lowercase__    ,							'do_resize' ) )
         self.assertTrue(hasattr(lowercase__    ,							'size' ) )






    def       _UpperCamelCase    (       self )							-> Optional[int]:
         pass






    def       _UpperCamelCase    (       self )							-> List[str]:
         # Initialize image_processor
         SCREAMING_SNAKE_CASE					:			Dict    	=       self.image_processing_class(**self.image_processor_dict )
         # create random PIL images
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       prepare_image_inputs(self.image_proc_tester    ,							equal_resolution=lowercase__ )
         for image in image_inputs:
              self.assertIsInstance(lowercase__    ,							Image.Image )

         # Test not batched input
         SCREAMING_SNAKE_CASE					:			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
         SCREAMING_SNAKE_CASE					:			str    	=       image_processor(lowercase__    ,							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    (       self )							-> List[Any]:
         # Initialize image_processor
         SCREAMING_SNAKE_CASE					:			int    	=       self.image_processing_class(**self.image_processor_dict )
         # create random numpy tensors
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       prepare_image_inputs(self.image_proc_tester    ,							equal_resolution=lowercase__    ,							numpify=lowercase__ )
         for image in image_inputs:
              self.assertIsInstance(lowercase__    ,							np.ndarray )

         # Test not batched input
         SCREAMING_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
         SCREAMING_SNAKE_CASE					:			List[str]    	=       image_processor(lowercase__    ,							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    (       self )							-> Tuple:
         # Initialize image_processor
         SCREAMING_SNAKE_CASE					:			List[str]    	=       self.image_processing_class(**self.image_processor_dict )
         # create random PyTorch tensors
         SCREAMING_SNAKE_CASE					:			Dict    	=       prepare_image_inputs(self.image_proc_tester    ,							equal_resolution=lowercase__    ,							torchify=lowercase__ )
         for image in image_inputs:
              self.assertIsInstance(lowercase__    ,							torch.Tensor )

         # Test not batched input
         SCREAMING_SNAKE_CASE					:			Optional[int]    	=       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
         SCREAMING_SNAKE_CASE					:			List[str]    	=       image_processor(lowercase__    ,							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'],
             )    ,							)




'''simple docstring'''





def     __lowerCAmelCase						(       a_       ,      a_		)      ->	str:





     '''simple docstring'''





     if number < 0 or shift_amount < 0:
          raise ValueError('both inputs must be positive integers'		)

     SCREAMING_SNAKE_CASE					:			str    	=       str(bin(a_		)		)
     binary_number += "0" * shift_amount
     return binary_number


def     __lowerCAmelCase						(       a_       ,      a_		)      ->	str:





     '''simple docstring'''





     if number < 0 or shift_amount < 0:
          raise ValueError('both inputs must be positive integers'		)

     SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       str(bin(a_		)		)[2:]
     if shift_amount >= len(a_		):
          return "0b0"
     SCREAMING_SNAKE_CASE					:			Dict    	=       binary_number[: len(a_		) - shift_amount]
     return "0b" + shifted_binary_number


def     __lowerCAmelCase						(       a_       ,      a_		)      ->	str:





     '''simple docstring'''





     if number >= 0:  # Get binary representation of positive number
          SCREAMING_SNAKE_CASE					:			Tuple    	=       '0' + str(bin(a_		)		).strip('-'		)[2:]
     else:  # Get binary (2's complement) representation of negative number
          SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       len(bin(a_		)[3:]		)  # Find 2's complement of number
          SCREAMING_SNAKE_CASE					:			Any    	=       bin(abs(a_		) - (1 << binary_number_length)		)[3:]
          SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       (
              '1' + '0' * (binary_number_length - len(a_		)) + binary_number
          )

     if shift_amount >= len(a_		):
          return "0b" + binary_number[0] * len(a_		)
     return (
         "0b"
         + binary_number[0] * shift_amount
         + binary_number[: len(a_		) - shift_amount]
     )


if __name__ == "__main__":
 import doctest

 doctest.testmod()



