





import os
import tempfile
import unittest
import uuid
from pathlib import Path

from transformers.testing_utils import get_tests_dir, require_soundfile, require_torch, require_vision
from transformers.tools.agent_types import AgentAudio, AgentImage, AgentText
from transformers.utils import is_soundfile_availble, is_torch_available, is_vision_available


if is_torch_available():
  import torch

if is_soundfile_availble():
  import soundfile as sf

if is_vision_available():
  from PIL import Image






def       _A  (      lowerCamelCase=""   ):
   a__	:						Any      		=  tempfile.mkdtemp()
   return os.path.join(lowerCamelCase							, str(uuid.uuida()   ) + suffix   )







@require_soundfile
@require_torch
class   __lowerCAmelCase			(					unittest.TestCase  ):





   def 	_snake_case ( self      )				->  Dict:
      """simple docstring"""





      a__	:						Optional[int]      		=  torch.rand(12					,			dtype=torch.floataa      ) - 0.5
      a__	:						int      		=  AgentAudio(snake_case      )
      a__	:						int      		=  str(agent_type.to_string()      )

      # Ensure that the tensor and the agent_type's tensor are the same
      self.assertTrue(torch.allclose(snake_case					,			agent_type.to_raw()					,			atol=1E-4      )      )

      del agent_type

      # Ensure the path remains even after the object deletion
      self.assertTrue(os.path.exists(snake_case      )      )

      # Ensure that the file contains the same value as the original tensor
      a__	:						List[str]      		=  sf.read(snake_case      )
      self.assertTrue(torch.allclose(snake_case					,			torch.tensor(snake_case      )					,			atol=1E-4      )      )





   def 	_snake_case ( self      )				->  Optional[Any]:
      """simple docstring"""





      a__	:						List[str]      		=  torch.rand(12					,			dtype=torch.floataa      ) - 0.5
      a__	:						Any      		=  get_new_path(suffix=".wav"      )
      sf.write(snake_case					,			snake_case					,			16_000      )

      a__	:						Dict      		=  AgentAudio(snake_case      )

      self.assertTrue(torch.allclose(snake_case					,			agent_type.to_raw()					,			atol=1E-4      )      )
      self.assertEqual(agent_type.to_string()					,			snake_case      )







@require_vision
@require_torch
class   __lowerCAmelCase			(					unittest.TestCase  ):





   def 	_snake_case ( self      )				->  Optional[Any]:
      """simple docstring"""





      a__	:						Any      		=  torch.randint(0					,			256					,			(64, 64, 3)      )
      a__	:						int      		=  AgentImage(snake_case      )
      a__	:						Union[str, Any]      		=  str(agent_type.to_string()      )

      # Ensure that the tensor and the agent_type's tensor are the same
      self.assertTrue(torch.allclose(snake_case					,			agent_type._tensor					,			atol=1E-4      )      )

      self.assertIsInstance(agent_type.to_raw()					,			Image.Image      )

      # Ensure the path remains even after the object deletion
      del agent_type
      self.assertTrue(os.path.exists(snake_case      )      )





   def 	_snake_case ( self      )				->  Dict:
      """simple docstring"""





      a__	:						Dict      		=  Path(get_tests_dir("fixtures/tests_samples/COCO"      )      ) / "000000039769.png"
      a__	:						str      		=  Image.open(snake_case      )
      a__	:						Any      		=  AgentImage(snake_case      )

      self.assertTrue(path.samefile(agent_type.to_string()      )      )
      self.assertTrue(image == agent_type.to_raw()      )

      # Ensure the path remains even after the object deletion
      del agent_type
      self.assertTrue(os.path.exists(snake_case      )      )





   def 	_snake_case ( self      )				->  str:
      """simple docstring"""





      a__	:						Optional[int]      		=  Path(get_tests_dir("fixtures/tests_samples/COCO"      )      ) / "000000039769.png"
      a__	:						List[Any]      		=  Image.open(snake_case      )
      a__	:						int      		=  AgentImage(snake_case      )

      self.assertFalse(path.samefile(agent_type.to_string()      )      )
      self.assertTrue(image == agent_type.to_raw()      )

      # Ensure the path remains even after the object deletion
      del agent_type
      self.assertTrue(os.path.exists(snake_case      )      )







