


import unittest
from typing import Dict, List, Optional, Union

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 BridgeTowerImageProcessor



class 				A       (			unittest.TestCase				):
					'''simple docstring'''






					def __init__(self       :		List[Any] ,   _UpperCAmelCase       :		int ,   _UpperCAmelCase       :		bool = True ,   _UpperCAmelCase       :		Dict[str, int] = None ,   _UpperCAmelCase       :		int = 32 ,   _UpperCAmelCase       :		bool = True ,   _UpperCAmelCase       :		Union[int, float] = 1 / 255 ,   _UpperCAmelCase       :		bool = True ,   _UpperCAmelCase       :		bool = True ,   _UpperCAmelCase       :		Optional[Union[float, List[float]]] = [0.48_145_466, 0.4_578_275, 0.40_821_073] ,   _UpperCAmelCase       :		Optional[Union[float, List[float]]] = [0.26_862_954, 0.26_130_258, 0.27_577_711] ,   _UpperCAmelCase       :		bool = True ,   _UpperCAmelCase       :		Any=7 ,   _UpperCAmelCase       :		int=30 ,   _UpperCAmelCase       :		List[Any]=400 ,   _UpperCAmelCase       :		int=3 ,   )		->  Any:




							"""simple docstring"""


							lowercase__	     =						parent
							lowercase__	     =						do_resize
							lowercase__	     =						size if size is not None else {"shortest_edge": 288}
							lowercase__	     =						size_divisor
							lowercase__	     =						do_rescale
							lowercase__	     =						rescale_factor
							lowercase__	     =						do_normalize
							lowercase__	     =						do_center_crop
							lowercase__	     =						image_mean
							lowercase__	     =						image_std
							lowercase__	     =						do_pad
							lowercase__	     =						batch_size
							lowercase__	     =						num_channels
							lowercase__	     =						min_resolution
							lowercase__	     =						max_resolution

					def     lowerCamelCase__	(self       :		Any						)		->  Tuple:




							"""simple docstring"""


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


					def     lowerCamelCase__	(self       :		Dict ,   _UpperCAmelCase       :		Optional[int] ,   _UpperCAmelCase       :		Optional[int]=False						)		->  List[Any]:




							"""simple docstring"""


							if not batched:
									lowercase__	     =						self.size["shortest_edge"]
									lowercase__	     =						image_inputs[0]
									if isinstance(a__ ,   Image.Image						):
											lowercase__	     =						image.size
									else:
											lowercase__	     =						image.shape[1], image.shape[2]
									lowercase__	     =						size / min(a__ ,   a__						)
									if h < w:
											lowercase__	     =						size, scale * w
									else:
											lowercase__	     =						scale * h, size

									lowercase__	     =						int((1333 / 800) * size						)
									if max(a__ ,   a__						) > max_size:
											lowercase__	     =						max_size / max(a__ ,   a__						)
											lowercase__	     =						newh * scale
											lowercase__	     =						neww * scale

									lowercase__	     =						int(newh + 0.5						), int(neww + 0.5						)
									lowercase__	     =						(
									    newh // self.size_divisor * self.size_divisor,
									    neww // self.size_divisor * self.size_divisor,
									)

							else:
									lowercase__	     =						[]
									for image in image_inputs:
											lowercase__	     =						self.get_expected_values([image]						)
											expected_values.append((expected_height, expected_width)						)
									lowercase__	     =						max(a__ ,   key=lambda _UpperCAmelCase						: item[0]						)[0]
									lowercase__	     =						max(a__ ,   key=lambda _UpperCAmelCase						: item[1]						)[1]

							return expected_height, expected_width






