
'''simple docstring'''

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

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


snake_case									=    logging.get_logger(__name__)




class    lowerCAmelCase       (     UpperCamelCase_  ):
 A_				:				List[str]	=			["""pixel_values"""]


 def __init__(    self  : Tuple			,							a__  : bool = True			,							a__  : Dict[str, int] = None			,							a__  : PILImageResampling = PILImageResampling.BICUBIC			,							a__  : bool = True			,							a__  : Dict[str, int] = None			,							a__  : bool = True			,							a__  : Union[int, float] = 1 / 255			,							a__  : bool = True			,							a__  : Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_MEAN			,							a__  : Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_STD			,							**a__  : Union[str, Any]			,							):
  '''simple docstring'''

  super().__init__(**a__    )
  lowerCAmelCase__     :   Dict     		=	size if size is not None else {"shortest_edge": 224}
  lowerCAmelCase__     :   Union[str, Any]     		=	get_size_dict(a__			,							default_to_square=a__    )
  lowerCAmelCase__     :   str     		=	crop_size if crop_size is not None else {"height": 224, "width": 224}
  lowerCAmelCase__     :   str     		=	get_size_dict(a__			,							param_name="crop_size"    )

  lowerCAmelCase__     :   Tuple     		=	do_resize
  lowerCAmelCase__     :   Any     		=	size
  lowerCAmelCase__     :   List[Any]     		=	resample
  lowerCAmelCase__     :   Optional[int]     		=	do_center_crop
  lowerCAmelCase__     :   str     		=	crop_size
  lowerCAmelCase__     :   Dict     		=	do_rescale
  lowerCAmelCase__     :   List[str]     		=	rescale_factor
  lowerCAmelCase__     :   Any     		=	do_normalize
  lowerCAmelCase__     :   str     		=	image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
  lowerCAmelCase__     :   Any     		=	image_std if image_std is not None else IMAGENET_DEFAULT_STD


 def    _A	(    self  : Dict			,							a__  : np.ndarray			,							a__  : Dict[str, int]			,							a__  : PILImageResampling = PILImageResampling.BICUBIC			,							a__  : Optional[Union[str, ChannelDimension]] = None			,							**a__  : Union[str, Any]			,							):
  '''simple docstring'''

  lowerCAmelCase__     :   Tuple     		=	get_size_dict(a__			,							default_to_square=a__    )
  # size_dict is a dict with either keys "height" and "width" or "shortest_edge"
  if "shortest_edge" in size:
   lowerCAmelCase__     :   Tuple     		=	int((256 / 224) * size["shortest_edge"]    )
   lowerCAmelCase__     :   Dict     		=	get_resize_output_image_size(a__			,							size=a__			,							default_to_square=a__    )
   lowerCAmelCase__     :   Any     		=	{"height": output_size[0], "width": output_size[1]}
  if "height" not in size_dict or "width" not in size_dict:
   raise ValueError(
       F'''Size dict must have keys \'height\' and \'width\' or \'shortest_edge\'. Got {size_dict.keys()}'''    )
  return resize(
      a__			,							size=(size_dict["height"], size_dict["width"])			,							resample=a__			,							data_format=a__			,							**a__    )


 def    _A	(    self  : Any			,							a__  : np.ndarray			,							a__  : Dict[str, int]			,							a__  : Optional[Union[str, ChannelDimension]] = None			,							**a__  : Union[str, Any]			,							):
  '''simple docstring'''

  lowerCAmelCase__     :   Any     		=	get_size_dict(a__    )
  if "height" not in size or "width" not in size:
   raise ValueError(F'''Size dict must have keys \'height\' and \'width\'. Got {size.keys()}'''    )
  return center_crop(a__			,							size=(size["height"], size["width"])			,							data_format=a__			,							**a__    )


 def    _A	(    self  : Optional[int]			,							a__  : np.ndarray			,							a__  : Union[int, float]			,							a__  : Optional[Union[str, ChannelDimension]] = None			,							**a__  : Optional[Any]			,							):
  '''simple docstring'''

  return rescale(a__			,							scale=a__			,							data_format=a__			,							**a__    )


 def    _A	(    self  : Any			,							a__  : np.ndarray			,							a__  : Union[float, List[float]]			,							a__  : Union[float, List[float]]			,							a__  : Optional[Union[str, ChannelDimension]] = None			,							**a__  : Tuple			,							):
  '''simple docstring'''

  return normalize(a__			,							mean=a__			,							std=a__			,							data_format=a__			,							**a__    )


 def    _A	(    self  : List[str]			,							a__  : ImageInput			,							a__  : Optional[bool] = None			,							a__  : Optional[Dict[str, int]] = None			,							a__  : PILImageResampling = None			,							a__  : Optional[bool] = None			,							a__  : Optional[Dict[str, int]] = None			,							a__  : Optional[bool] = None			,							a__  : Optional[float] = None			,							a__  : Optional[bool] = None			,							a__  : Optional[Union[float, Iterable[float]]] = None			,							a__  : Optional[Union[float, Iterable[float]]] = None			,							a__  : Optional[TensorType] = None			,							a__  : ChannelDimension = ChannelDimension.FIRST			,							**a__  : List[str]			,							):
  '''simple docstring'''

  lowerCAmelCase__     :   Optional[int]     		=	do_resize if do_resize is not None else self.do_resize
  lowerCAmelCase__     :   str     		=	resample if resample is not None else self.resample
  lowerCAmelCase__     :   Optional[Any]     		=	do_center_crop if do_center_crop is not None else self.do_center_crop
  lowerCAmelCase__     :   Optional[int]     		=	do_rescale if do_rescale is not None else self.do_rescale
  lowerCAmelCase__     :   Optional[int]     		=	rescale_factor if rescale_factor is not None else self.rescale_factor
  lowerCAmelCase__     :   Union[str, Any]     		=	do_normalize if do_normalize is not None else self.do_normalize
  lowerCAmelCase__     :   Any     		=	image_mean if image_mean is not None else self.image_mean
  lowerCAmelCase__     :   Optional[Any]     		=	image_std if image_std is not None else self.image_std

  lowerCAmelCase__     :   Optional[Any]     		=	size if size is not None else self.size
  lowerCAmelCase__     :   List[str]     		=	get_size_dict(a__			,							default_to_square=a__    )
  lowerCAmelCase__     :   Optional[Any]     		=	crop_size if crop_size is not None else self.crop_size
  lowerCAmelCase__     :   Any     		=	get_size_dict(a__			,							param_name="crop_size"    )

  lowerCAmelCase__     :   Tuple     		=	make_list_of_images(a__    )

  if not valid_images(a__    ):
   raise ValueError(
       "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
       "torch.Tensor, tf.Tensor or jax.ndarray."    )

  if do_resize and size is None:
   raise ValueError("Size must be specified if do_resize is True."    )

  if do_center_crop and crop_size is None:
   raise ValueError("Crop size must be specified if do_center_crop is True."    )

  if do_rescale and rescale_factor is None:
   raise ValueError("Rescale factor must be specified if do_rescale is True."    )

  if do_normalize and (image_mean is None or image_std is None):
   raise ValueError("Image mean and std must be specified if do_normalize is True."    )

  # All transformations expect numpy arrays.
  lowerCAmelCase__     :   int     		=	[to_numpy_array(a__    ) for image in images]

  if do_resize:
   lowerCAmelCase__     :   Optional[int]     		=	[self.resize(a__			,							a__			,							a__    ) for image in images]

  if do_center_crop:
   lowerCAmelCase__     :   List[str]     		=	[self.center_crop(a__			,							a__    ) for image in images]

  if do_rescale:
   lowerCAmelCase__     :   List[Any]     		=	[self.rescale(a__			,							a__    ) for image in images]

  if do_normalize:
   lowerCAmelCase__     :   Tuple     		=	[self.normalize(a__			,							a__			,							a__    ) for image in images]

  lowerCAmelCase__     :   Union[str, Any]     		=	[to_channel_dimension_format(a__			,							a__    ) for image in images]

  lowerCAmelCase__     :   Any     		=	{"pixel_values": images}
  return BatchFeature(data=a__			,							tensor_type=a__    )







'''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()}')





