



"""simple docstring"""

import unittest

import numpy as np
from datasets import load_dataset

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 SegformerImageProcessor
class 						lowerCAmelCase__	(  unittest.TestCase   ):


	'''simple docstring'''







	def __init__(			self							:					Tuple    ,					_SCREAMING_SNAKE_CASE							:					Union[str, Any]    ,					_SCREAMING_SNAKE_CASE							:					Dict=7    ,					_SCREAMING_SNAKE_CASE							:					List[str]=3    ,					_SCREAMING_SNAKE_CASE							:					Union[str, Any]=30    ,					_SCREAMING_SNAKE_CASE							:					List[str]=400    ,					_SCREAMING_SNAKE_CASE							:					List[str]=True    ,					_SCREAMING_SNAKE_CASE							:					Dict=None    ,					_SCREAMING_SNAKE_CASE							:					List[Any]=True    ,					_SCREAMING_SNAKE_CASE							:					int=[0.5, 0.5, 0.5]    ,					_SCREAMING_SNAKE_CASE							:					Union[str, Any]=[0.5, 0.5, 0.5]    ,					_SCREAMING_SNAKE_CASE							:					int=False    ,					)	->  Any:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Tuple 							=    size if size is not None else {'height': 30, 'width': 30}
					SCREAMING_SNAKE_CASE	:       Any 							=    parent
					SCREAMING_SNAKE_CASE	:       Dict 							=    batch_size
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    num_channels
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    min_resolution
					SCREAMING_SNAKE_CASE	:       Any 							=    max_resolution
					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    do_resize
					SCREAMING_SNAKE_CASE	:       str 							=    size
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    do_normalize
					SCREAMING_SNAKE_CASE	:       int 							=    image_mean
					SCREAMING_SNAKE_CASE	:       List[str] 							=    image_std
					SCREAMING_SNAKE_CASE	:       Dict 							=    do_reduce_labels







	def  _lowerCAmelCase    (			self							:					List[Any]						)	->  Any:





					"""simple docstring"""


					return {
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_normalize": self.do_normalize,
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					    "do_reduce_labels": self.do_reduce_labels,
					}




def    __snake_case       (  )    ->					Union[str, Any]:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE	:       int 							=    load_dataset('hf-internal-testing/fixtures_ade20k'       ,		split='test'    )

				SCREAMING_SNAKE_CASE	:       List[Any] 							=    Image.open(dataset[0]['file']    )
				SCREAMING_SNAKE_CASE	:       Any 							=    Image.open(dataset[1]['file']    )

				return image, map
def    __snake_case       (  )    ->					Any:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    load_dataset('hf-internal-testing/fixtures_ade20k'       ,		split='test'    )

				SCREAMING_SNAKE_CASE	:       Any 							=    Image.open(dataset[0]['file']    )
				SCREAMING_SNAKE_CASE	:       Tuple 							=    Image.open(dataset[1]['file']    )
				SCREAMING_SNAKE_CASE	:       List[Any] 							=    Image.open(dataset[2]['file']    )
				SCREAMING_SNAKE_CASE	:       Dict 							=    Image.open(dataset[3]['file']    )

				return [imagea, imagea], [mapa, mapa]







