


'''simple docstring'''

from typing import List, Optional, Union

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


lowerCamelCase							:   Any  						=	logging.get_logger(__name__)

lowerCamelCase							:   Dict  						=	{
    'huggingface/time-series-transformer-tourism-monthly': (
        'https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json'
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}
class   __lowerCAmelCase						(lowercase_     ):





      '''simple docstring'''






      lowerCAmelCase__					:     Optional[Any]  					=							"""time_series_transformer"""
      lowerCAmelCase__					:     Optional[int]  					=							{
          """hidden_size""": """d_model""",
          """num_attention_heads""": """encoder_attention_heads""",
          """num_hidden_layers""": """encoder_layers""",
      }



      def __init__(self    :    Any   ,						UpperCamelCase    :    Optional[int] = None   ,						UpperCamelCase    :    Optional[int] = None   ,						UpperCamelCase    :    str = "student_t"   ,						UpperCamelCase    :    str = "nll"   ,						UpperCamelCase    :    int = 1   ,						UpperCamelCase    :    List[int] = [1, 2, 3, 4, 5, 6, 7]   ,						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 = 32   ,						UpperCamelCase    :    int = 32   ,						UpperCamelCase    :    int = 2   ,						UpperCamelCase    :    int = 2   ,						UpperCamelCase    :    int = 2   ,						UpperCamelCase    :    int = 2   ,						UpperCamelCase    :    bool = True   ,						UpperCamelCase    :    str = "gelu"   ,						UpperCamelCase    :    int = 64   ,						UpperCamelCase    :    float = 0.1   ,						UpperCamelCase    :    float = 0.1   ,						UpperCamelCase    :    float = 0.1   ,						UpperCamelCase    :    float = 0.1   ,						UpperCamelCase    :    float = 0.1   ,						UpperCamelCase    :    int = 100   ,						UpperCamelCase    :    float = 0.02   ,						UpperCamelCase    :    Tuple=True   ,						**UpperCamelCase    :    Optional[Any]   ,						):

             '''simple docstring'''







             lowercase__      			= prediction_length
             lowercase__      			= context_length or prediction_length
             lowercase__      			= distribution_output
             lowercase__      			= loss
             lowercase__      			= input_size
             lowercase__      			= num_time_features
             lowercase__      			= lags_sequence
             lowercase__      			= scaling
             lowercase__      			= num_dynamic_real_features
             lowercase__      			= num_static_real_features
             lowercase__      			= num_static_categorical_features
             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`''' )
                    lowercase__      			= cardinality
             else:
                    lowercase__      			= [0]
             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`''' )
                    lowercase__      			= embedding_dimension
             else:
                    lowercase__      			= [min(50   ,						(cat + 1) // 2 ) for cat in self.cardinality]
             lowercase__      			= num_parallel_samples

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

             lowercase__      			= dropout
             lowercase__      			= attention_dropout
             lowercase__      			= activation_dropout
             lowercase__      			= encoder_layerdrop
             lowercase__      			= decoder_layerdrop

             lowercase__      			= activation_function
             lowercase__      			= init_std

             lowercase__      			= use_cache

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






      @property
      def       UpperCamelCase__		(self    :    Optional[int] ):

             '''simple docstring'''







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

class   __lowerCAmelCase						:  # Public class to implement a graph





      '''simple docstring'''






      def __init__(self    :    int   ,						UpperCamelCase    :    int   ,						UpperCamelCase    :    int   ,						UpperCamelCase    :    list[list[bool]] ):

             '''simple docstring'''







             lowercase__      			= row
             lowercase__      			= col
             lowercase__      			= graph



      def       UpperCamelCase__		(self    :    Optional[int]   ,						UpperCamelCase    :    int   ,						UpperCamelCase    :    int   ,						UpperCamelCase    :    list[list[bool]] ):

             '''simple docstring'''







             return (
                 0 <= i < self.ROW
                 and 0 <= j < self.COL
                 and not visited[i][j]
                 and self.graph[i][j]
             )



      def       UpperCamelCase__		(self    :    int   ,						UpperCamelCase    :    int   ,						UpperCamelCase    :    int   ,						UpperCamelCase    :    list[list[bool]] ):

             '''simple docstring'''







             lowercase__      			= [-1, -1, -1, 0, 0, 1, 1, 1]  # Coordinate order
             lowercase__      			= [-1, 0, 1, -1, 1, -1, 0, 1]
             lowercase__      			= True  # Make those cells visited
             for k in range(8 ):
                    if self.is_safe(i + row_nbr[k]   ,						j + col_nbr[k]   ,						UpperCamelCase ):
                           self.diffs(i + row_nbr[k]   ,						j + col_nbr[k]   ,						UpperCamelCase )






      def       UpperCamelCase__		(self    :    Dict ):  # And finally, count all islands.

             '''simple docstring'''







             lowercase__      			= [[False for j in range(self.COL )] for i in range(self.ROW )]
             lowercase__      			= 0
             for i in range(self.ROW ):
                    for j in range(self.COL ):
                           if visited[i][j] is False and self.graph[i][j] == 1:
                                  self.diffs(UpperCamelCase   ,						UpperCamelCase   ,						UpperCamelCase )
                                  count += 1
             return count




