






"""simple docstring"""
class      UpperCamelCase_			:





	def __init__( self   :					str		)		->     Optional[Any]:
				UpperCAmelCase_	:					List[Any]     	=   ""
				UpperCAmelCase_	:					List[Any]     	=   ""
				UpperCAmelCase_	:					Tuple     	=   []





	def 	_SCREAMING_SNAKE_CASE ( self   :					Tuple      ,      lowerCAmelCase_   :					int      ,      lowerCAmelCase_   :					int		)		->     int:
				if m == -1:
							return n + 1
				elif n == -1:
							return m + 1
				elif self.dp[m][n] > -1:
							return self.dp[m][n]
				else:
							if self.worda[m] == self.worda[n]:
										UpperCAmelCase_	:					List[str]     	=   self.__min_dist_top_down_dp(m - 1      ,      n - 1		)
							else:
										UpperCAmelCase_	:					str     	=   self.__min_dist_top_down_dp(lowerCAmelCase_      ,      n - 1		)
										UpperCAmelCase_	:					Optional[Any]     	=   self.__min_dist_top_down_dp(m - 1      ,      lowerCAmelCase_		)
										UpperCAmelCase_	:					Dict     	=   self.__min_dist_top_down_dp(m - 1      ,      n - 1		)
										UpperCAmelCase_	:					str     	=   1 + min(lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_		)

							return self.dp[m][n]





	def 	_SCREAMING_SNAKE_CASE ( self   :					Optional[int]      ,      lowerCAmelCase_   :					str      ,      lowerCAmelCase_   :					str		)		->     int:
				UpperCAmelCase_	:					Optional[int]     	=   worda
				UpperCAmelCase_	:					Union[str, Any]     	=   worda
				UpperCAmelCase_	:					str     	=   [[-1 for _ in range(len(lowerCAmelCase_		)		)] for _ in range(len(lowerCAmelCase_		)		)]

				return self.__min_dist_top_down_dp(len(lowerCAmelCase_		) - 1      ,      len(lowerCAmelCase_		) - 1		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					Tuple      ,      lowerCAmelCase_   :					str      ,      lowerCAmelCase_   :					str		)		->     int:
				UpperCAmelCase_	:					str     	=   worda
				UpperCAmelCase_	:					Any     	=   worda
				UpperCAmelCase_	:					Union[str, Any]     	=   len(lowerCAmelCase_		)
				UpperCAmelCase_	:					str     	=   len(lowerCAmelCase_		)
				UpperCAmelCase_	:					Optional[int]     	=   [[0 for _ in range(n + 1		)] for _ in range(m + 1		)]

				for i in range(m + 1		):
							for j in range(n + 1		):
										if i == 0:  # first string is empty
													UpperCAmelCase_	:					int     	=   j
										elif j == 0:  # second string is empty
													UpperCAmelCase_	:					List[Any]     	=   i
										elif worda[i - 1] == worda[j - 1]:  # last characters are equal
													UpperCAmelCase_	:					Any     	=   self.dp[i - 1][j - 1]
										else:
													UpperCAmelCase_	:					Union[str, Any]     	=   self.dp[i][j - 1]
													UpperCAmelCase_	:					List[Any]     	=   self.dp[i - 1][j]
													UpperCAmelCase_	:					Union[str, Any]     	=   self.dp[i - 1][j - 1]
													UpperCAmelCase_	:					Union[str, Any]     	=   1 + min(lowerCAmelCase_      ,      lowerCAmelCase_      ,      lowerCAmelCase_		)
				return self.dp[m][n]


if __name__ == "__main__":
			lowerCamelCase_							      = EditDistance()

			print('''****************** Testing Edit Distance DP Algorithm ******************''')
			print()

			lowerCamelCase_							      = input('''Enter the first string: ''').strip()
			lowerCamelCase_							      = input('''Enter the second string: ''').strip()

			print()
			print(f'The minimum edit distance is: {solver.min_dist_top_down(Sa, Sa)}')
			print(f'The minimum edit distance is: {solver.min_dist_bottom_up(Sa, Sa)}')
			print()
			print('''*************** End of Testing Edit Distance DP Algorithm ***************''')











"""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	):





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





	def 	_SCREAMING_SNAKE_CASE ( self   :					int		)		->     Union[str, Any]:
				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_			(__A							,		unittest.TestCase	):
	__magic_name__       =							ViTImageProcessor if is_vision_available() else None





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[str]		)		->     Optional[Any]:
				UpperCAmelCase_	:					Optional[Any]     	=   EfficientFormerImageProcessorTester(self		)





	@property
	def 	_SCREAMING_SNAKE_CASE ( self   :					Dict		)		->     List[Any]:
				return self.image_proc_tester.prepare_image_processor_dict()





	def 	_SCREAMING_SNAKE_CASE ( self   :					Tuple		)		->     str:
				UpperCAmelCase_	:					Tuple     	=   self.image_processing_class(**self.image_processor_dict		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "image_mean"		)		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "image_std"		)		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "do_normalize"		)		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "do_resize"		)		)
				self.assertTrue(hasattr(lowerCAmelCase_      ,      "size"		)		)





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[str]		)		->     List[str]:
				pass





	def 	_SCREAMING_SNAKE_CASE ( self   :					Optional[int]		)		->     int:
				# Initialize image_processor
				UpperCAmelCase_	:					str     	=   self.image_processing_class(**self.image_processor_dict		)
				# create random PIL images
				UpperCAmelCase_	:					int     	=   prepare_image_inputs(self.image_proc_tester      ,      equal_resolution=lowerCAmelCase_		)
				for image in image_inputs:
							self.assertIsInstance(lowerCAmelCase_      ,      Image.Image		)

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

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

				# Test not batched input
				UpperCAmelCase_	:					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
				UpperCAmelCase_	:					Optional[int]     	=   image_processor(lowerCAmelCase_      ,      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"],
				    )      ,      )