@require_torch
@require_vision
class 						lowerCAmelCase__	(  _lowerCamelCase       ,       unittest.TestCase   ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE  :		List[str]     	=   SegformerImageProcessor if is_vision_available() else None





	def  _lowerCAmelCase    (			self							:					Dict						)	->  Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       str 							=    SegformerImageProcessingTester(self						)





	@property
	def  _lowerCAmelCase    (			self							:					Union[str, Any]						)	->  Any:





					"""simple docstring"""


					return self.image_processor_tester.prepare_image_processor_dict()





	def  _lowerCAmelCase    (			self							:					int						)	->  Any:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[str] 							=    self.image_processing_class(**self.image_processor_dict						)
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'do_resize'						)						)
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'size'						)						)
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'do_normalize'						)						)
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'image_mean'						)						)
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'image_std'						)						)
					self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'do_reduce_labels'						)						)





	def  _lowerCAmelCase    (			self							:					Optional[Any]						)	->  Optional[int]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Dict 							=    self.image_processing_class.from_dict(self.image_processor_dict						)
					self.assertEqual(image_processor.size    ,					{'height': 30, 'width': 30}						)
					self.assertEqual(image_processor.do_reduce_labels    ,					_SCREAMING_SNAKE_CASE						)

					SCREAMING_SNAKE_CASE	:       Optional[Any] 							=    self.image_processing_class.from_dict(self.image_processor_dict    ,					size=42    ,					reduce_labels=_SCREAMING_SNAKE_CASE						)
					self.assertEqual(image_processor.size    ,					{'height': 42, 'width': 42}						)
					self.assertEqual(image_processor.do_reduce_labels    ,					_SCREAMING_SNAKE_CASE						)





	def  _lowerCAmelCase    (			self							:					Tuple						)	->  Optional[int]:





					"""simple docstring"""


					pass





	def  _lowerCAmelCase    (			self							:					Union[str, Any]						)	->  Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    self.image_processing_class(**self.image_processor_dict						)
					# create random PIL images
					SCREAMING_SNAKE_CASE	:       Dict 							=    prepare_image_inputs(self.image_processor_tester    ,					equal_resolution=_SCREAMING_SNAKE_CASE						)
					for image in image_inputs:
									self.assertIsInstance(_SCREAMING_SNAKE_CASE    ,					Image.Image						)

					# Test not batched input
					SCREAMING_SNAKE_CASE	:       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.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)

					# Test batched
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    image_processing(_SCREAMING_SNAKE_CASE    ,					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.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)





	def  _lowerCAmelCase    (			self							:					Any						)	->  Dict:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[str] 							=    self.image_processing_class(**self.image_processor_dict						)
					# create random numpy tensors
					SCREAMING_SNAKE_CASE	:       int 							=    prepare_image_inputs(self.image_processor_tester    ,					equal_resolution=_SCREAMING_SNAKE_CASE    ,					numpify=_SCREAMING_SNAKE_CASE						)
					for image in image_inputs:
									self.assertIsInstance(_SCREAMING_SNAKE_CASE    ,					np.ndarray						)

					# Test not batched input
					SCREAMING_SNAKE_CASE	:       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.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)

					# Test batched
					SCREAMING_SNAKE_CASE	:       str 							=    image_processing(_SCREAMING_SNAKE_CASE    ,					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.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)





	def  _lowerCAmelCase    (			self							:					Optional[Any]						)	->  Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[str] 							=    self.image_processing_class(**self.image_processor_dict						)
					# create random PyTorch tensors
					SCREAMING_SNAKE_CASE	:       List[str] 							=    prepare_image_inputs(self.image_processor_tester    ,					equal_resolution=_SCREAMING_SNAKE_CASE    ,					torchify=_SCREAMING_SNAKE_CASE						)
					for image in image_inputs:
									self.assertIsInstance(_SCREAMING_SNAKE_CASE    ,					torch.Tensor						)

					# Test not batched input
					SCREAMING_SNAKE_CASE	:       Any 							=    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.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)

					# Test batched
					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    image_processing(_SCREAMING_SNAKE_CASE    ,					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.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)





	def  _lowerCAmelCase    (			self							:					Any						)	->  Tuple:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       Dict 							=    self.image_processing_class(**self.image_processor_dict						)
					# create random PyTorch tensors
					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    prepare_image_inputs(self.image_processor_tester    ,					equal_resolution=_SCREAMING_SNAKE_CASE    ,					torchify=_SCREAMING_SNAKE_CASE						)
					SCREAMING_SNAKE_CASE	:       List[str] 							=    []
					for image in image_inputs:
									self.assertIsInstance(_SCREAMING_SNAKE_CASE    ,					torch.Tensor						)
									maps.append(torch.zeros(image.shape[-2:]						).long()						)

					# Test not batched input
					SCREAMING_SNAKE_CASE	:       Dict 							=    image_processing(image_inputs[0]    ,					maps[0]    ,					return_tensors='pt'						)
					self.assertEqual(
					    encoding['pixel_values'].shape    ,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)
					self.assertEqual(
					    encoding['labels'].shape    ,					(
					        1,
					        self.image_processor_tester.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)
					self.assertEqual(encoding['labels'].dtype    ,					torch.long						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 255						)

					# Test batched
					SCREAMING_SNAKE_CASE	:       str 							=    image_processing(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					return_tensors='pt'						)
					self.assertEqual(
					    encoding['pixel_values'].shape    ,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)
					self.assertEqual(
					    encoding['labels'].shape    ,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)
					self.assertEqual(encoding['labels'].dtype    ,					torch.long						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 255						)

					# Test not batched input (PIL images)
					SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE	:       Optional[int] 							=    prepare_semantic_single_inputs()

					SCREAMING_SNAKE_CASE	:       List[str] 							=    image_processing(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					return_tensors='pt'						)
					self.assertEqual(
					    encoding['pixel_values'].shape    ,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)
					self.assertEqual(
					    encoding['labels'].shape    ,					(
					        1,
					        self.image_processor_tester.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)
					self.assertEqual(encoding['labels'].dtype    ,					torch.long						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 255						)

					# Test batched input (PIL images)
					SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    prepare_semantic_batch_inputs()

					SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    image_processing(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					return_tensors='pt'						)
					self.assertEqual(
					    encoding['pixel_values'].shape    ,					(
					        2,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)
					self.assertEqual(
					    encoding['labels'].shape    ,					(
					        2,
					        self.image_processor_tester.size['height'],
					        self.image_processor_tester.size['width'],
					    )    ,					)
					self.assertEqual(encoding['labels'].dtype    ,					torch.long						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 255						)







	def  _lowerCAmelCase    (			self							:					Dict						)	->  Union[str, Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE	:       List[str] 							=    self.image_processing_class(**self.image_processor_dict						)

					# ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
					SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE	:       Any 							=    prepare_semantic_single_inputs()
					SCREAMING_SNAKE_CASE	:       int 							=    image_processing(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					return_tensors='pt'						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 150						)

					SCREAMING_SNAKE_CASE	:       Optional[int] 							=    True
					SCREAMING_SNAKE_CASE	:       Tuple 							=    image_processing(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					return_tensors='pt'						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 255						)










"""simple docstring"""

def    __snake_case       (  __A			:	str       ,		__A			:	str    )    ->					int:






				'''simple docstring'''
				# The longer word should come first
				if len(__A    ) < len(__A    ):
								return levenshtein_distance(__A       ,		__A    )

				if len(__A    ) == 0:
								return len(__A    )

				SCREAMING_SNAKE_CASE	:       List[Any] 							=    list(range(len(__A    ) + 1    )    )

				for i, ca in enumerate(__A    ):
								SCREAMING_SNAKE_CASE	:       Union[str, Any] 							=    [i + 1]

								for j, ca in enumerate(__A    ):
												# Calculate insertions, deletions and substitutions
												SCREAMING_SNAKE_CASE	:       str 							=    previous_row[j + 1] + 1
												SCREAMING_SNAKE_CASE	:       List[str] 							=    current_row[j] + 1
												SCREAMING_SNAKE_CASE	:       Any 							=    previous_row[j] + (ca != ca)

												# Get the minimum to append to the current row
												current_row.append(min(__A       ,		__A       ,		__A    )    )

								# Store the previous row
								SCREAMING_SNAKE_CASE	:       Tuple 							=    current_row

				# Returns the last element (distance)
				return previous_row[-1]


if __name__ == "__main__":
							A_	:						Optional[int]				=			input('Enter the first word:\n').strip()
							A_	:						Optional[Any]				=			input('Enter the second word:\n').strip()

							A_	:						str				=			levenshtein_distance(first_word, second_word)
							print(f'''Levenshtein distance between {first_word} and {second_word} is {result}''')





