




'''simple docstring'''







import os
import tempfile
from functools import partial
from unittest import TestCase
from unittest.mock import patch

import datasets
import datasets.config

from .utils import require_beam







class 					_a (datasets.BeamBasedBuilder	):





     '''simple docstring'''



     def 			snake_case_      (				self							)      ->				Optional[Any]:
          return datasets.DatasetInfo(
              features=datasets.Features({"""content""": datasets.Value("""string"""							)}							)							,supervised_keys=__a							,)







     def 			snake_case_      (				self							,__a							,__a							)      ->				Dict:
          return [datasets.SplitGenerator(name=datasets.Split.TRAIN							,gen_kwargs={"""examples""": get_test_dummy_examples()}							)]







     def 			snake_case_      (				self							,__a							,__a							)      ->				Union[str, Any]:
          import apache_beam as beam

          return pipeline | "Load Examples" >> beam.Create(__a							)







class 					_a (datasets.BeamBasedBuilder	):





     '''simple docstring'''



     def 			snake_case_      (				self							)      ->				Union[str, Any]:
          return datasets.DatasetInfo(
              features=datasets.Features({"""a""": datasets.Sequence({"""b""": datasets.Value("""string"""							)}							)}							)							,supervised_keys=__a							,)







     def 			snake_case_      (				self							,__a							,__a							)      ->				List[Any]:
          return [
              datasets.SplitGenerator(name=datasets.Split.TRAIN							,gen_kwargs={"""examples""": get_test_nested_examples()}							)
          ]







     def 			snake_case_      (				self							,__a							,__a							)      ->				Tuple:
          import apache_beam as beam

          return pipeline | "Load Examples" >> beam.Create(__a							)



def        lowerCamelCase__				(      ):
     return [(i, {"content": content}) for i, content in enumerate(["""foo""", """bar""", """foobar"""]				)]



def        lowerCamelCase__				(      ):
     return [(i, {"a": {"b": [content]}}) for i, content in enumerate(["""foo""", """bar""", """foobar"""]				)]







class 					_a (a__	):





     '''simple docstring'''



     @require_beam
     def 			snake_case_      (				self							)      ->				Optional[int]:
          snake_case			:      Dict        =			len(get_test_dummy_examples()							)
          with tempfile.TemporaryDirectory() as tmp_cache_dir:
               snake_case			:      Union[str, Any]        =			DummyBeamDataset(cache_dir=__a							,beam_runner="""DirectRunner"""							)
               builder.download_and_prepare()
               self.assertTrue(
                   os.path.exists(
                       os.path.join(__a							,builder.name							,"""default"""							,"""0.0.0"""							,F'''{builder.name}-train.arrow'''							)							)							)
               self.assertDictEqual(builder.info.features							,datasets.Features({"""content""": datasets.Value("""string"""							)}							)							)
               snake_case			:      Any        =			builder.as_dataset()
               self.assertEqual(dset["""train"""].num_rows							,__a							)
               self.assertEqual(dset["""train"""].info.splits["""train"""].num_examples							,__a							)
               self.assertDictEqual(dset["""train"""][0]							,get_test_dummy_examples()[0][1]							)
               self.assertDictEqual(
                   dset["""train"""][expected_num_examples - 1]							,get_test_dummy_examples()[expected_num_examples - 1][1]							)
               self.assertTrue(
                   os.path.exists(os.path.join(__a							,builder.name							,"""default"""							,"""0.0.0"""							,"""dataset_info.json"""							)							)							)
               del dset







     @require_beam
     def 			snake_case_      (				self							)      ->				str:
          import apache_beam as beam

          snake_case			:      Union[str, Any]        =			beam.io.parquetio.WriteToParquet

          snake_case			:      Optional[Any]        =			len(get_test_dummy_examples()							)
          with tempfile.TemporaryDirectory() as tmp_cache_dir:
               snake_case			:      Optional[Any]        =			DummyBeamDataset(cache_dir=__a							,beam_runner="""DirectRunner"""							)
               with patch("""apache_beam.io.parquetio.WriteToParquet"""							) as write_parquet_mock:
                    snake_case			:      Any        =			partial(__a							,num_shards=2							)
                    builder.download_and_prepare()
               self.assertTrue(
                   os.path.exists(
                       os.path.join(
                           __a							,builder.name							,"""default"""							,"""0.0.0"""							,F'''{builder.name}-train-00000-of-00002.arrow'''							)							)							)
               self.assertTrue(
                   os.path.exists(
                       os.path.join(
                           __a							,builder.name							,"""default"""							,"""0.0.0"""							,F'''{builder.name}-train-00000-of-00002.arrow'''							)							)							)
               self.assertDictEqual(builder.info.features							,datasets.Features({"""content""": datasets.Value("""string"""							)}							)							)
               snake_case			:      List[str]        =			builder.as_dataset()
               self.assertEqual(dset["""train"""].num_rows							,__a							)
               self.assertEqual(dset["""train"""].info.splits["""train"""].num_examples							,__a							)
               # Order is not preserved when sharding, so we just check that all the elements are there
               self.assertListEqual(sorted(dset["""train"""]["""content"""]							)							,sorted(["""foo""", """bar""", """foobar"""]							)							)
               self.assertTrue(
                   os.path.exists(os.path.join(__a							,builder.name							,"""default"""							,"""0.0.0"""							,"""dataset_info.json"""							)							)							)
               del dset







     @require_beam
     def 			snake_case_      (				self							)      ->				Tuple:
          with tempfile.TemporaryDirectory() as tmp_cache_dir:
               snake_case			:      Optional[int]        =			DummyBeamDataset(cache_dir=__a							)
               self.assertRaises(datasets.builder.MissingBeamOptions							,builder.download_and_prepare							)







     @require_beam
     def 			snake_case_      (				self							)      ->				List[Any]:
          snake_case			:      Tuple        =			len(get_test_nested_examples()							)
          with tempfile.TemporaryDirectory() as tmp_cache_dir:
               snake_case			:      int        =			NestedBeamDataset(cache_dir=__a							,beam_runner="""DirectRunner"""							)
               builder.download_and_prepare()
               self.assertTrue(
                   os.path.exists(
                       os.path.join(__a							,builder.name							,"""default"""							,"""0.0.0"""							,F'''{builder.name}-train.arrow'''							)							)							)
               self.assertDictEqual(
                   builder.info.features							,datasets.Features({"""a""": datasets.Sequence({"""b""": datasets.Value("""string"""							)}							)}							)							)
               snake_case			:      List[Any]        =			builder.as_dataset()
               self.assertEqual(dset["""train"""].num_rows							,__a							)
               self.assertEqual(dset["""train"""].info.splits["""train"""].num_examples							,__a							)
               self.assertDictEqual(dset["""train"""][0]							,get_test_nested_examples()[0][1]							)
               self.assertDictEqual(
                   dset["""train"""][expected_num_examples - 1]							,get_test_nested_examples()[expected_num_examples - 1][1]							)
               self.assertTrue(
                   os.path.exists(os.path.join(__a							,builder.name							,"""default"""							,"""0.0.0"""							,"""dataset_info.json"""							)							)							)
               del dset









