


import os

import pytest
import yaml

from datasets.features.features import Features, Value
from datasets.info import DatasetInfo, DatasetInfosDict




@pytest.mark.parametrize(
    '''files'''      ,       [
        ['''full:README.md''', '''dataset_infos.json'''],
        ['''empty:README.md''', '''dataset_infos.json'''],
        ['''dataset_infos.json'''],
        ['''full:README.md'''],
    ]      ,       )
def     __SCREAMING_SNAKE_CASE							(       lowercase_      ,       lowercase_      )		->     int:




						'''simple docstring'''







						__UpperCAmelCase			:							Tuple	    =	tmp_path_factory.mktemp('''dset_infos_dir'''      )
						if "full:README.md" in files:
												with open(dataset_infos_dir / '''README.md'''      ,       '''w'''      ) as f:
																		f.write('''---\ndataset_info:\n  dataset_size: 42\n---'''      )
						if "empty:README.md" in files:
												with open(dataset_infos_dir / '''README.md'''      ,       '''w'''      ) as f:
																		f.write(''''''      )
    # we want to support dataset_infos.json for backward compatibility
						if "dataset_infos.json" in files:
												with open(dataset_infos_dir / '''dataset_infos.json'''      ,       '''w'''      ) as f:
																		f.write('''{"default": {"dataset_size": 42}}'''      )
						__UpperCAmelCase			:							str	    =	DatasetInfosDict.from_directory(lowercase_      )
						assert dataset_infos
						assert dataset_infos["default"].dataset_size == 42




@pytest.mark.parametrize(
    '''dataset_info'''      ,       [
        DatasetInfo(),
        DatasetInfo(
            description='''foo'''      ,       features=Features({'''a''': Value('''int32'''      )}      )      ,       builder_name='''builder'''      ,       config_name='''config'''      ,       version='''1.0.0'''      ,       splits=[{'''name''': '''train'''}]      ,       download_size=42      ,       ),
    ]      ,       )
def     __SCREAMING_SNAKE_CASE							(       lowercase_      ,       lowercase_      )		->     List[Any]:




						'''simple docstring'''







						__UpperCAmelCase			:							int	    =	str(lowercase_      )
						dataset_info.write_to_directory(lowercase_      )
						__UpperCAmelCase			:							Union[str, Any]	    =	DatasetInfo.from_directory(lowercase_      )
						assert dataset_info == reloaded
						assert os.path.exists(os.path.join(lowercase_      ,       '''dataset_info.json'''      )      )




def     __SCREAMING_SNAKE_CASE							(       )		->     int:




						'''simple docstring'''







						__UpperCAmelCase			:							Tuple	    =	DatasetInfo(
						    description='''foo'''      ,       citation='''bar'''      ,       homepage='''https://foo.bar'''      ,       license='''CC0'''      ,       features=Features({'''a''': Value('''int32'''      )}      )      ,       post_processed={}      ,       supervised_keys=()      ,       task_templates=[]      ,       builder_name='''builder'''      ,       config_name='''config'''      ,       version='''1.0.0'''      ,       splits=[{'''name''': '''train''', '''num_examples''': 42}]      ,       download_checksums={}      ,       download_size=1337      ,       post_processing_size=442      ,       dataset_size=1234      ,       size_in_bytes=1337 + 442 + 1234      ,       )
						__UpperCAmelCase			:							List[Any]	    =	dataset_info._to_yaml_dict()
						assert sorted(lowercase_      ) == sorted(DatasetInfo._INCLUDED_INFO_IN_YAML      )
						for key in DatasetInfo._INCLUDED_INFO_IN_YAML:
												assert key in dataset_info_yaml_dict
												assert isinstance(dataset_info_yaml_dict[key]      ,       (list, dict, int, str)      )
						__UpperCAmelCase			:							List[Any]	    =	yaml.safe_dump(lowercase_      )
						__UpperCAmelCase			:							int	    =	yaml.safe_load(lowercase_      )
						assert dataset_info_yaml_dict == reloaded




def     __SCREAMING_SNAKE_CASE							(       )		->     Dict:




						'''simple docstring'''







						__UpperCAmelCase			:							List[str]	    =	DatasetInfo()
						__UpperCAmelCase			:							List[Any]	    =	dataset_info._to_yaml_dict()
						assert dataset_info_yaml_dict == {}





@pytest.mark.parametrize(
    '''dataset_infos_dict'''      ,       [
        DatasetInfosDict(),
        DatasetInfosDict({'''default''': DatasetInfo()}      ),
        DatasetInfosDict({'''my_config_name''': DatasetInfo()}      ),
        DatasetInfosDict(
            {
                '''default''': DatasetInfo(
                    description='''foo'''      ,       features=Features({'''a''': Value('''int32'''      )}      )      ,       builder_name='''builder'''      ,       config_name='''config'''      ,       version='''1.0.0'''      ,       splits=[{'''name''': '''train'''}]      ,       download_size=42      ,       )
            }      ),
        DatasetInfosDict(
            {
                '''v1''': DatasetInfo(dataset_size=42      ),
                '''v2''': DatasetInfo(dataset_size=1337      ),
            }      ),
    ]      ,       )
def     __SCREAMING_SNAKE_CASE							(       lowercase_      ,       lowercase_      )		->     str:




						'''simple docstring'''







						__UpperCAmelCase			:							Dict	    =	str(lowercase_      )
						dataset_infos_dict.write_to_directory(lowercase_      )
						__UpperCAmelCase			:							str	    =	DatasetInfosDict.from_directory(lowercase_      )

						# the config_name of the dataset_infos_dict take over the attribute
						for config_name, dataset_info in dataset_infos_dict.items():
												__UpperCAmelCase			:							List[str]	    =	config_name
												# the yaml representation doesn't include fields like description or citation
												# so we just test that we can recover what we can from the yaml
												__UpperCAmelCase			:							List[Any]	    =	DatasetInfo._from_yaml_dict(dataset_info._to_yaml_dict()      )
						assert dataset_infos_dict == reloaded

						if dataset_infos_dict:
												assert os.path.exists(os.path.join(lowercase_      ,       '''README.md'''      )      )





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
							)

