





'''simple docstring'''

from collections.abc import Generator
from math import sin

def 						__magic_name__       (							__UpperCAmelCase      )						->					bytes:

   '''simple docstring'''







   if len(__UpperCAmelCase      ) != 32:
      raise ValueError("""Input must be of length 32"""      )

   __SCREAMING_SNAKE_CASE      							=       b""""""
   for i in [3, 2, 1, 0]:
      little_endian += string_aa[8 * i : 8 * i + 8]
   return little_endian

def 						__magic_name__       (							__UpperCAmelCase      )						->					bytes:

   '''simple docstring'''







   if i < 0:
      raise ValueError("""Input must be non-negative"""      )

   __SCREAMING_SNAKE_CASE      							=       format(__UpperCAmelCase							,	"""08x"""      )[-8:]
   __SCREAMING_SNAKE_CASE      							=       b""""""
   for i in [3, 2, 1, 0]:
      little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode("""utf-8"""      )
   return little_endian_hex

def 						__magic_name__       (							__UpperCAmelCase      )						->					bytes:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       b""""""
   for char in message:
      bit_string += format(__UpperCAmelCase							,	"""08b"""      ).encode("""utf-8"""      )
   __SCREAMING_SNAKE_CASE      							=       format(len(__UpperCAmelCase      )							,	"""064b"""      ).encode("""utf-8"""      )

   # Pad bit_string to a multiple of 512 chars
   bit_string += b"1"
   while len(__UpperCAmelCase      ) % 512 != 448:
      bit_string += b"0"
   bit_string += to_little_endian(start_len[32:]      ) + to_little_endian(start_len[:32]      )

   return bit_string

def 						__magic_name__       (							__UpperCAmelCase      )						->					Generator[list[int], None, None]:

   '''simple docstring'''







   if len(__UpperCAmelCase      ) % 512 != 0:
      raise ValueError("""Input must have length that's a multiple of 512"""      )

   for pos in range(0							,	len(__UpperCAmelCase      )							,	512      ):
      __SCREAMING_SNAKE_CASE      							=       bit_string[pos : pos + 512]
      __SCREAMING_SNAKE_CASE      							=       []
      for i in range(0							,	512							,	32      ):
         block_words.append(int(to_little_endian(block[i : i + 32]      )							,	2      )      )
      yield block_words

def 						__magic_name__       (							__UpperCAmelCase      )						->					int:

   '''simple docstring'''







   if i < 0:
      raise ValueError("""Input must be non-negative"""      )

   __SCREAMING_SNAKE_CASE      							=       format(__UpperCAmelCase							,	"""032b"""      )
   __SCREAMING_SNAKE_CASE      							=       """"""
   for c in i_str:
      new_str += "1" if c == "0" else "0"
   return int(__UpperCAmelCase							,	2      )

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase      )						->					int:

   '''simple docstring'''







   return (a + b) % 2**32

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase      )						->					int:

   '''simple docstring'''







   if i < 0:
      raise ValueError("""Input must be non-negative"""      )
   if shift < 0:
      raise ValueError("""Shift must be non-negative"""      )
   return ((i << shift) ^ (i >> (32 - shift))) % 2**32

