'''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 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


_UpperCamelCase					:		Optional[int]							      =		logging.get_logger(__name__)



def     __snake_case			(							lowerCAmelCase							:  Optional[Any]   ,	lowerCAmelCase							:  Tuple      ):
 __UpperCAmelCase								=       b.T
 __UpperCAmelCase								=       np.sum(np.square(__snake_case      )   ,	axis=1      )
 __UpperCAmelCase								=       np.sum(np.square(__snake_case      )   ,	axis=0      )
 __UpperCAmelCase								=       np.matmul(__snake_case   ,	__snake_case      )
 __UpperCAmelCase								=       aa[:, None] - 2 * ab + ba[None, :]
 return d



def     __snake_case			(							lowerCAmelCase							:  int   ,	lowerCAmelCase							:  str      ):
 __UpperCAmelCase								=       x.reshape(-1   ,	3      )
 __UpperCAmelCase								=       squared_euclidean_distance(__snake_case   ,	__snake_case      )
 return np.argmin(__snake_case   ,	axis=1      )

class 	_lowercase(  a_					):



   """simple docstring"""





   __lowerCamelCase     =	['''pixel_values''']





   def __init__(				self:     List[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:     int      ,):
    super().__init__(**UpperCamelCase_						)
    __UpperCAmelCase								=       size if size is not None else {'height': 256, 'width': 256}
    __UpperCAmelCase								=       get_size_dict(UpperCamelCase_						)
    __UpperCAmelCase								=       np.array(UpperCamelCase_						) if clusters is not None else None
    __UpperCAmelCase								=       do_resize
    __UpperCAmelCase								=       size
    __UpperCAmelCase								=       resample
    __UpperCAmelCase								=       do_normalize
    __UpperCAmelCase								=       do_color_quantize





   def       snake_case						(				self:     str      ,a:     np.ndarray      ,a:     Dict[str, int]      ,a:     PILImageResampling = PILImageResampling.BILINEAR      ,a:     Optional[Union[str, ChannelDimension]] = None      ,**a:     Tuple      ,):
    __UpperCAmelCase								=       get_size_dict(UpperCamelCase_						)
    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(
        UpperCamelCase_      ,size=(size['height'], size['width'])      ,resample=UpperCamelCase_      ,data_format=UpperCamelCase_      ,**UpperCamelCase_						)





   def       snake_case						(				self:     Any      ,a:     np.ndarray      ,a:     Optional[Union[str, ChannelDimension]] = None      ,):
    __UpperCAmelCase								=       rescale(image=UpperCamelCase_      ,scale=1 / 127.5      ,data_format=UpperCamelCase_						)
    __UpperCAmelCase								=       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:     Optional[int]      ,):
    __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(UpperCamelCase_						)
    __UpperCAmelCase								=       resample if resample is not None else self.resample
    __UpperCAmelCase								=       do_normalize if do_normalize is not None else self.do_normalize
    __UpperCAmelCase								=       do_color_quantize if do_color_quantize is not None else self.do_color_quantize
    __UpperCAmelCase								=       clusters if clusters is not None else self.clusters
    __UpperCAmelCase								=       np.array(UpperCamelCase_						)

    __UpperCAmelCase								=       make_list_of_images(UpperCamelCase_						)

    if not valid_images(UpperCamelCase_						):
     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								=       [to_numpy_array(UpperCamelCase_						) for image in images]

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

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

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

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

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

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











"""simple docstring"""
from ..utils import DummyObject, requires_backends



class        UpperCamelCase__ (				metaclass=a_):







    """simple docstring"""
    __UpperCAmelCase           = ["""flax""", """transformers"""]







    def __init__(		self :	List[Any]				,    *UpperCamelCase_ :	str				,    **UpperCamelCase_ :	Any ):





           '''simple docstring'''

           requires_backends(self				,    ['flax', 'transformers'] )







    @classmethod
    def 				a__			(		cls :	Optional[int]				,    *UpperCamelCase_ :	Tuple				,    **UpperCamelCase_ :	List[Any] ):





           '''simple docstring'''

           requires_backends(cls				,    ['flax', 'transformers'] )







    @classmethod
    def 				a__			(		cls :	str				,    *UpperCamelCase_ :	Optional[Any]				,    **UpperCamelCase_ :	Dict ):





           '''simple docstring'''

           requires_backends(cls				,    ['flax', 'transformers'] )



class        UpperCamelCase__ (				metaclass=a_):







    """simple docstring"""
    __UpperCAmelCase           = ["""flax""", """transformers"""]







    def __init__(		self :	List[Any]				,    *UpperCamelCase_ :	str				,    **UpperCamelCase_ :	str ):





           '''simple docstring'''

           requires_backends(self				,    ['flax', 'transformers'] )







    @classmethod
    def 				a__			(		cls :	Optional[int]				,    *UpperCamelCase_ :	Optional[int]				,    **UpperCamelCase_ :	List[str] ):





           '''simple docstring'''

           requires_backends(cls				,    ['flax', 'transformers'] )







    @classmethod
    def 				a__			(		cls :	Tuple				,    *UpperCamelCase_ :	List[str]				,    **UpperCamelCase_ :	Optional[Any] ):





           '''simple docstring'''

           requires_backends(cls				,    ['flax', 'transformers'] )



class        UpperCamelCase__ (				metaclass=a_):







    """simple docstring"""
    __UpperCAmelCase           = ["""flax""", """transformers"""]







    def __init__(		self :	Optional[int]				,    *UpperCamelCase_ :	List[Any]				,    **UpperCamelCase_ :	List[str] ):





           '''simple docstring'''

           requires_backends(self				,    ['flax', 'transformers'] )







    @classmethod
    def 				a__			(		cls :	str				,    *UpperCamelCase_ :	List[str]				,    **UpperCamelCase_ :	Tuple ):





           '''simple docstring'''

           requires_backends(cls				,    ['flax', 'transformers'] )







    @classmethod
    def 				a__			(		cls :	Tuple				,    *UpperCamelCase_ :	Any				,    **UpperCamelCase_ :	List[str] ):





           '''simple docstring'''

           requires_backends(cls				,    ['flax', 'transformers'] )



class        UpperCamelCase__ (				metaclass=a_):







    """simple docstring"""
    __UpperCAmelCase           = ["""flax""", """transformers"""]







    def __init__(		self :	Optional[Any]				,    *UpperCamelCase_ :	Optional[Any]				,    **UpperCamelCase_ :	Dict ):





           '''simple docstring'''

           requires_backends(self				,    ['flax', 'transformers'] )







    @classmethod
    def 				a__			(		cls :	str				,    *UpperCamelCase_ :	Dict				,    **UpperCamelCase_ :	List[str] ):





           '''simple docstring'''

           requires_backends(cls				,    ['flax', 'transformers'] )







    @classmethod
    def 				a__			(		cls :	str				,    *UpperCamelCase_ :	Optional[Any]				,    **UpperCamelCase_ :	Union[str, Any] ):





           '''simple docstring'''

           requires_backends(cls				,    ['flax', 'transformers'] )