class   __lowerCAmelCase			(					unittest.TestCase  ):





   def 	_snake_case ( self      )				->  List[Any]:
      """simple docstring"""





      a__	:						List[str]      		=  "Hey!"
      a__	:						Dict      		=  AgentText(snake_case      )

      self.assertEqual(snake_case					,			agent_type.to_string()      )
      self.assertEqual(snake_case					,			agent_type.to_raw()      )
      self.assertEqual(snake_case					,			snake_case      )








from typing import List, Optional, Union

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


SCREAMING_SNAKE_CASE__       :			Any			      =						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__       :			str			      =						{
    """huggingface/informer-tourism-monthly""": (
        """https://huggingface.co/huggingface/informer-tourism-monthly/resolve/main/config.json"""
    ),
    # See all Informer models at https://huggingface.co/models?filter=informer
}







class   __lowerCAmelCase			(					_UpperCamelCase  ):
   _UpperCamelCase :						Optional[Any]     		=				"""informer"""
   _UpperCamelCase :						Any     		=				{
       """hidden_size""": """d_model""",
       """num_attention_heads""": """encoder_attention_heads""",
       """num_hidden_layers""": """encoder_layers""",
   }





   def __init__( self					,			snake_case = None					,			snake_case = None					,			snake_case = "student_t"					,			snake_case = "nll"					,			snake_case = 1					,			snake_case = None					,			snake_case = "mean"					,			snake_case = 0					,			snake_case = 0					,			snake_case = 0					,			snake_case = 0					,			snake_case = None					,			snake_case = None					,			snake_case = 64					,			snake_case = 32					,			snake_case = 32					,			snake_case = 2					,			snake_case = 2					,			snake_case = 2					,			snake_case = 2					,			snake_case = True					,			snake_case = "gelu"					,			snake_case = 0.05					,			snake_case = 0.1					,			snake_case = 0.1					,			snake_case = 0.1					,			snake_case = 0.1					,			snake_case = 100					,			snake_case = 0.02					,			snake_case=True					,			snake_case = "prob"					,			snake_case = 5					,			snake_case = True					,			**snake_case					,			)				->  Union[str, Any]:
      """simple docstring"""





      a__	:						Optional[Any]      		=  prediction_length
      a__	:						Optional[int]      		=  context_length or prediction_length
      a__	:						Optional[int]      		=  distribution_output
      a__	:						str      		=  loss
      a__	:						Optional[Any]      		=  input_size
      a__	:						int      		=  num_time_features
      a__	:						Optional[int]      		=  lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
      a__	:						Optional[int]      		=  scaling
      a__	:						List[str]      		=  num_dynamic_real_features
      a__	:						Optional[int]      		=  num_static_real_features
      a__	:						Optional[int]      		=  num_static_categorical_features

      # set cardinality
      if cardinality and num_static_categorical_features > 0:
         if len(snake_case      ) != num_static_categorical_features:
            raise ValueError(
                "The cardinality should be a list of the same length as `num_static_categorical_features`"      )
         a__	:						List[Any]      		=  cardinality
      else:
         a__	:						Tuple      		=  [0]

      # set embedding_dimension
      if embedding_dimension and num_static_categorical_features > 0:
         if len(snake_case      ) != num_static_categorical_features:
            raise ValueError(
                "The embedding dimension should be a list of the same length as `num_static_categorical_features`"      )
         a__	:						Tuple      		=  embedding_dimension
      else:
         a__	:						int      		=  [min(50					,			(cat + 1) // 2      ) for cat in self.cardinality]

      a__	:						Optional[Any]      		=  num_parallel_samples

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

      a__	:						List[str]      		=  dropout
      a__	:						int      		=  attention_dropout
      a__	:						List[Any]      		=  activation_dropout
      a__	:						Optional[int]      		=  encoder_layerdrop
      a__	:						Tuple      		=  decoder_layerdrop

      a__	:						Any      		=  activation_function
      a__	:						Tuple      		=  init_std

      a__	:						Optional[int]      		=  use_cache

      # Informer
      a__	:						Union[str, Any]      		=  attention_type
      a__	:						List[str]      		=  sampling_factor
      a__	:						Optional[int]      		=  distil

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





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

