


'''simple docstring'''




def 	a_					( lowerCamelCase	:     int				):
   lowerCAmelCase     =			abs(_UpperCAmelCase				)
   lowerCAmelCase     =			0
   while n > 0:
      res += n % 10
      n //= 10
   return res





def 	a_					( lowerCamelCase	:     int				):
   lowerCAmelCase     =			abs(_UpperCAmelCase				)
   return n if n < 10 else n % 10 + sum_of_digits(n // 10				)





def 	a_					( lowerCamelCase	:     int				):
   return sum(int(_UpperCAmelCase				) for c in str(abs(_UpperCAmelCase				)				)				)





def 	a_					( ):
   from collections.abc import Callable
   from timeit import timeit

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

   for value in (262144, 1125899906842624, 1267650600228229401496703205376):
      for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
         benchmark_a_function(_UpperCAmelCase	, _UpperCAmelCase				)
      print()


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       benchmark()










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 rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
				import PIL


__A   			=logging.get_logger(__name__)

def        a						(      _UpperCAmelCase							:					Optional[Any] ,   _UpperCAmelCase							:					Dict						):







		'''simple docstring'''





		__UpperCAmelCase    :     List[str]													=	b.T
		__UpperCAmelCase    :     Any													=	np.sum(np.square(_UpperCAmelCase						) ,   axis=1						)
		__UpperCAmelCase    :     int													=	np.sum(np.square(_UpperCAmelCase						) ,   axis=0						)
		__UpperCAmelCase    :     Optional[int]													=	np.matmul(_UpperCAmelCase ,   _UpperCAmelCase						)
		__UpperCAmelCase    :     List[str]													=	aa[:, None] - 2 * ab + ba[None, :]
		return d

def        a						(      _UpperCAmelCase							:					Optional[int] ,   _UpperCAmelCase							:					Optional[Any]						):







		'''simple docstring'''





		__UpperCAmelCase    :     str													=	x.reshape(-1 ,   3						)
		__UpperCAmelCase    :     Optional[int]													=	squared_euclidean_distance(_UpperCAmelCase ,   _UpperCAmelCase						)
		return np.argmin(_UpperCAmelCase ,   axis=1						)

class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			UpperCamelCase									=       ["""pixel_values"""]




			def __init__(   self							: str       ,       a_							: Optional[Union[List[List[int]], np.ndarray]] = None       ,       a_							: bool = True       ,       a_							: Dict[str, int] = None       ,       a_							: PILImageResampling = PILImageResampling.BILINEAR       ,       a_							: bool = True       ,       a_							: bool = True       ,       **a_							: List[str]       ,       ):
					'''simple docstring'''





					super().__init__(**a_ )
					__UpperCAmelCase    :     Optional[int]													=	size if size is not None else {'''height''': 2_56, '''width''': 2_56}
					__UpperCAmelCase    :     List[str]													=	get_size_dict(a_ )
					__UpperCAmelCase    :     str													=	np.array(a_ ) if clusters is not None else None
					__UpperCAmelCase    :     Dict													=	do_resize
					__UpperCAmelCase    :     Tuple													=	size
					__UpperCAmelCase    :     Union[str, Any]													=	resample
					__UpperCAmelCase    :     Tuple													=	do_normalize
					__UpperCAmelCase    :     Optional[int]													=	do_color_quantize




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





					__UpperCAmelCase    :     Tuple													=	get_size_dict(a_ )
					if "height" not in size or "width" not in size:
							raise ValueError(F'Size dictionary must contain both height and width keys. Got {size.keys()}' )
					return resize(
					    a_       ,       size=(size['''height'''], size['''width'''])       ,       resample=a_       ,       data_format=a_       ,       **a_ )




			def  snake_case__     (   self							: Tuple       ,       a_							: np.ndarray       ,       a_							: Optional[Union[str, ChannelDimension]] = None       ,       ):
					'''simple docstring'''





					__UpperCAmelCase    :     Dict													=	rescale(image=a_       ,       scale=1 / 1_2_7.5       ,       data_format=a_ )
					__UpperCAmelCase    :     Union[str, Any]													=	image - 1
					return image




			def  snake_case__     (   self							: int       ,       a_							: ImageInput       ,       a_							: bool = None       ,       a_							: Dict[str, int] = None       ,       a_							: PILImageResampling = None       ,       a_							: bool = None       ,       a_							: Optional[bool] = None       ,       a_							: Optional[Union[List[List[int]], np.ndarray]] = None       ,       a_							: Optional[Union[str, TensorType]] = None       ,       a_							: Optional[Union[str, ChannelDimension]] = ChannelDimension.FIRST       ,       **a_							: Any       ,       ):
					'''simple docstring'''





					__UpperCAmelCase    :     Any													=	do_resize if do_resize is not None else self.do_resize
					__UpperCAmelCase    :     List[str]													=	size if size is not None else self.size
					__UpperCAmelCase    :     Any													=	get_size_dict(a_ )
					__UpperCAmelCase    :     Optional[int]													=	resample if resample is not None else self.resample
					__UpperCAmelCase    :     List[str]													=	do_normalize if do_normalize is not None else self.do_normalize
					__UpperCAmelCase    :     int													=	do_color_quantize if do_color_quantize is not None else self.do_color_quantize
					__UpperCAmelCase    :     Optional[int]													=	clusters if clusters is not None else self.clusters
					__UpperCAmelCase    :     Any													=	np.array(a_ )

					__UpperCAmelCase    :     Optional[int]													=	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 or resample is None:
							raise ValueError('''Size and resample must be specified if do_resize is True.''' )

					if do_color_quantize and clusters is None:
							raise ValueError('''Clusters must be specified if do_color_quantize is True.''' )

					# All transformations expect numpy arrays.
					__UpperCAmelCase    :     List[Any]													=	[to_numpy_array(a_ ) for image in images]

					if do_resize:
							__UpperCAmelCase    :     List[str]													=	[self.resize(image=a_       ,       size=a_       ,       resample=a_ ) for image in images]

					if do_normalize:
							__UpperCAmelCase    :     Dict													=	[self.normalize(image=a_ ) for image in images]

					if do_color_quantize:
							__UpperCAmelCase    :     int													=	[to_channel_dimension_format(a_       ,       ChannelDimension.LAST ) for image in images]
							# color quantize from (batch_size, height, width, 3) to (batch_size, height, width)
							__UpperCAmelCase    :     List[str]													=	np.array(a_ )
							__UpperCAmelCase    :     Dict													=	color_quantize(a_       ,       a_ ).reshape(images.shape[:-1] )

							# flatten to (batch_size, height*width)
							__UpperCAmelCase    :     Any													=	images.shape[0]
							__UpperCAmelCase    :     Any													=	images.reshape(a_       ,       -1 )

							# We need to convert back to a list of images to keep consistent behaviour across processors.
							__UpperCAmelCase    :     List[Any]													=	list(a_ )
					else:
							__UpperCAmelCase    :     int													=	[to_channel_dimension_format(a_       ,       a_ ) for image in images]

					__UpperCAmelCase    :     int													=	{'''input_ids''': images}
					return BatchFeature(data=a_       ,       tensor_type=a_ )





