code: 
  
  A_		:			Union[str, Any]										=   {
      '0000': '0',
      '0001': '1',
      '0010': '2',
      '0011': '3',
      '0100': '4',
      '0101': '5',
      '0110': '6',
      '0111': '7',
      '1000': '8',
      '1001': '9',
      '1010': 'a',
      '1011': 'b',
      '1100': 'c',
      '1101': 'd',
      '1110': 'e',
      '1111': 'f',
  }
  
  
  def       __a       (   SCREAMING_SNAKE_CASE      )      ->     str:
  
  
  
  
  
  
      '''simple docstring'''
      __UpperCAmelCase									=			str(SCREAMING_SNAKE_CASE      ).strip()
  
      # Exceptions
      if not binary_str:
          raise ValueError('''Empty string was passed to the function'''      )
      __UpperCAmelCase									=			binary_str[0] == '''-'''
      __UpperCAmelCase									=			binary_str[1:] if is_negative else binary_str
      if not all(char in '''01''' for char in binary_str      ):
          raise ValueError('''Non-binary value was passed to the function'''      )
  
      __UpperCAmelCase									=			(
          '''0''' * (4 * (divmod(len(SCREAMING_SNAKE_CASE      )       ,   4      )[0] + 1) - len(SCREAMING_SNAKE_CASE      )) + binary_str
      )
  
      __UpperCAmelCase									=			[]
      for x in range(0       ,   len(SCREAMING_SNAKE_CASE      )       ,   4      ):
          hexadecimal.append(BITS_TO_HEX[binary_str[x : x + 4]]      )
      __UpperCAmelCase									=			'''0x''' + ''''''.join(SCREAMING_SNAKE_CASE      )
  
      return "-" + hexadecimal_str if is_negative else hexadecimal_str
  
  
  if __name__ == "__main__":
         from doctest import testmod
  
         testmod()
  
  
  
  
  