'''simple docstring'''







from typing import List, Optional

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


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

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







class 					_a (a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     List[str]          =					"""autoformer"""
     lowerCAmelCase_  :     int          =					{
         """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 = True							,__a = 0							,__a = 0							,__a = 0							,__a = 0							,__a = None							,__a = None							,__a = 64							,__a = 2							,__a = 2							,__a = 2							,__a = 2							,__a = 32							,__a = 32							,__a = "gelu"							,__a = 0.1							,__a = 0.1							,__a = 0.1							,__a = 0.1							,__a = 0.1							,__a = 100							,__a = 0.02							,__a = True							,__a=True							,__a = 10							,__a = 25							,__a = 3							,**__a							,)      ->				Union[str, Any]:
          # time series specific configuration
          snake_case			:      List[str]        =			prediction_length
          snake_case			:      str        =			context_length if context_length is not None else prediction_length
          snake_case			:      List[Any]        =			distribution_output
          snake_case			:      Any        =			loss
          snake_case			:      Union[str, Any]        =			input_size
          snake_case			:      Optional[int]        =			num_time_features
          snake_case			:      Union[str, Any]        =			lags_sequence
          snake_case			:      Any        =			scaling
          snake_case			:      str        =			num_dynamic_real_features
          snake_case			:      Union[str, Any]        =			num_static_real_features
          snake_case			:      Optional[int]        =			num_static_categorical_features
          if cardinality is not None 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`"""							)
               snake_case			:      int        =			cardinality
          else:
               snake_case			:      Optional[Any]        =			[0]
          if embedding_dimension is not None 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`"""							)
               snake_case			:      int        =			embedding_dimension
          else:
               snake_case			:      List[str]        =			[min(50							,(cat + 1) // 2							) for cat in self.cardinality]
          snake_case			:      Optional[int]        =			num_parallel_samples

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

          snake_case			:      str        =			dropout
          snake_case			:      Union[str, Any]        =			attention_dropout
          snake_case			:      Optional[Any]        =			activation_dropout
          snake_case			:      Tuple        =			encoder_layerdrop
          snake_case			:      Any        =			decoder_layerdrop

          snake_case			:      Any        =			activation_function
          snake_case			:      int        =			init_std

          snake_case			:      Optional[Any]        =			use_cache

          # Autoformer
          snake_case			:      int        =			label_length
          snake_case			:      str        =			moving_average
          snake_case			:      Tuple        =			autocorrelation_factor

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







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



