


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 ViTImageProcessor




class 							lowerCamelCase   (  unittest.TestCase ):


	def __init__(    self				,     lowercase__				,     lowercase__=1_3				,     lowercase__=3				,     lowercase__=2_2_4				,     lowercase__=3_0				,     lowercase__=4_0_0				,     lowercase__=True				,     lowercase__=None				,     lowercase__=True				,     lowercase__=[0.5, 0.5, 0.5]				,     lowercase__=[0.5, 0.5, 0.5]				,     ):
							__UpperCAmelCase			:							Dict	    =	size if size is not None else {'''height''': 1_8, '''width''': 1_8}
							__UpperCAmelCase			:							Union[str, Any]	    =	parent
							__UpperCAmelCase			:							Union[str, Any]	    =	batch_size
							__UpperCAmelCase			:							List[Any]	    =	num_channels
							__UpperCAmelCase			:							Dict	    =	image_size
							__UpperCAmelCase			:							Union[str, Any]	    =	min_resolution
							__UpperCAmelCase			:							List[Any]	    =	max_resolution
							__UpperCAmelCase			:							Optional[int]	    =	do_resize
							__UpperCAmelCase			:							Union[str, Any]	    =	size
							__UpperCAmelCase			:							List[Any]	    =	do_normalize
							__UpperCAmelCase			:							List[Any]	    =	image_mean
							__UpperCAmelCase			:							Union[str, Any]	    =	image_std


	def  A(    self):
							return {
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							    "do_normalize": self.do_normalize,
							    "do_resize": self.do_resize,
							    "size": self.size,
							}






@require_torch
@require_vision
class 							lowerCamelCase   (  _UpperCamelCase							,						unittest.TestCase ):
	_lowerCAmelCase     :		Dict										=						ViTImageProcessor if is_vision_available() else None


	def  A(    self):
							__UpperCAmelCase			:							Optional[Any]	    =	EfficientFormerImageProcessorTester(self)


	@property
	def  A(    self):
							return self.image_proc_tester.prepare_image_processor_dict()


	def  A(    self):
							__UpperCAmelCase			:							Optional[int]	    =	self.image_processing_class(**self.image_processor_dict)
							self.assertTrue(hasattr(lowercase__				,     '''image_mean'''))
							self.assertTrue(hasattr(lowercase__				,     '''image_std'''))
							self.assertTrue(hasattr(lowercase__				,     '''do_normalize'''))
							self.assertTrue(hasattr(lowercase__				,     '''do_resize'''))
							self.assertTrue(hasattr(lowercase__				,     '''size'''))


	def  A(    self):
							pass


	def  A(    self):
							# Initialize image_processor
							__UpperCAmelCase			:							Optional[Any]	    =	self.image_processing_class(**self.image_processor_dict)
							# create random PIL images
							__UpperCAmelCase			:							Optional[int]	    =	prepare_image_inputs(self.image_proc_tester				,     equal_resolution=lowercase__)
							for image in image_inputs:
													self.assertIsInstance(lowercase__				,     Image.Image)

							# Test not batched input
							__UpperCAmelCase			:							Union[str, Any]	    =	image_processor(image_inputs[0]				,     return_tensors='''pt''').pixel_values
							self.assertEqual(
							    encoded_images.shape				,     (
							        1,
							        self.image_proc_tester.num_channels,
							        self.image_proc_tester.size['''height'''],
							        self.image_proc_tester.size['''width'''],
							    )				,     )

							# Test batched
							__UpperCAmelCase			:							List[Any]	    =	image_processor(lowercase__				,     return_tensors='''pt''').pixel_values
							self.assertEqual(
							    encoded_images.shape				,     (
							        self.image_proc_tester.batch_size,
							        self.image_proc_tester.num_channels,
							        self.image_proc_tester.size['''height'''],
							        self.image_proc_tester.size['''width'''],
							    )				,     )


	def  A(    self):
							# Initialize image_processor
							__UpperCAmelCase			:							Optional[int]	    =	self.image_processing_class(**self.image_processor_dict)
							# create random numpy tensors
							__UpperCAmelCase			:							Dict	    =	prepare_image_inputs(self.image_proc_tester				,     equal_resolution=lowercase__				,     numpify=lowercase__)
							for image in image_inputs:
													self.assertIsInstance(lowercase__				,     np.ndarray)

							# Test not batched input
							__UpperCAmelCase			:							Optional[int]	    =	image_processor(image_inputs[0]				,     return_tensors='''pt''').pixel_values
							self.assertEqual(
							    encoded_images.shape				,     (
							        1,
							        self.image_proc_tester.num_channels,
							        self.image_proc_tester.size['''height'''],
							        self.image_proc_tester.size['''width'''],
							    )				,     )

							# Test batched
							__UpperCAmelCase			:							int	    =	image_processor(lowercase__				,     return_tensors='''pt''').pixel_values
							self.assertEqual(
							    encoded_images.shape				,     (
							        self.image_proc_tester.batch_size,
							        self.image_proc_tester.num_channels,
							        self.image_proc_tester.size['''height'''],
							        self.image_proc_tester.size['''width'''],
							    )				,     )


	def  A(    self):
							# Initialize image_processor
							__UpperCAmelCase			:							int	    =	self.image_processing_class(**self.image_processor_dict)
							# create random PyTorch tensors
							__UpperCAmelCase			:							Any	    =	prepare_image_inputs(self.image_proc_tester				,     equal_resolution=lowercase__				,     torchify=lowercase__)
							for image in image_inputs:
													self.assertIsInstance(lowercase__				,     torch.Tensor)

							# Test not batched input
							__UpperCAmelCase			:							List[str]	    =	image_processor(image_inputs[0]				,     return_tensors='''pt''').pixel_values
							self.assertEqual(
							    encoded_images.shape				,     (
							        1,
							        self.image_proc_tester.num_channels,
							        self.image_proc_tester.size['''height'''],
							        self.image_proc_tester.size['''width'''],
							    )				,     )

							# Test batched
							__UpperCAmelCase			:							List[Any]	    =	image_processor(lowercase__				,     return_tensors='''pt''').pixel_values
							self.assertEqual(
							    encoded_images.shape				,     (
							        self.image_proc_tester.batch_size,
							        self.image_proc_tester.num_channels,
							        self.image_proc_tester.size['''height'''],
							        self.image_proc_tester.size['''width'''],
							    )				,     )





