

'''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 MobileNetVaImageProcessor
class 					__a   (		unittest.TestCase  ):

						def __init__(		self	:						Tuple    ,			lowercase__	:						str    ,			lowercase__	:						Optional[Any]=7    ,			lowercase__	:						int=3    ,			lowercase__	:						Union[str, Any]=18    ,			lowercase__	:						Union[str, Any]=30    ,			lowercase__	:						str=4_00    ,			lowercase__	:						str=True    ,			lowercase__	:						Any=None    ,			lowercase__	:						Tuple=True    ,			lowercase__	:						List[str]=None    ,			)						->Optional[int]:

							"""simple docstring"""



							_lowercase							=     size if size is not None else {"""shortest_edge""": 20}
							_lowercase							=     crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
							_lowercase							=     parent
							_lowercase							=     batch_size
							_lowercase							=     num_channels
							_lowercase							=     image_size
							_lowercase							=     min_resolution
							_lowercase							=     max_resolution
							_lowercase							=     do_resize
							_lowercase							=     size
							_lowercase							=     do_center_crop
							_lowercase							=     crop_size


						def 	_UpperCAmelCase							(		self	:						Tuple)						->Any:

							"""simple docstring"""



							return {
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "do_center_crop": self.do_center_crop,
							    "crop_size": self.crop_size,
							}






@require_torch
@require_vision
class 					__a   (		_snake_case							,unittest.TestCase  ):
						__SCREAMING_SNAKE_CASE     :					str  =      MobileNetVaImageProcessor if is_vision_available() else None

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

							"""simple docstring"""



							_lowercase							=     MobileNetVaImageProcessingTester(self)

						@property
						def 	_UpperCAmelCase							(		self	:						List[str])						->Optional[Any]:

							"""simple docstring"""



							return self.image_processor_tester.prepare_image_processor_dict()

						def 	_UpperCAmelCase							(		self	:						Tuple)						->Tuple:

							"""simple docstring"""



							_lowercase							=     self.image_processing_class(**self.image_processor_dict)
							self.assertTrue(hasattr(lowercase__    ,			"""do_resize"""))
							self.assertTrue(hasattr(lowercase__    ,			"""size"""))
							self.assertTrue(hasattr(lowercase__    ,			"""do_center_crop"""))
							self.assertTrue(hasattr(lowercase__    ,			"""center_crop"""))

						def 	_UpperCAmelCase							(		self	:						List[Any])						->int:

							"""simple docstring"""



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

							_lowercase							=     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	:						Optional[int])						->Any:

							"""simple docstring"""



							pass

						def 	_UpperCAmelCase							(		self	:						Dict)						->Tuple:

							"""simple docstring"""



							_lowercase							=     self.image_processing_class(**self.image_processor_dict)
							# create random PIL images
							_lowercase							=     prepare_image_inputs(self.image_processor_tester    ,			equal_resolution=lowercase__)
							for image in image_inputs:
								self.assertIsInstance(lowercase__    ,			Image.Image)

							# Test not batched input
							_lowercase							=     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
							_lowercase							=     image_processing(lowercase__    ,			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[Any])						->Union[str, Any]:

							"""simple docstring"""



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

							# Test not batched input
							_lowercase							=     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
							_lowercase							=     image_processing(lowercase__    ,			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	:						List[Any])						->str:

							"""simple docstring"""



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

							# Test not batched input
							_lowercase							=     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
							_lowercase							=     image_processing(lowercase__    ,			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"""],
							    )    ,			)






"""simple docstring"""




__lowerCAmelCase							:  Any 				=		{
    '''0''': 1,
    '''1''': 1,
    '''2''': 2,
    '''3''': 6,
    '''4''': 24,
    '''5''': 120,
    '''6''': 720,
    '''7''': 5040,
    '''8''': 40320,
    '''9''': 362880,
}

__lowerCAmelCase							:  List[Any] 				=		{145: 145}

__lowerCAmelCase							:  Any 				=		{
    145: 0,
    169: 3,
    36301: 3,
    1454: 3,
    871: 2,
    45361: 2,
    872: 2,
}

def __snake_case (      UpperCamelCase    )       ->    int:


		"""simple docstring"""





		if n in CACHE_SUM_DIGIT_FACTORIALS:
				return CACHE_SUM_DIGIT_FACTORIALS[n]
		a__   		=     sum(DIGIT_FACTORIALS[let] for let in str(UpperCamelCase    )    )
		a__   		=     ret
		return ret

def __snake_case (      UpperCamelCase						,					UpperCamelCase = None    )       ->    int:


		"""simple docstring"""





		a__   		=     previous or set()
		if n in CHAIN_LENGTH_CACHE:
				return CHAIN_LENGTH_CACHE[n]
		a__   		=     sum_digit_factorials(UpperCamelCase    )
		if next_number in previous:
				a__   		=     0
				return 0
		else:
				previous.add(UpperCamelCase    )
				a__   		=     1 + chain_length(UpperCamelCase						,					UpperCamelCase    )
				a__   		=     ret
				return ret

def __snake_case (      UpperCamelCase = 60						,					UpperCamelCase = 1_000_000    )       ->    int:


		"""simple docstring"""





		return sum(1 for i in range(1						,					UpperCamelCase    ) if chain_length(UpperCamelCase    ) == num_terms    )


if __name__ == "__main__":
					print(f"{solution() = }")




