
import warnings
from typing import List

import numpy as np

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
from ...utils import is_flax_available, is_tf_available, is_torch_available






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''
   __UpperCamelCase		:    Optional[int] 				=    ['''image_processor''', '''tokenizer''']
   __UpperCamelCase		:    Any 				=    '''OwlViTImageProcessor'''
   __UpperCamelCase		:    Union[str, Any] 				=    ('''CLIPTokenizer''', '''CLIPTokenizerFast''')


   def __init__(					self     :							Dict			,			lowerCAmelCase_     :							List[Any]=None			,			lowerCAmelCase_     :							List[Any]=None			,			**lowerCAmelCase_     :							Dict     ):

      """simple docstring"""
      _A:  List[Any]					=       None
      if "feature_extractor" in kwargs:
         warnings.warn(
             '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
             ''' instead.'''			,			lowerCAmelCase_			,			)
         _A:  List[Any]					=       kwargs.pop('''feature_extractor'''     )

      _A:  List[Any]					=       image_processor if image_processor is not None else feature_extractor
      if image_processor is None:
         raise ValueError('''You need to specify an `image_processor`.'''     )
      if tokenizer is None:
         raise ValueError('''You need to specify a `tokenizer`.'''     )

      super().__init__(lowerCAmelCase_			,			lowerCAmelCase_     )


   def __call__(					self     :							Dict			,			lowerCAmelCase_     :							Tuple=None			,			lowerCAmelCase_     :							Dict=None			,			lowerCAmelCase_     :							List[str]=None			,			lowerCAmelCase_     :							Union[str, Any]="max_length"			,			lowerCAmelCase_     :							Tuple="np"			,			**lowerCAmelCase_     :							Union[str, Any]     ):

      """simple docstring"""

      if text is None and query_images is None and images is None:
         raise ValueError(
             '''You have to specify at least one text or query image or image. All three cannot be none.'''     )

      if text is not None:
         if isinstance(lowerCAmelCase_			,			lowerCAmelCase_     ) or (isinstance(lowerCAmelCase_			,			lowerCAmelCase_     ) and not isinstance(text[0]			,			lowerCAmelCase_     )):
            _A:  Any					=       [self.tokenizer(lowerCAmelCase_			,			padding=lowerCAmelCase_			,			return_tensors=lowerCAmelCase_			,			**lowerCAmelCase_     )]

         elif isinstance(lowerCAmelCase_			,			lowerCAmelCase_     ) and isinstance(text[0]			,			lowerCAmelCase_     ):
            _A:  List[str]					=       []

            # Maximum number of queries across batch
            _A:  Optional[int]					=       max([len(lowerCAmelCase_     ) for t in text]     )

            # Pad all batch samples to max number of text queries
            for t in text:
               if len(lowerCAmelCase_     ) != max_num_queries:
                  _A:  Any					=       t + [''' '''] * (max_num_queries - len(lowerCAmelCase_     ))

               _A:  Dict					=       self.tokenizer(lowerCAmelCase_			,			padding=lowerCAmelCase_			,			return_tensors=lowerCAmelCase_			,			**lowerCAmelCase_     )
               encodings.append(lowerCAmelCase_     )
         else:
            raise TypeError('''Input text should be a string, a list of strings or a nested list of strings'''     )

         if return_tensors == "np":
            _A:  Optional[int]					=       np.concatenate([encoding['''input_ids'''] for encoding in encodings]			,			axis=0     )
            _A:  Union[str, Any]					=       np.concatenate([encoding['''attention_mask'''] for encoding in encodings]			,			axis=0     )

         elif return_tensors == "jax" and is_flax_available():
            import jax.numpy as jnp

            _A:  Dict					=       jnp.concatenate([encoding['''input_ids'''] for encoding in encodings]			,			axis=0     )
            _A:  str					=       jnp.concatenate([encoding['''attention_mask'''] for encoding in encodings]			,			axis=0     )

         elif return_tensors == "pt" and is_torch_available():
            import torch

            _A:  Any					=       torch.cat([encoding['''input_ids'''] for encoding in encodings]			,			dim=0     )
            _A:  Optional[Any]					=       torch.cat([encoding['''attention_mask'''] for encoding in encodings]			,			dim=0     )

         elif return_tensors == "tf" and is_tf_available():
            import tensorflow as tf

            _A:  str					=       tf.stack([encoding['''input_ids'''] for encoding in encodings]			,			axis=0     )
            _A:  List[str]					=       tf.stack([encoding['''attention_mask'''] for encoding in encodings]			,			axis=0     )

         else:
            raise ValueError('''Target return tensor type could not be returned'''     )

         _A:  Dict					=       BatchEncoding()
         _A:  Optional[int]					=       input_ids
         _A:  int					=       attention_mask

      if query_images is not None:
         _A:  str					=       BatchEncoding()
         _A:  List[Any]					=       self.image_processor(
             lowerCAmelCase_			,			return_tensors=lowerCAmelCase_			,			**lowerCAmelCase_     ).pixel_values
         _A:  Dict					=       query_pixel_values

      if images is not None:
         _A:  Dict					=       self.image_processor(lowerCAmelCase_			,			return_tensors=lowerCAmelCase_			,			**lowerCAmelCase_     )

      if text is not None and images is not None:
         _A:  Optional[Any]					=       image_features.pixel_values
         return encoding
      elif query_images is not None and images is not None:
         _A:  Tuple					=       image_features.pixel_values
         return encoding
      elif text is not None or query_images is not None:
         return encoding
      else:
         return BatchEncoding(data=dict(**lowerCAmelCase_     )			,			tensor_type=lowerCAmelCase_     )


   def  __magic_name__				(					self     :							List[Any]			,			*lowerCAmelCase_     :							List[Any]			,			**lowerCAmelCase_     :							Dict     ):

      """simple docstring"""
      return self.image_processor.post_process(*lowerCAmelCase_			,			**lowerCAmelCase_     )


   def  __magic_name__				(					self     :							Optional[Any]			,			*lowerCAmelCase_     :							int			,			**lowerCAmelCase_     :							int     ):

      """simple docstring"""
      return self.image_processor.post_process_object_detection(*lowerCAmelCase_			,			**lowerCAmelCase_     )


   def  __magic_name__				(					self     :							Optional[int]			,			*lowerCAmelCase_     :							Union[str, Any]			,			**lowerCAmelCase_     :							Optional[int]     ):

      """simple docstring"""
      return self.image_processor.post_process_image_guided_detection(*lowerCAmelCase_			,			**lowerCAmelCase_     )


   def  __magic_name__				(					self     :							Optional[Any]			,			*lowerCAmelCase_     :							Any			,			**lowerCAmelCase_     :							Optional[int]     ):

      """simple docstring"""
      return self.tokenizer.batch_decode(*lowerCAmelCase_			,			**lowerCAmelCase_     )


   def  __magic_name__				(					self     :							int			,			*lowerCAmelCase_     :							Optional[int]			,			**lowerCAmelCase_     :							Optional[int]     ):

      """simple docstring"""
      return self.tokenizer.decode(*lowerCAmelCase_			,			**lowerCAmelCase_     )


   @property
   def  __magic_name__				(					self     :							List[str]     ):

      """simple docstring"""
      warnings.warn(
          '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''			,			lowerCAmelCase_			,			)
      return self.image_processor_class


   @property
   def  __magic_name__				(					self     :							Tuple     ):

      """simple docstring"""
      warnings.warn(
          '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'''			,			lowerCAmelCase_			,			)
      return self.image_processor





from typing import List, Optional, Union

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


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

UpperCAmelCase__		:     Any     			=      {
    '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 UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''
   __UpperCamelCase		:    List[Any] 				=    '''informer'''
   __UpperCamelCase		:    List[str] 				=    {
       '''hidden_size''': '''d_model''',
       '''num_attention_heads''': '''encoder_attention_heads''',
       '''num_hidden_layers''': '''encoder_layers''',
   }


   def __init__(					self     :							Optional[Any]			,			lowerCAmelCase_     :							Optional[int] = None			,			lowerCAmelCase_     :							Optional[int] = None			,			lowerCAmelCase_     :							str = "student_t"			,			lowerCAmelCase_     :							str = "nll"			,			lowerCAmelCase_     :							int = 1			,			lowerCAmelCase_     :							List[int] = None			,			lowerCAmelCase_     :							Optional[Union[str, bool]] = "mean"			,			lowerCAmelCase_     :							int = 0			,			lowerCAmelCase_     :							int = 0			,			lowerCAmelCase_     :							int = 0			,			lowerCAmelCase_     :							int = 0			,			lowerCAmelCase_     :							Optional[List[int]] = None			,			lowerCAmelCase_     :							Optional[List[int]] = None			,			lowerCAmelCase_     :							int = 6_4			,			lowerCAmelCase_     :							int = 3_2			,			lowerCAmelCase_     :							int = 3_2			,			lowerCAmelCase_     :							int = 2			,			lowerCAmelCase_     :							int = 2			,			lowerCAmelCase_     :							int = 2			,			lowerCAmelCase_     :							int = 2			,			lowerCAmelCase_     :							bool = True			,			lowerCAmelCase_     :							str = "gelu"			,			lowerCAmelCase_     :							float = 0.05			,			lowerCAmelCase_     :							float = 0.1			,			lowerCAmelCase_     :							float = 0.1			,			lowerCAmelCase_     :							float = 0.1			,			lowerCAmelCase_     :							float = 0.1			,			lowerCAmelCase_     :							int = 1_0_0			,			lowerCAmelCase_     :							float = 0.02			,			lowerCAmelCase_     :							Tuple=True			,			lowerCAmelCase_     :							str = "prob"			,			lowerCAmelCase_     :							int = 5			,			lowerCAmelCase_     :							bool = True			,			**lowerCAmelCase_     :							str			,			):

      """simple docstring"""
      # time series specific configuration
      _A:  Optional[Any]					=       prediction_length
      _A:  Optional[Any]					=       context_length or prediction_length
      _A:  Dict					=       distribution_output
      _A:  List[str]					=       loss
      _A:  int					=       input_size
      _A:  List[str]					=       num_time_features
      _A:  Optional[Any]					=       lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
      _A:  str					=       scaling
      _A:  Optional[Any]					=       num_dynamic_real_features
      _A:  List[Any]					=       num_static_real_features
      _A:  Tuple					=       num_static_categorical_features

      # set cardinality
      if cardinality and num_static_categorical_features > 0:
         if len(lowerCAmelCase_     ) != num_static_categorical_features:
            raise ValueError(
                '''The cardinality should be a list of the same length as `num_static_categorical_features`'''     )
         _A:  str					=       cardinality
      else:
         _A:  Union[str, Any]					=       [0]

      # set embedding_dimension
      if embedding_dimension and num_static_categorical_features > 0:
         if len(lowerCAmelCase_     ) != num_static_categorical_features:
            raise ValueError(
                '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''     )
         _A:  List[str]					=       embedding_dimension
      else:
         _A:  Union[str, Any]					=       [min(5_0			,			(cat + 1) // 2     ) for cat in self.cardinality]

      _A:  int					=       num_parallel_samples

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

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

      _A:  int					=       activation_function
      _A:  Tuple					=       init_std

      _A:  Union[str, Any]					=       use_cache

      # Informer
      _A:  Union[str, Any]					=       attention_type
      _A:  str					=       sampling_factor
      _A:  List[str]					=       distil

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


   @property
   def  __magic_name__				(					self     :							List[str]     ):

      """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
      )



