"""simple docstring"""


from typing import Dict, 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_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


UpperCAmelCase__  		=     logging.get_logger(__name__)


class        a				(		UpperCamelCase__   ):
    _snake_case     :  Dict     							=							['pixel_values']


    def __init__(					self	:  Optional[Any]   ,				__lowerCAmelCase	:  Any = True   ,				__lowerCAmelCase	:  Tuple = None   ,				__lowerCAmelCase	:  List[Any] = PILImageResampling.BILINEAR   ,				__lowerCAmelCase	:  Optional[Any] = True   ,				__lowerCAmelCase	:  Dict = None   ,				__lowerCAmelCase	:  List[Any] = True   ,				__lowerCAmelCase	:  int = 1 / 255   ,				__lowerCAmelCase	:  Any = True   ,				__lowerCAmelCase	:  Optional[Any] = None   ,				__lowerCAmelCase	:  str = None   ,				**__lowerCAmelCase	:  List[str]   ,				):
      super().__init__(**_a					)
      _UpperCAmelCase						 =      size if size is not None else {"""shortest_edge""": 256}
      _UpperCAmelCase						 =      get_size_dict(_a   ,				default_to_square=_a					)
      _UpperCAmelCase						 =      crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
      _UpperCAmelCase						 =      get_size_dict(_a					)
      _UpperCAmelCase						 =      do_resize
      _UpperCAmelCase						 =      size
      _UpperCAmelCase						 =      resample
      _UpperCAmelCase						 =      do_center_crop
      _UpperCAmelCase						 =      crop_size
      _UpperCAmelCase						 =      do_rescale
      _UpperCAmelCase						 =      rescale_factor
      _UpperCAmelCase						 =      do_normalize
      _UpperCAmelCase						 =      image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
      _UpperCAmelCase						 =      image_std if image_std is not None else IMAGENET_STANDARD_STD


    def      lowerCAmelCase_  (					self	:  List[str]   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  Tuple   ,				__lowerCAmelCase	:  List[str] = PILImageResampling.BICUBIC   ,				__lowerCAmelCase	:  Tuple = None   ,				**__lowerCAmelCase	:  Dict   ,				):
      _UpperCAmelCase						 =      get_size_dict(_a   ,				default_to_square=_a					)
      if "shortest_edge" not in size:
        raise ValueError(f'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'''					)
      _UpperCAmelCase						 =      get_resize_output_image_size(_a   ,				size=size["""shortest_edge"""]   ,				default_to_square=_a					)
      return resize(_a   ,				size=_a   ,				resample=_a   ,				data_format=_a   ,				**_a					)


    def      lowerCAmelCase_  (					self	:  int   ,				__lowerCAmelCase	:  Any   ,				__lowerCAmelCase	:  List[str]   ,				__lowerCAmelCase	:  Optional[int] = None   ,				**__lowerCAmelCase	:  List[Any]   ,				):
      _UpperCAmelCase						 =      get_size_dict(_a					)
      return center_crop(_a   ,				size=(size["""height"""], size["""width"""])   ,				data_format=_a   ,				**_a					)


    def      lowerCAmelCase_  (					self	:  Union[str, Any]   ,				__lowerCAmelCase	:  List[str]   ,				__lowerCAmelCase	:  Dict   ,				__lowerCAmelCase	:  Optional[Any] = None   ,				**__lowerCAmelCase	:  Any					):
      return rescale(_a   ,				scale=_a   ,				data_format=_a   ,				**_a					)


    def      lowerCAmelCase_  (					self	:  str   ,				__lowerCAmelCase	:  Dict   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  Any = None   ,				**__lowerCAmelCase	:  str   ,				):
      return normalize(_a   ,				mean=_a   ,				std=_a   ,				data_format=_a   ,				**_a					)


    def      lowerCAmelCase_  (					self	:  Dict   ,				__lowerCAmelCase	:  Dict   ,				__lowerCAmelCase	:  List[str] = None   ,				__lowerCAmelCase	:  str = None   ,				__lowerCAmelCase	:  Union[str, Any] = None   ,				__lowerCAmelCase	:  Union[str, Any] = None   ,				__lowerCAmelCase	:  Dict = None   ,				__lowerCAmelCase	:  Optional[int] = None   ,				__lowerCAmelCase	:  List[str] = None   ,				__lowerCAmelCase	:  List[Any] = None   ,				__lowerCAmelCase	:  Any = None   ,				__lowerCAmelCase	:  List[Any] = None   ,				__lowerCAmelCase	:  Optional[int] = None   ,				__lowerCAmelCase	:  Any = ChannelDimension.FIRST   ,				**__lowerCAmelCase	:  List[Any]   ,				):
      _UpperCAmelCase						 =      do_resize if do_resize is not None else self.do_resize
      _UpperCAmelCase						 =      size if size is not None else self.size
      _UpperCAmelCase						 =      get_size_dict(_a   ,				default_to_square=_a					)
      _UpperCAmelCase						 =      resample if resample is not None else self.resample
      _UpperCAmelCase						 =      do_center_crop if do_center_crop is not None else self.do_center_crop
      _UpperCAmelCase						 =      crop_size if crop_size is not None else self.crop_size
      _UpperCAmelCase						 =      get_size_dict(_a					)
      _UpperCAmelCase						 =      do_rescale if do_rescale is not None else self.do_rescale
      _UpperCAmelCase						 =      rescale_factor if rescale_factor is not None else self.rescale_factor
      _UpperCAmelCase						 =      do_normalize if do_normalize is not None else self.do_normalize
      _UpperCAmelCase						 =      image_mean if image_mean is not None else self.image_mean
      _UpperCAmelCase						 =      image_std if image_std is not None else self.image_std

      _UpperCAmelCase						 =      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.
      _UpperCAmelCase						 =      [to_numpy_array(_a					) for image in images]

      if do_resize:
        _UpperCAmelCase						 =      [self.resize(image=_a   ,				size=_a   ,				resample=_a					) for image in images]

      if do_center_crop:
        _UpperCAmelCase						 =      [self.center_crop(image=_a   ,				size=_a					) for image in images]

      if do_rescale:
        _UpperCAmelCase						 =      [self.rescale(image=_a   ,				scale=_a					) for image in images]

      if do_normalize:
        _UpperCAmelCase						 =      [self.normalize(image=_a   ,				mean=_a   ,				std=_a					) for image in images]

      _UpperCAmelCase						 =      [to_channel_dimension_format(_a   ,				_a					) for image in images]

      _UpperCAmelCase						 =      {"""pixel_values""": images}
      return BatchFeature(data=_a   ,				tensor_type=_a					)