@require_torch
@require_vision
class 				A       (			UpperCamelCase_					,    unittest.TestCase				):
					'''simple docstring'''






					A__     =					BridgeTowerImageProcessor if is_vision_available() else None

					def     lowerCamelCase__	(self       :		str						)		->  int:




							"""simple docstring"""


							lowercase__	     =						BridgeTowerImageProcessingTester(self						)

					@property
					def     lowerCamelCase__	(self       :		Tuple						)		->  Any:




							"""simple docstring"""


							return self.image_processor_tester.prepare_image_processor_dict()

					def     lowerCamelCase__	(self       :		List[str]						)		->  int:




							"""simple docstring"""


							lowercase__	     =						self.image_processing_class(**self.image_processor_dict						)
							self.assertTrue(hasattr(a__ ,   """image_mean"""						)						)
							self.assertTrue(hasattr(a__ ,   """image_std"""						)						)
							self.assertTrue(hasattr(a__ ,   """do_normalize"""						)						)
							self.assertTrue(hasattr(a__ ,   """do_resize"""						)						)
							self.assertTrue(hasattr(a__ ,   """size"""						)						)
							self.assertTrue(hasattr(a__ ,   """size_divisor"""						)						)

					def     lowerCamelCase__	(self       :		str						)		->  str:




							"""simple docstring"""


							pass

					def     lowerCamelCase__	(self       :		Any						)		->  List[str]:




							"""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=a__						)
							for image in image_inputs:
									self.assertIsInstance(a__ ,   Image.Image						)

							# Test not batched input
							lowercase__	     =						image_processing(image_inputs[0] ,   return_tensors="""pt"""						).pixel_values

							lowercase__	     =						self.image_processor_tester.get_expected_values(a__						)
							self.assertEqual(
							    encoded_images.shape ,   (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,   )

							# Test batched
							lowercase__	     =						image_processing(a__ ,   return_tensors="""pt"""						).pixel_values

							lowercase__	     =						self.image_processor_tester.get_expected_values(a__ ,   batched=a__						)
							self.assertEqual(
							    encoded_images.shape ,   (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    ) ,   )

					def     lowerCamelCase__	(self       :		int						)		->  Tuple:




							"""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=a__ ,   numpify=a__						)
							for image in image_inputs:
									self.assertIsInstance(a__ ,   np.ndarray						)

							# Test not batched input
							lowercase__	     =						image_processing(image_inputs[0] ,   return_tensors="""pt"""						).pixel_values

							lowercase__	     =						self.image_processor_tester.get_expected_values(a__						)
							self.assertEqual(
							    encoded_images.shape ,   (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,   )

							# Test batched
							lowercase__	     =						image_processing(a__ ,   return_tensors="""pt"""						).pixel_values

							lowercase__	     =						self.image_processor_tester.get_expected_values(a__ ,   batched=a__						)
							self.assertEqual(
							    encoded_images.shape ,   (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    ) ,   )


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




							"""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=a__ ,   torchify=a__						)
							for image in image_inputs:
									self.assertIsInstance(a__ ,   torch.Tensor						)

							# Test not batched input
							lowercase__	     =						image_processing(image_inputs[0] ,   return_tensors="""pt"""						).pixel_values

							lowercase__	     =						self.image_processor_tester.get_expected_values(a__						)
							self.assertEqual(
							    encoded_images.shape ,   (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,   )

							# Test batched
							lowercase__	     =						image_processing(a__ ,   return_tensors="""pt"""						).pixel_values

							lowercase__	     =						self.image_processor_tester.get_expected_values(a__ ,   batched=a__						)
							self.assertEqual(
							    encoded_images.shape ,   (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    ) ,   )



'''simple docstring'''

from math import factorial

snake_case									=    {str(digit): factorial(digit) for digit in range(10)}


def        UpperCAmelCase_ (  lowerCamelCase_			):







 """simple docstring"""


 if not isinstance(lowerCamelCase_      ,			lowerCamelCase_			):
  raise TypeError("Parameter number must be int"			)

 if number < 0:
  raise ValueError("Parameter number must be greater than or equal to 0"			)

 # Converts number in string to iterate on its digits and adds its factorial.
 return sum(DIGIT_FACTORIAL[digit] for digit in str(lowerCamelCase_			)			)


def        UpperCAmelCase_ (  lowerCamelCase_ = 6_0      ,			lowerCamelCase_ = 1_0_0_0_0_0_0			):







 """simple docstring"""


 if not isinstance(lowerCamelCase_      ,			lowerCamelCase_			) or not isinstance(lowerCamelCase_      ,			lowerCamelCase_			):
  raise TypeError("Parameters chain_length and number_limit must be int"			)

 if chain_length <= 0 or number_limit <= 0:
  raise ValueError(
      "Parameters chain_length and number_limit must be greater than 0"			)

 # the counter for the chains with the exact desired length
 lowerCAmelCase__     :   str     		=	0
 # the cached sizes of the previous chains
 lowerCAmelCase__     :   dict[int, int]     		=	{}

 for start_chain_element in range(1      ,			lowerCamelCase_			):
  # The temporary set will contain the elements of the chain
  lowerCAmelCase__     :   Any     		=	set()
  lowerCAmelCase__     :   int     		=	0

  # Stop computing the chain when you find a cached size, a repeating item or the
  # length is greater then the desired one.
  lowerCAmelCase__     :   Dict     		=	start_chain_element
  while (
      chain_element not in chain_sets_lengths
      and chain_element not in chain_set
      and chain_set_length <= chain_length
  ):
   chain_set.add(lowerCamelCase_			)
   chain_set_length += 1
   lowerCAmelCase__     :   Dict     		=	digit_factorial_sum(lowerCamelCase_			)

  if chain_element in chain_sets_lengths:
   chain_set_length += chain_sets_lengths[chain_element]

  lowerCAmelCase__     :   Optional[Any]     		=	chain_set_length

  # If chain contains the exact amount of elements increase the counter
  if chain_set_length == chain_length:
   chains_counter += 1

 return chains_counter


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     print(f'{solution()}')





