






"""simple docstring"""







import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import GLPNImageProcessor


class      UpperCamelCase		(unittest.TestCase     ):






						def __init__(		self  :Optional[int]			, __magic_name__  :List[Any]			, __magic_name__  :List[Any]=7			, __magic_name__  :Any=3			, __magic_name__  :List[Any]=18			, __magic_name__  :List[Any]=30			, __magic_name__  :Tuple=400			, __magic_name__  :List[Any]=True			, __magic_name__  :Tuple=32			, __magic_name__  :Dict=True			, )      ->str:
										lowercase    :      int       = parent
										lowercase    :      Optional[int]       = batch_size
										lowercase    :      Tuple       = num_channels
										lowercase    :      Dict       = image_size
										lowercase    :      Union[str, Any]       = min_resolution
										lowercase    :      int       = max_resolution
										lowercase    :      Union[str, Any]       = do_resize
										lowercase    :      List[str]       = size_divisor
										lowercase    :      Tuple       = do_rescale






						def      __snake_case      (		self  :List[str]				)      ->Dict:
										return {
										    "do_resize": self.do_resize,
										    "size_divisor": self.size_divisor,
										    "do_rescale": self.do_rescale,
										}


@require_torch
@require_vision
class      UpperCamelCase		(lowercase__						,						unittest.TestCase     ):
						_SCREAMING_SNAKE_CASE  : Dict												=		GLPNImageProcessor if is_vision_available() else None






						def      __snake_case      (		self  :Optional[int]				)      ->str:
										lowercase    :      Any       = GLPNImageProcessingTester(self				)






						@property
						def      __snake_case      (		self  :str				)      ->Tuple:
										return self.image_processor_tester.prepare_image_processor_dict()






						def      __snake_case      (		self  :List[Any]				)      ->List[Any]:
										lowercase    :      int       = self.image_processing_class(**self.image_processor_dict				)
										self.assertTrue(hasattr(lowercase_			, """do_resize"""				)				)
										self.assertTrue(hasattr(lowercase_			, """size_divisor"""				)				)
										self.assertTrue(hasattr(lowercase_			, """resample"""				)				)
										self.assertTrue(hasattr(lowercase_			, """do_rescale"""				)				)






						def      __snake_case      (		self  :Dict				)      ->Optional[int]:
										pass






						def      __snake_case      (		self  :Union[str, Any]				)      ->Optional[int]:
										# Initialize image_processing
										lowercase    :      Dict       = self.image_processing_class(**self.image_processor_dict				)
										# create random PIL images
										lowercase    :      int       = prepare_image_inputs(self.image_processor_tester			, equal_resolution=lowercase_				)
										for image in image_inputs:
														self.assertIsInstance(lowercase_			, Image.Image				)

										# Test not batched input (GLPNImageProcessor doesn't support batching)
										lowercase    :      Dict       = image_processing(image_inputs[0]			, return_tensors="""pt"""				).pixel_values
										self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0				)
										self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0				)






						def      __snake_case      (		self  :Any				)      ->int:
										# Initialize image_processing
										lowercase    :      Dict       = self.image_processing_class(**self.image_processor_dict				)
										# create random numpy tensors
										lowercase    :      List[str]       = prepare_image_inputs(self.image_processor_tester			, equal_resolution=lowercase_			, numpify=lowercase_				)
										for image in image_inputs:
														self.assertIsInstance(lowercase_			, np.ndarray				)

										# Test not batched input (GLPNImageProcessor doesn't support batching)
										lowercase    :      Tuple       = image_processing(image_inputs[0]			, return_tensors="""pt"""				).pixel_values
										self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0				)
										self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0				)






						def      __snake_case      (		self  :Optional[Any]				)      ->Optional[Any]:
										# Initialize image_processing
										lowercase    :      Optional[int]       = self.image_processing_class(**self.image_processor_dict				)
										# create random PyTorch tensors
										lowercase    :      Dict       = prepare_image_inputs(self.image_processor_tester			, equal_resolution=lowercase_			, torchify=lowercase_				)
										for image in image_inputs:
														self.assertIsInstance(lowercase_			, torch.Tensor				)

										# Test not batched input (GLPNImageProcessor doesn't support batching)
										lowercase    :      List[Any]       = image_processing(image_inputs[0]			, return_tensors="""pt"""				).pixel_values
										self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0				)
										self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0				)




from typing import List, Optional

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


_lowerCAmelCase:						List[Any]   				=       logging.get_logger(__name__)

_lowerCAmelCase:						Any   				=       {
    'huggingface/autoformer-tourism-monthly': 'https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json',
}




class       lowercase_					(lowercase__   ):
				snake_case	    ='autoformer'
				snake_case	    ={
				    'hidden_size': 'd_model',
				    'num_attention_heads': 'encoder_attention_heads',
				    'num_hidden_layers': 'encoder_layers',
				}





				def __init__(				self       ,  lowercase_ = None       ,  lowercase_ = None       ,  lowercase_ = "student_t"       ,  lowercase_ = "nll"       ,  lowercase_ = 1       ,  lowercase_ = [1, 2, 3, 4, 5, 6, 7]       ,  lowercase_ = True       ,  lowercase_ = 0       ,  lowercase_ = 0       ,  lowercase_ = 0       ,  lowercase_ = 0       ,  lowercase_ = None       ,  lowercase_ = None       ,  lowercase_ = 64       ,  lowercase_ = 2       ,  lowercase_ = 2       ,  lowercase_ = 2       ,  lowercase_ = 2       ,  lowercase_ = 32       ,  lowercase_ = 32       ,  lowercase_ = "gelu"       ,  lowercase_ = 0.1       ,  lowercase_ = 0.1       ,  lowercase_ = 0.1       ,  lowercase_ = 0.1       ,  lowercase_ = 0.1       ,  lowercase_ = 100       ,  lowercase_ = 0.02       ,  lowercase_ = True       ,  lowercase_=True       ,  lowercase_ = 10       ,  lowercase_ = 25       ,  lowercase_ = 3       ,  **lowercase_       ,  )  -> Union[str, Any]:
											# time series specific configuration
											a__      =prediction_length
											a__      =context_length if context_length is not None else prediction_length
											a__      =distribution_output
											a__      =loss
											a__      =input_size
											a__      =num_time_features
											a__      =lags_sequence
											a__      =scaling
											a__      =num_dynamic_real_features
											a__      =num_static_real_features
											a__      =num_static_categorical_features
											if cardinality is not None and num_static_categorical_features > 0:
																		if len(lowercase_) != num_static_categorical_features:
																									raise ValueError(
																									    'The cardinality should be a list of the same length as `num_static_categorical_features`')
																		a__      =cardinality
											else:
																		a__      =[0]
											if embedding_dimension is not None and num_static_categorical_features > 0:
																		if len(lowercase_) != num_static_categorical_features:
																									raise ValueError(
																									    'The embedding dimension should be a list of the same length as `num_static_categorical_features`')
																		a__      =embedding_dimension
											else:
																		a__      =[min(50       ,  (cat + 1) // 2) for cat in self.cardinality]
											a__      =num_parallel_samples

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

											a__      =dropout
											a__      =attention_dropout
											a__      =activation_dropout
											a__      =encoder_layerdrop
											a__      =decoder_layerdrop

											a__      =activation_function
											a__      =init_std

											a__      =use_cache

											# Autoformer
											a__      =label_length
											a__      =moving_average
											a__      =autocorrelation_factor

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





				@property
				def 						__UpperCamelCase    (				self)  -> 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
											)