from typing import List, Optional

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


lowerCAmelCase       		=    logging.get_logger(__name__)

lowerCAmelCase       		=    {
    """huggingface/autoformer-tourism-monthly""": """https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json""",
}




class 							lowerCamelCase   (  _UpperCamelCase ):
	_lowerCAmelCase     :		Optional[int]										=						'''autoformer'''
	_lowerCAmelCase     :		Any										=						{
	    '''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__ = 6_4				,     lowercase__ = 2				,     lowercase__ = 2				,     lowercase__ = 2				,     lowercase__ = 2				,     lowercase__ = 3_2				,     lowercase__ = 3_2				,     lowercase__ = "gelu"				,     lowercase__ = 0.1				,     lowercase__ = 0.1				,     lowercase__ = 0.1				,     lowercase__ = 0.1				,     lowercase__ = 0.1				,     lowercase__ = 1_0_0				,     lowercase__ = 0.0_2				,     lowercase__ = True				,     lowercase__=True				,     lowercase__ = 1_0				,     lowercase__ = 2_5				,     lowercase__ = 3				,     **lowercase__				,     ):
							# time series specific configuration
							__UpperCAmelCase			:							Optional[int]	    =	prediction_length
							__UpperCAmelCase			:							Tuple	    =	context_length if context_length is not None else prediction_length
							__UpperCAmelCase			:							Tuple	    =	distribution_output
							__UpperCAmelCase			:							Tuple	    =	loss
							__UpperCAmelCase			:							Dict	    =	input_size
							__UpperCAmelCase			:							str	    =	num_time_features
							__UpperCAmelCase			:							str	    =	lags_sequence
							__UpperCAmelCase			:							int	    =	scaling
							__UpperCAmelCase			:							int	    =	num_dynamic_real_features
							__UpperCAmelCase			:							List[str]	    =	num_static_real_features
							__UpperCAmelCase			:							List[str]	    =	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`''')
													__UpperCAmelCase			:							Union[str, Any]	    =	cardinality
							else:
													__UpperCAmelCase			:							List[Any]	    =	[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`''')
													__UpperCAmelCase			:							Union[str, Any]	    =	embedding_dimension
							else:
													__UpperCAmelCase			:							int	    =	[min(5_0				,     (cat + 1) // 2) for cat in self.cardinality]
							__UpperCAmelCase			:							Tuple	    =	num_parallel_samples

							# Transformer architecture configuration
							__UpperCAmelCase			:							Dict	    =	input_size * len(self.lags_sequence) + self._number_of_features
							__UpperCAmelCase			:							Optional[int]	    =	d_model
							__UpperCAmelCase			:							List[Any]	    =	encoder_attention_heads
							__UpperCAmelCase			:							int	    =	decoder_attention_heads
							__UpperCAmelCase			:							str	    =	encoder_ffn_dim
							__UpperCAmelCase			:							int	    =	decoder_ffn_dim
							__UpperCAmelCase			:							List[Any]	    =	encoder_layers
							__UpperCAmelCase			:							Tuple	    =	decoder_layers

							__UpperCAmelCase			:							Union[str, Any]	    =	dropout
							__UpperCAmelCase			:							int	    =	attention_dropout
							__UpperCAmelCase			:							int	    =	activation_dropout
							__UpperCAmelCase			:							str	    =	encoder_layerdrop
							__UpperCAmelCase			:							Dict	    =	decoder_layerdrop

							__UpperCAmelCase			:							int	    =	activation_function
							__UpperCAmelCase			:							Optional[int]	    =	init_std

							__UpperCAmelCase			:							Optional[int]	    =	use_cache

							# Autoformer
							__UpperCAmelCase			:							str	    =	label_length
							__UpperCAmelCase			:							int	    =	moving_average
							__UpperCAmelCase			:							Optional[int]	    =	autocorrelation_factor

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


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

