



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


__A   :							List[Any]										=   logging.get_logger(__name__)
class 			_a (					lowerCAmelCase):
			"""simple docstring"""
			UpperCamelCase__			      =	["""pixel_values"""]



			def __init__(		self     :    str				,   __UpperCamelCase     :    bool = True				,   __UpperCamelCase     :    Dict[str, int] = None				,   __UpperCamelCase     :    PILImageResampling = PILImageResampling.BICUBIC				,   __UpperCamelCase     :    bool = True				,   __UpperCamelCase     :    Dict[str, int] = None				,   __UpperCamelCase     :    bool = True				,   __UpperCamelCase     :    Union[int, float] = 1 / 2_5_5				,   __UpperCamelCase     :    bool = True				,   __UpperCamelCase     :    Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_MEAN				,   __UpperCamelCase     :    Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_STD				,   **__UpperCamelCase     :    Optional[Any]				,   )->None:
							super().__init__(**__UpperCamelCase   )
							_UpperCAmelCase					=    size if size is not None else {'''shortest_edge''': 2_2_4}
							_UpperCAmelCase					=    get_size_dict(__UpperCamelCase				,   default_to_square=__UpperCamelCase   )
							_UpperCAmelCase					=    crop_size if crop_size is not None else {'''height''': 2_2_4, '''width''': 2_2_4}
							_UpperCAmelCase					=    get_size_dict(__UpperCamelCase				,   param_name='''crop_size'''   )

							_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_DEFAULT_MEAN
							_UpperCAmelCase					=    image_std if image_std is not None else IMAGENET_DEFAULT_STD



			def  lowercase__						(		self     :    Any				,   __UpperCamelCase     :    np.ndarray				,   __UpperCamelCase     :    Dict[str, int]				,   __UpperCamelCase     :    PILImageResampling = PILImageResampling.BICUBIC				,   __UpperCamelCase     :    Optional[Union[str, ChannelDimension]] = None				,   **__UpperCamelCase     :    str				,   )->np.ndarray:
							_UpperCAmelCase					=    get_size_dict(__UpperCamelCase				,   default_to_square=__UpperCamelCase   )
							# size_dict is a dict with either keys "height" and "width" or "shortest_edge"
							if "shortest_edge" in size:
											_UpperCAmelCase					=    int((2_5_6 / 2_2_4) * size['''shortest_edge''']   )
											_UpperCAmelCase					=    get_resize_output_image_size(__UpperCamelCase				,   size=__UpperCamelCase				,   default_to_square=__UpperCamelCase   )
											_UpperCAmelCase					=    {'''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(
							    __UpperCamelCase				,   size=(size_dict['''height'''], size_dict['''width'''])				,   resample=__UpperCamelCase				,   data_format=__UpperCamelCase				,   **__UpperCamelCase   )



			def  lowercase__						(		self     :    Union[str, Any]				,   __UpperCamelCase     :    np.ndarray				,   __UpperCamelCase     :    Dict[str, int]				,   __UpperCamelCase     :    Optional[Union[str, ChannelDimension]] = None				,   **__UpperCamelCase     :    List[Any]				,   )->np.ndarray:
							_UpperCAmelCase					=    get_size_dict(__UpperCamelCase   )
							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(__UpperCamelCase				,   size=(size['''height'''], size['''width'''])				,   data_format=__UpperCamelCase				,   **__UpperCamelCase   )



			def  lowercase__						(		self     :    Any				,   __UpperCamelCase     :    np.ndarray				,   __UpperCamelCase     :    Union[int, float]				,   __UpperCamelCase     :    Optional[Union[str, ChannelDimension]] = None				,   **__UpperCamelCase     :    int				,   )->np.ndarray:
							return rescale(__UpperCamelCase				,   scale=__UpperCamelCase				,   data_format=__UpperCamelCase				,   **__UpperCamelCase   )



			def  lowercase__						(		self     :    Any				,   __UpperCamelCase     :    np.ndarray				,   __UpperCamelCase     :    Union[float, List[float]]				,   __UpperCamelCase     :    Union[float, List[float]]				,   __UpperCamelCase     :    Optional[Union[str, ChannelDimension]] = None				,   **__UpperCamelCase     :    Optional[Any]				,   )->np.ndarray:
							return normalize(__UpperCamelCase				,   mean=__UpperCamelCase				,   std=__UpperCamelCase				,   data_format=__UpperCamelCase				,   **__UpperCamelCase   )



			def  lowercase__						(		self     :    Dict				,   __UpperCamelCase     :    ImageInput				,   __UpperCamelCase     :    Optional[bool] = None				,   __UpperCamelCase     :    Optional[Dict[str, int]] = None				,   __UpperCamelCase     :    PILImageResampling = None				,   __UpperCamelCase     :    Optional[bool] = None				,   __UpperCamelCase     :    Optional[Dict[str, int]] = None				,   __UpperCamelCase     :    Optional[bool] = None				,   __UpperCamelCase     :    Optional[float] = None				,   __UpperCamelCase     :    Optional[bool] = None				,   __UpperCamelCase     :    Optional[Union[float, Iterable[float]]] = None				,   __UpperCamelCase     :    Optional[Union[float, Iterable[float]]] = None				,   __UpperCamelCase     :    Optional[TensorType] = None				,   __UpperCamelCase     :    ChannelDimension = ChannelDimension.FIRST				,   **__UpperCamelCase     :    Dict				,   )->BatchFeature:
							_UpperCAmelCase					=    do_resize if do_resize is not None else self.do_resize
							_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					=    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					=    size if size is not None else self.size
							_UpperCAmelCase					=    get_size_dict(__UpperCamelCase				,   default_to_square=__UpperCamelCase   )
							_UpperCAmelCase					=    crop_size if crop_size is not None else self.crop_size
							_UpperCAmelCase					=    get_size_dict(__UpperCamelCase				,   param_name='''crop_size'''   )

							_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:
											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(__UpperCamelCase   ) for image in images]

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

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

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

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

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

							_UpperCAmelCase					=    {'''pixel_values''': images}
							return BatchFeature(data=__UpperCamelCase				,   tensor_type=__UpperCamelCase   )








"""simple docstring"""


from typing import List, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A   :							Any										=   logging.get_logger(__name__)

__A   :							Dict										=   {
    "huggingface/informer-tourism-monthly": (
        "https://huggingface.co/huggingface/informer-tourism-monthly/resolve/main/config.json"
    ),
    # See all Informer models at https://huggingface.co/models?filter=informer
}
class 			_a (					lowerCAmelCase):
			"""simple docstring"""
			UpperCamelCase__			      =	"""informer"""
			UpperCamelCase__			      =	{
			    """hidden_size""": """d_model""",
			    """num_attention_heads""": """encoder_attention_heads""",
			    """num_hidden_layers""": """encoder_layers""",
			}



			def __init__(		self     :    List[str]				,   __UpperCamelCase     :    Optional[int] = None				,   __UpperCamelCase     :    Optional[int] = None				,   __UpperCamelCase     :    str = "student_t"				,   __UpperCamelCase     :    str = "nll"				,   __UpperCamelCase     :    int = 1				,   __UpperCamelCase     :    List[int] = None				,   __UpperCamelCase     :    Optional[Union[str, bool]] = "mean"				,   __UpperCamelCase     :    int = 0				,   __UpperCamelCase     :    int = 0				,   __UpperCamelCase     :    int = 0				,   __UpperCamelCase     :    int = 0				,   __UpperCamelCase     :    Optional[List[int]] = None				,   __UpperCamelCase     :    Optional[List[int]] = None				,   __UpperCamelCase     :    int = 6_4				,   __UpperCamelCase     :    int = 3_2				,   __UpperCamelCase     :    int = 3_2				,   __UpperCamelCase     :    int = 2				,   __UpperCamelCase     :    int = 2				,   __UpperCamelCase     :    int = 2				,   __UpperCamelCase     :    int = 2				,   __UpperCamelCase     :    bool = True				,   __UpperCamelCase     :    str = "gelu"				,   __UpperCamelCase     :    float = 0.0_5				,   __UpperCamelCase     :    float = 0.1				,   __UpperCamelCase     :    float = 0.1				,   __UpperCamelCase     :    float = 0.1				,   __UpperCamelCase     :    float = 0.1				,   __UpperCamelCase     :    int = 1_0_0				,   __UpperCamelCase     :    float = 0.0_2				,   __UpperCamelCase     :    Optional[Any]=True				,   __UpperCamelCase     :    str = "prob"				,   __UpperCamelCase     :    int = 5				,   __UpperCamelCase     :    bool = True				,   **__UpperCamelCase     :    Union[str, Any]				,   )->Dict:
							# time series specific configuration
							_UpperCAmelCase					=    prediction_length
							_UpperCAmelCase					=    context_length or prediction_length
							_UpperCAmelCase					=    distribution_output
							_UpperCAmelCase					=    loss
							_UpperCAmelCase					=    input_size
							_UpperCAmelCase					=    num_time_features
							_UpperCAmelCase					=    lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
							_UpperCAmelCase					=    scaling
							_UpperCAmelCase					=    num_dynamic_real_features
							_UpperCAmelCase					=    num_static_real_features
							_UpperCAmelCase					=    num_static_categorical_features

							# set cardinality
							if cardinality and num_static_categorical_features > 0:
											if len(__UpperCamelCase   ) != num_static_categorical_features:
															raise ValueError(
															    '''The cardinality should be a list of the same length as `num_static_categorical_features`'''   )
											_UpperCAmelCase					=    cardinality
							else:
											_UpperCAmelCase					=    [0]

							# set embedding_dimension
							if embedding_dimension and num_static_categorical_features > 0:
											if len(__UpperCamelCase   ) != num_static_categorical_features:
															raise ValueError(
															    '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''   )
											_UpperCAmelCase					=    embedding_dimension
							else:
											_UpperCAmelCase					=    [min(5_0				,   (cat + 1) // 2   ) for cat in self.cardinality]

							_UpperCAmelCase					=    num_parallel_samples

							# Transformer architecture configuration
							_UpperCAmelCase					=    input_size * len(self.lags_sequence   ) + self._number_of_features
							_UpperCAmelCase					=    d_model
							_UpperCAmelCase					=    encoder_attention_heads
							_UpperCAmelCase					=    decoder_attention_heads
							_UpperCAmelCase					=    encoder_ffn_dim
							_UpperCAmelCase					=    decoder_ffn_dim
							_UpperCAmelCase					=    encoder_layers
							_UpperCAmelCase					=    decoder_layers

							_UpperCAmelCase					=    dropout
							_UpperCAmelCase					=    attention_dropout
							_UpperCAmelCase					=    activation_dropout
							_UpperCAmelCase					=    encoder_layerdrop
							_UpperCAmelCase					=    decoder_layerdrop

							_UpperCAmelCase					=    activation_function
							_UpperCAmelCase					=    init_std

							_UpperCAmelCase					=    use_cache

							# Informer
							_UpperCAmelCase					=    attention_type
							_UpperCAmelCase					=    sampling_factor
							_UpperCAmelCase					=    distil

							super().__init__(is_encoder_decoder=__UpperCamelCase				,   **__UpperCamelCase   )



			@property
			def  lowercase__						(		self     :    Optional[int]   )->int:
							return (
							    sum(self.embedding_dimension   )
							    + self.num_dynamic_real_features
							    + self.num_time_features
							    + self.num_static_real_features
							    + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
							)