def 						__magic_name__       (							__UpperCAmelCase      )						->					bytes:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       preprocess(__UpperCAmelCase      )

   __SCREAMING_SNAKE_CASE      							=       [int(2**32 * abs(sin(i + 1      )      )      ) for i in range(64      )]

   # Starting states
   __SCREAMING_SNAKE_CASE      							=       0X6745_2301
   __SCREAMING_SNAKE_CASE      							=       0XEFCD_AB89
   __SCREAMING_SNAKE_CASE      							=       0X98BA_DCFE
   __SCREAMING_SNAKE_CASE      							=       0X1032_5476

   __SCREAMING_SNAKE_CASE      							=       [
       7,
       12,
       17,
       22,
       7,
       12,
       17,
       22,
       7,
       12,
       17,
       22,
       7,
       12,
       17,
       22,
       5,
       9,
       14,
       20,
       5,
       9,
       14,
       20,
       5,
       9,
       14,
       20,
       5,
       9,
       14,
       20,
       4,
       11,
       16,
       23,
       4,
       11,
       16,
       23,
       4,
       11,
       16,
       23,
       4,
       11,
       16,
       23,
       6,
       10,
       15,
       21,
       6,
       10,
       15,
       21,
       6,
       10,
       15,
       21,
       6,
       10,
       15,
       21,
   ]

   # Process bit string in chunks, each with 16 32-char words
   for block_words in get_block_words(__UpperCAmelCase      ):
      __SCREAMING_SNAKE_CASE      							=       aa
      __SCREAMING_SNAKE_CASE      							=       ba
      __SCREAMING_SNAKE_CASE      							=       ca
      __SCREAMING_SNAKE_CASE      							=       da

      # Hash current chunk
      for i in range(64      ):
         if i <= 15:
            # f = (b & c) | (not_32(b) & d)     # Alternate definition for f
            __SCREAMING_SNAKE_CASE      							=       d ^ (b & (c ^ d))
            __SCREAMING_SNAKE_CASE      							=       i
         elif i <= 31:
            # f = (d & b) | (not_32(d) & c)     # Alternate definition for f
            __SCREAMING_SNAKE_CASE      							=       c ^ (d & (b ^ c))
            __SCREAMING_SNAKE_CASE      							=       (5 * i + 1) % 16
         elif i <= 47:
            __SCREAMING_SNAKE_CASE      							=       b ^ c ^ d
            __SCREAMING_SNAKE_CASE      							=       (3 * i + 5) % 16
         else:
            __SCREAMING_SNAKE_CASE      							=       c ^ (b | not_aa(__UpperCAmelCase      ))
            __SCREAMING_SNAKE_CASE      							=       (7 * i) % 16
         __SCREAMING_SNAKE_CASE      							=       (f + a + added_consts[i] + block_words[g]) % 2**32
         __SCREAMING_SNAKE_CASE      							=       d
         __SCREAMING_SNAKE_CASE      							=       c
         __SCREAMING_SNAKE_CASE      							=       b
         __SCREAMING_SNAKE_CASE      							=       sum_aa(__UpperCAmelCase							,	left_rotate_aa(__UpperCAmelCase							,	shift_amounts[i]      )      )

      # Add hashed chunk to running total
      __SCREAMING_SNAKE_CASE      							=       sum_aa(__UpperCAmelCase							,	__UpperCAmelCase      )
      __SCREAMING_SNAKE_CASE      							=       sum_aa(__UpperCAmelCase							,	__UpperCAmelCase      )
      __SCREAMING_SNAKE_CASE      							=       sum_aa(__UpperCAmelCase							,	__UpperCAmelCase      )
      __SCREAMING_SNAKE_CASE      							=       sum_aa(__UpperCAmelCase							,	__UpperCAmelCase      )

   __SCREAMING_SNAKE_CASE      							=       reformat_hex(__UpperCAmelCase      ) + reformat_hex(__UpperCAmelCase      ) + reformat_hex(__UpperCAmelCase      ) + reformat_hex(__UpperCAmelCase      )
   return digest


if __name__ == "__main__":
    import doctest

    doctest.testmod()












