



'''simple docstring'''




from typing import List, Optional, Union

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


a     :    Optional[Any]      						=					logging.get_logger(__name__)

a     :    Any      						=					{
    """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     UpperCamelCase_				(							__magic_name__    ):
 lowercase    =				'time_series_transformer'
 lowercase    =				{
     'hidden_size': 'd_model',
     'num_attention_heads': 'encoder_attention_heads',
     'num_hidden_layers': 'encoder_layers',
 }





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

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

        UpperCAmelCase  :	Optional[Any]							  =	dropout
        UpperCAmelCase  :	Dict							  =	attention_dropout
        UpperCAmelCase  :	List[Any]							  =	activation_dropout
        UpperCAmelCase  :	Union[str, Any]							  =	encoder_layerdrop
        UpperCAmelCase  :	Optional[Any]							  =	decoder_layerdrop

        UpperCAmelCase  :	Optional[Any]							  =	activation_function
        UpperCAmelCase  :	List[str]							  =	init_std

        UpperCAmelCase  :	Optional[int]							  =	use_cache

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






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




from collections.abc import Callable

import numpy as np



def    __lowerCamelCase						(      _lowercase			,       _lowercase			,       _lowercase			,       _lowercase			,       _lowercase	)   ->    np.array:
							UpperCAmelCase  :	Optional[Any]							  =	int(np.ceil((x_end - xa) / step_size	)	)
							UpperCAmelCase  :	str							  =	np.zeros((n + 1,)	)
							UpperCAmelCase  :	Optional[Any]							  =	ya
							UpperCAmelCase  :	Union[str, Any]							  =	xa

							for k in range(_lowercase	):
														UpperCAmelCase  :	Dict							  =	y[k] + step_size * ode_func(_lowercase			,       y[k]	)
														UpperCAmelCase  :	Optional[int]							  =	y[k] + (
														    (step_size / 2) * (ode_func(_lowercase			,       y[k]	) + ode_func(x + step_size			,       _lowercase	))
														)
														x += step_size

							return y


if __name__ == "__main__":
							import doctest

							doctest.testmod()