style_context: 
  
  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 SwinaSRImageProcessor
         from transformers.image_transforms import get_image_size
  class 					A_   (      unittest.TestCase						):
  
  
      '''simple docstring'''
  
  
  
  
  
  
      def __init__(self     ,      lowercase__     ,      lowercase__=7     ,      lowercase__=3     ,      lowercase__=18     ,      lowercase__=30     ,      lowercase__=400     ,      lowercase__=True     ,      lowercase__=1 / 255     ,      lowercase__=True     ,      lowercase__=8     ,      )     ->      List[str]:
          __UpperCAmelCase									=			parent
          __UpperCAmelCase									=			batch_size
          __UpperCAmelCase									=			num_channels
          __UpperCAmelCase									=			image_size
          __UpperCAmelCase									=			min_resolution
          __UpperCAmelCase									=			max_resolution
          __UpperCAmelCase									=			do_rescale
          __UpperCAmelCase									=			rescale_factor
          __UpperCAmelCase									=			do_pad
          __UpperCAmelCase									=			pad_size
  
  
      def      lowerCAmelCase_						(self  )     ->      int:
          return {
              "do_rescale": self.do_rescale,
              "rescale_factor": self.rescale_factor,
              "do_pad": self.do_pad,
              "pad_size": self.pad_size,
          }
  
  
  
  
  
  
      def      lowerCAmelCase_						(self     ,      lowercase__=False     ,      lowercase__=False     ,      lowercase__=False  )     ->      Tuple:
          assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
          if equal_resolution:
              __UpperCAmelCase									=			[]
              for i in range(self.batch_size  ):
                  image_inputs.append(
                      np.random.randint(
                          255     ,      size=(self.num_channels, self.max_resolution, self.max_resolution)     ,      dtype=np.uinta  )  )
          else:
              __UpperCAmelCase									=			[]
              for i in range(self.batch_size  ):
                  __UpperCAmelCase					,     __UpperCAmelCase									=			np.random.choice(np.arange(self.min_resolution     ,      self.max_resolution  )     ,      2  )
                  image_inputs.append(np.random.randint(255     ,      size=(self.num_channels, width, height)     ,      dtype=np.uinta  )  )
  
          if not numpify and not torchify:
              # PIL expects the channel dimension as last dimension
              __UpperCAmelCase									=			[Image.fromarray(np.moveaxis(lowercase__     ,      0     ,      -1  )  ) for x in image_inputs]
  
          if torchify:
              __UpperCAmelCase									=			[torch.from_numpy(lowercase__  ) for x in image_inputs]
  
          return image_inputs
  
  
  
  
  
  
  @require_torch
  @require_vision
  class 					A_   (      _a ,     unittest.TestCase						):
  
  
      '''simple docstring'''
  
  
  
  
  
  
      a__     							=       SwinaSRImageProcessor if is_vision_available() else None
  
  
      def      lowerCAmelCase_						(self  )     ->      str:
          __UpperCAmelCase									=			SwinaSRImageProcessingTester(self  )
  
  
      @property
      def      lowerCAmelCase_						(self  )     ->      str:
          return self.image_processor_tester.prepare_image_processor_dict()
  
  
      def      lowerCAmelCase_						(self  )     ->      List[Any]:
          __UpperCAmelCase									=			self.image_processing_class(**self.image_processor_dict  )
          self.assertTrue(hasattr(lowercase__     ,      '''do_rescale'''  )  )
          self.assertTrue(hasattr(lowercase__     ,      '''rescale_factor'''  )  )
          self.assertTrue(hasattr(lowercase__     ,      '''do_pad'''  )  )
          self.assertTrue(hasattr(lowercase__     ,      '''pad_size'''  )  )
  
  
      def      lowerCAmelCase_						(self  )     ->      Optional[Any]:
          pass
  
  
      def      lowerCAmelCase_						(self     ,      lowercase__  )     ->      int:
          __UpperCAmelCase					,     __UpperCAmelCase									=			get_image_size(lowercase__  )
          __UpperCAmelCase									=			self.image_processor_tester.pad_size
  
          __UpperCAmelCase									=			(old_height // size + 1) * size - old_height
          __UpperCAmelCase									=			(old_width // size + 1) * size - old_width
          return old_height + pad_height, old_width + pad_width
  
  
      def      lowerCAmelCase_						(self  )     ->      Optional[int]:
          # Initialize image_processor
          __UpperCAmelCase									=			self.image_processing_class(**self.image_processor_dict  )
          # create random PIL images
          __UpperCAmelCase									=			self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__  )
          for image in image_inputs:
              self.assertIsInstance(lowercase__     ,      Image.Image  )
  
          # Test not batched input
          __UpperCAmelCase									=			image_processor(image_inputs[0]     ,      return_tensors='''pt'''  ).pixel_values
          __UpperCAmelCase					,     __UpperCAmelCase									=			self.calculate_expected_size(np.array(image_inputs[0]  )  )
          self.assertEqual(
              encoded_images.shape     ,      (
                  1,
                  self.image_processor_tester.num_channels,
                  expected_height,
                  expected_width,
              )     ,      )
  
  
      def      lowerCAmelCase_						(self  )     ->      str:
          # Initialize image_processor
          __UpperCAmelCase									=			self.image_processing_class(**self.image_processor_dict  )
          # create random numpy tensors
          __UpperCAmelCase									=			self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__     ,      numpify=lowercase__  )
          for image in image_inputs:
              self.assertIsInstance(lowercase__     ,      np.ndarray  )
  
          # Test not batched input
          __UpperCAmelCase									=			image_processor(image_inputs[0]     ,      return_tensors='''pt'''  ).pixel_values
          __UpperCAmelCase					,     __UpperCAmelCase									=			self.calculate_expected_size(image_inputs[0]  )
          self.assertEqual(
              encoded_images.shape     ,      (
                  1,
                  self.image_processor_tester.num_channels,
                  expected_height,
                  expected_width,
              )     ,      )
  
  
  
  
  
  
      def      lowerCAmelCase_						(self  )     ->      int:
          # Initialize image_processor
          __UpperCAmelCase									=			self.image_processing_class(**self.image_processor_dict  )
          # create random PyTorch tensors
          __UpperCAmelCase									=			self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__     ,      torchify=lowercase__  )
          for image in image_inputs:
              self.assertIsInstance(lowercase__     ,      torch.Tensor  )
  
          # Test not batched input
          __UpperCAmelCase									=			image_processor(image_inputs[0]     ,      return_tensors='''pt'''  ).pixel_values
          __UpperCAmelCase					,     __UpperCAmelCase									=			self.calculate_expected_size(image_inputs[0]  )
          self.assertEqual(
              encoded_images.shape     ,      (
                  1,
                  self.image_processor_tester.num_channels,
                  expected_height,
                  expected_width,
              )     ,      )
  
  
  
  
  