


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

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase			,     lowerCamelCase=7			,     lowerCamelCase=3			,     lowerCamelCase=18			,     lowerCamelCase=30			,     lowerCamelCase=400			,     lowerCamelCase=True			,     lowerCamelCase=None			,     lowerCamelCase=True			,     lowerCamelCase=None			,     lowerCamelCase=True			,     lowerCamelCase=[0.4814_5466, 0.457_8275, 0.4082_1073]			,     lowerCamelCase=[0.2686_2954, 0.2613_0258, 0.2757_7711]			,     lowerCamelCase=True			,     ):


          '''simple docstring'''





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


     def lowerCAmelCase__  (   self		):


          '''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 lowerCAmelCase__  (   self			,     lowerCamelCase=False			,     lowerCamelCase=False			,     lowerCamelCase=False		):


          '''simple docstring'''





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

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

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

          return image_inputs







@require_torch
@require_vision
class 							__magic_name__	(       lowerCAmelCase    ,		unittest.TestCase ):

     """simple docstring"""






     lowerCamelCase__       						=				ChineseCLIPImageProcessor if is_vision_available() else None


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Optional[Any]      =							ChineseCLIPImageProcessingTester(self			,     do_center_crop=lowerCamelCase		)


     @property
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          return self.image_processor_tester.prepare_image_processor_dict()


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Dict      =							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 lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       str      =							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}		)

          __A	:       List[str]      =							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		):


          '''simple docstring'''





          pass


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       List[str]      =							self.image_processing_class(**self.image_processor_dict		)
          # create random PIL images
          __A	:       Dict      =							self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase		)
          for image in image_inputs:
               self.assertIsInstance(lowerCamelCase			,     Image.Image		)

          # Test not batched input
          __A	:       List[str]      =							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
          __A	:       Optional[Any]      =							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 lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       str      =							self.image_processing_class(**self.image_processor_dict		)
          # create random numpy tensors
          __A	:       Optional[Any]      =							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
          __A	:       Tuple      =							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
          __A	:       str      =							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 lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Tuple      =							self.image_processing_class(**self.image_processor_dict		)
          # create random PyTorch tensors
          __A	:       Dict      =							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
          __A	:       int      =							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
          __A	:       List[Any]      =							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 							__magic_name__	(       lowerCAmelCase    ,		unittest.TestCase ):

     """simple docstring"""






     lowerCamelCase__       						=				ChineseCLIPImageProcessor if is_vision_available() else None


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Union[str, Any]      =							ChineseCLIPImageProcessingTester(self			,     num_channels=4			,     do_center_crop=lowerCamelCase		)
          __A	:       Optional[Any]      =							3


     @property
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          return self.image_processor_tester.prepare_image_processor_dict()


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       List[Any]      =							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 lowerCAmelCase__  (   self		):


          '''simple docstring'''





          pass


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Optional[Any]      =							self.image_processing_class(**self.image_processor_dict		)
          # create random PIL images
          __A	:       List[str]      =							self.image_processor_tester.prepare_inputs(equal_resolution=lowerCamelCase		)
          for image in image_inputs:
               self.assertIsInstance(lowerCamelCase			,     Image.Image		)

          # Test not batched input
          __A	:       Optional[int]      =							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
          __A	:       Union[str, Any]      =							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"],
              )			,     )





'''simple docstring'''


import functools


def 		_lowercase (SCREAMING_SNAKE_CASE       ,					SCREAMING_SNAKE_CASE							):




     '''simple docstring'''





     __A	:       int      =							len(SCREAMING_SNAKE_CASE							)
     __A	:       int      =							len(SCREAMING_SNAKE_CASE							)

     @functools.cache
     def min_distance(SCREAMING_SNAKE_CASE       ,					SCREAMING_SNAKE_CASE							) -> int:
          # if first word index is overflow - delete all from the second word
          if indexa >= len_worda:
               return len_worda - indexa
          # if second word index is overflow - delete all from the first word
          if indexa >= len_worda:
               return len_worda - indexa
          __A	:       Optional[int]      =							int(worda[indexa] != worda[indexa]							)  # current letters not identical
          return min(
              1 + min_distance(indexa + 1       ,					SCREAMING_SNAKE_CASE							)       ,					1 + min_distance(SCREAMING_SNAKE_CASE       ,					indexa + 1							)       ,					diff + min_distance(indexa + 1       ,					indexa + 1							)       ,					)

     return min_distance(0       ,					0							)


if __name__ == "__main__":
      import doctest

      doctest.testmod()