'''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


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import ChineseCLIPImageProcessor







class __a (   unittest.TestCase			):





   def __init__(					self				:			List[Any]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			List[str]=7				,lowerCamelCase				:			List[str]=3				,lowerCamelCase				:			List[str]=18				,lowerCamelCase				:			Any=30				,lowerCamelCase				:			Optional[Any]=400				,lowerCamelCase				:			Optional[Any]=True				,lowerCamelCase				:			Optional[Any]=None				,lowerCamelCase				:			Optional[int]=True				,lowerCamelCase				:			int=None				,lowerCamelCase				:			str=True				,lowerCamelCase				:			Dict=[0.48_145_466, 0.4_578_275, 0.40_821_073]				,lowerCamelCase				:			List[str]=[0.26_862_954, 0.26_130_258, 0.27_577_711]				,lowerCamelCase				:			Tuple=True				,):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       size if size is not None else {"""height""": 224, """width""": 224}
      __SCREAMING_SNAKE_CASE      							=       crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
      __SCREAMING_SNAKE_CASE      							=       parent
      __SCREAMING_SNAKE_CASE      							=       batch_size
      __SCREAMING_SNAKE_CASE      							=       num_channels
      __SCREAMING_SNAKE_CASE      							=       image_size
      __SCREAMING_SNAKE_CASE      							=       min_resolution
      __SCREAMING_SNAKE_CASE      							=       max_resolution
      __SCREAMING_SNAKE_CASE      							=       do_resize
      __SCREAMING_SNAKE_CASE      							=       size
      __SCREAMING_SNAKE_CASE      							=       do_center_crop
      __SCREAMING_SNAKE_CASE      							=       crop_size
      __SCREAMING_SNAKE_CASE      							=       do_normalize
      __SCREAMING_SNAKE_CASE      							=       image_mean
      __SCREAMING_SNAKE_CASE      							=       image_std
      __SCREAMING_SNAKE_CASE      							=       do_convert_rgb





   def      UpperCAmelCase__     (					self				:			Optional[int]    ):

      '''simple docstring'''

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





   def      UpperCAmelCase__     (					self				:			int				,lowerCamelCase				:			Union[str, Any]=False				,lowerCamelCase				:			str=False				,lowerCamelCase				:			str=False    ):

      '''simple docstring'''

      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

      if equal_resolution:
         __SCREAMING_SNAKE_CASE      							=       []
         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:
         __SCREAMING_SNAKE_CASE      							=       []
         for i in range(self.batch_size    ):
            __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       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
         __SCREAMING_SNAKE_CASE      							=       [Image.fromarray(np.moveaxis(lowerCamelCase				,0				,-1    )    ) for x in image_inputs]

      if torchify:
         __SCREAMING_SNAKE_CASE      							=       [torch.from_numpy(lowerCamelCase    ) for x in image_inputs]

      return image_inputs







@require_torch
@require_vision
class __a (   _snake_case,   unittest.TestCase			):
   __UpperCamelCase   : int	      =	ChineseCLIPImageProcessor if is_vision_available() else None





   def      UpperCAmelCase__     (					self				:			Any    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ChineseCLIPImageProcessingTester(self				,do_center_crop=lowerCamelCase    )





   @property
   def      UpperCAmelCase__     (					self				:			Optional[int]    ):

      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_resize"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""size"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_center_crop"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""center_crop"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_normalize"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""image_mean"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""image_std"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_convert_rgb"""    )    )





   def      UpperCAmelCase__     (					self				:			List[Any]    ):

      '''simple docstring'''

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

      __SCREAMING_SNAKE_CASE      							=       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				:			Dict    ):

      '''simple docstring'''

      pass





   def      UpperCAmelCase__     (					self				:			List[str]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random PIL images
      __SCREAMING_SNAKE_CASE      							=       self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase    )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase				,Image.Image    )

      # Test not batched input
      __SCREAMING_SNAKE_CASE      							=       image_processing(image_inputs[0]				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)

      # Test batched
      __SCREAMING_SNAKE_CASE      							=       image_processing(lowerCamelCase				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)





   def      UpperCAmelCase__     (					self				:			Optional[int]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random numpy tensors
      __SCREAMING_SNAKE_CASE      							=       self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase				,numpify=lowerCamelCase    )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase				,np.ndarray    )

      # Test not batched input
      __SCREAMING_SNAKE_CASE      							=       image_processing(image_inputs[0]				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)

      # Test batched
      __SCREAMING_SNAKE_CASE      							=       image_processing(lowerCamelCase				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)





   def      UpperCAmelCase__     (					self				:			str    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random PyTorch tensors
      __SCREAMING_SNAKE_CASE      							=       self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase				,torchify=lowerCamelCase    )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase				,torch.Tensor    )

      # Test not batched input
      __SCREAMING_SNAKE_CASE      							=       image_processing(image_inputs[0]				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)

      # Test batched
      __SCREAMING_SNAKE_CASE      							=       image_processing(lowerCamelCase				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)







@require_torch
@require_vision
class __a (   _snake_case,   unittest.TestCase			):
   __UpperCamelCase   : Optional[int]	      =	ChineseCLIPImageProcessor if is_vision_available() else None





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       ChineseCLIPImageProcessingTester(self				,num_channels=4				,do_center_crop=lowerCamelCase    )
      __SCREAMING_SNAKE_CASE      							=       3





   @property
   def      UpperCAmelCase__     (					self				:			Dict    ):

      '''simple docstring'''

      return self.image_processor_tester.prepare_image_processor_dict()





   def      UpperCAmelCase__     (					self				:			int    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_resize"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""size"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_center_crop"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""center_crop"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_normalize"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""image_mean"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""image_std"""    )    )
      self.assertTrue(hasattr(lowerCamelCase				,"""do_convert_rgb"""    )    )





   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      pass





   def      UpperCAmelCase__     (					self				:			Union[str, Any]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.image_processing_class(**self.image_processor_dict    )
      # create random PIL images
      __SCREAMING_SNAKE_CASE      							=       self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase    )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase				,Image.Image    )

      # Test not batched input
      __SCREAMING_SNAKE_CASE      							=       image_processing(image_inputs[0]				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              1,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)

      # Test batched
      __SCREAMING_SNAKE_CASE      							=       image_processing(lowerCamelCase				,return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape				,(
              self.image_processor_tester.batch_size,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )				,)