"""simple docstring"""


def     __UpperCAmelCase					(			lowercase		):







  """simple docstring"""
  _UpperCAmelCase						 =      abs(lowercase		)
  _UpperCAmelCase						 =      0
  while n > 0:
    res += n % 10
    n //= 10
  return res






def     __UpperCAmelCase					(			lowercase		):







  """simple docstring"""
  _UpperCAmelCase						 =      abs(lowercase		)
  return n if n < 10 else n % 10 + sum_of_digits(n // 10		)






def     __UpperCAmelCase					(			lowercase		):







  """simple docstring"""
  return sum(int(lowercase		) for c in str(abs(lowercase		)		)		)






def     __UpperCAmelCase					(			):







  """simple docstring"""
  from collections.abc import Callable
  from timeit import timeit

  def benchmark_a_function(lowercase   ,lowercase		) -> None:
    _UpperCAmelCase						 =      f'''{func.__name__}({value})'''
    _UpperCAmelCase						 =      timeit(f'''__main__.{call}'''   ,setup="""import __main__"""		)
    print(f'''{call:56} = {func(lowercase		)} -- {timing:.4f} seconds'''		)

  for value in (26_21_44, 11_25_89_99_06_84_26_24, 1_26_76_50_60_02_28_22_94_01_49_67_03_20_53_76):
    for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
      benchmark_a_function(lowercase   ,lowercase		)
    print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()
