


'''simple docstring'''



from typing import List, Optional

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


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

A__		:					Union[str, Any]												=  {
    """huggingface/autoformer-tourism-monthly""": """https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json""",
}





class    UpperCAmelCase_  (_UpperCAmelCase  ):





    """simple docstring"""






    lowerCamelCase  :					Dict							     =			'autoformer'
    lowerCamelCase  :					List[str]							     =			{
        'hidden_size': 'd_model',
        'num_attention_heads': 'encoder_attention_heads',
        'num_hidden_layers': 'encoder_layers',
    }







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

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

         __lowerCamelCase   :	Optional[Any]								=		dropout
         __lowerCamelCase   :	Any								=		attention_dropout
         __lowerCamelCase   :	Optional[int]								=		activation_dropout
         __lowerCamelCase   :	Any								=		encoder_layerdrop
         __lowerCamelCase   :	Optional[Any]								=		decoder_layerdrop

         __lowerCamelCase   :	int								=		activation_function
         __lowerCamelCase   :	str								=		init_std

         __lowerCamelCase   :	Dict								=		use_cache

         # Autoformer
         __lowerCamelCase   :	Optional[Any]								=		label_length
         __lowerCamelCase   :	List[str]								=		moving_average
         __lowerCamelCase   :	Dict								=		autocorrelation_factor

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







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










'''simple docstring'''



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				List[Any]							)     ->		str:
     __lowerCamelCase   :	Tuple								=		0
     __lowerCamelCase   :	Optional[int]								=		len(UpperCAmelCase_							)

     for i in range(n - 1							):
          for j in range(i + 1      ,    UpperCAmelCase_							):
               if arr[i] > arr[j]:
                    num_inversions += 1

     return num_inversions



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				str							)     ->		Optional[int]:
     if len(UpperCAmelCase_							) <= 1:
          return arr, 0
     __lowerCamelCase   :	str								=		len(UpperCAmelCase_							) // 2
     __lowerCamelCase   :	List[Any]								=		arr[0:mid]
     __lowerCamelCase   :	List[str]								=		arr[mid:]

     __lowerCamelCase				,       __lowerCamelCase   :	int								=		count_inversions_recursive(UpperCAmelCase_							)
     __lowerCamelCase				,       __lowerCamelCase   :	Optional[Any]								=		count_inversions_recursive(UpperCAmelCase_							)
     __lowerCamelCase				,       __lowerCamelCase   :	Any								=		_count_cross_inversions(UpperCAmelCase_      ,    UpperCAmelCase_							)

     __lowerCamelCase   :	Optional[int]								=		inversion_p + inversions_q + cross_inversions
     return c, num_inversions



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				List[Any]      ,    UpperCAmelCase_    :				List[str]							)     ->		Optional[Any]:
     __lowerCamelCase   :	List[str]								=		[]
     __lowerCamelCase   :	Optional[int]								=		0
     while i < len(UpperCAmelCase_							) and j < len(UpperCAmelCase_							):
          if p[i] > q[j]:
               # if P[1] > Q[j], then P[k] > Q[k] for all  i < k <= len(P)
               # These are all inversions. The claim emerges from the
               # property that P is sorted.
               num_inversion += len(UpperCAmelCase_							) - i
               r.append(q[j]							)
               j += 1
          else:
               r.append(p[i]							)
               i += 1

     if i < len(UpperCAmelCase_							):
          r.extend(p[i:]							)
     else:
          r.extend(q[j:]							)

     return r, num_inversion



def 			UpperCAmelCase__					(	)     ->		List[str]:
     __lowerCamelCase   :	Any								=		[10, 2, 1, 5, 5, 2, 11]

     # this arr has 8 inversions:
     # (10, 2), (10, 1), (10, 5), (10, 5), (10, 2), (2, 1), (5, 2), (5, 2)

     __lowerCamelCase   :	Optional[Any]								=		count_inversions_bf(UpperCAmelCase_							)
     __lowerCamelCase				,       __lowerCamelCase   :	Dict								=		count_inversions_recursive(UpperCAmelCase_							)

     assert num_inversions_bf == num_inversions_recursive == 8

     print('number of inversions = '      ,    UpperCAmelCase_							)

     # testing an array with zero inversion (a sorted arr_1)

     arr_a.sort()
     __lowerCamelCase   :	Optional[Any]								=		count_inversions_bf(UpperCAmelCase_							)
     __lowerCamelCase				,       __lowerCamelCase   :	int								=		count_inversions_recursive(UpperCAmelCase_							)

     assert num_inversions_bf == num_inversions_recursive == 0
     print('number of inversions = '      ,    UpperCAmelCase_							)

     # an empty list should also have zero inversions
     __lowerCamelCase   :	Dict								=		[]
     __lowerCamelCase   :	Optional[Any]								=		count_inversions_bf(UpperCAmelCase_							)
     __lowerCamelCase				,       __lowerCamelCase   :	Union[str, Any]								=		count_inversions_recursive(UpperCAmelCase_							)

     assert num_inversions_bf == num_inversions_recursive == 0
     print('number of inversions = '      ,    UpperCAmelCase_							)


if __name__ == "__main__":
      main()






