
from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

__lowerCAmelCase     :	str       			=  TypeVar('T')
__lowerCAmelCase     :	Optional[int]       			=  TypeVar('U')




class 			UpperCAmelCase_     (					Generic[T, U]	):


  '''simple docstring'''







  def __init__(					self     :					Any     ,				UpperCamelCase__     :					T | None     ,				UpperCamelCase__     :					U | None       )     ->      int:







    """simple docstring"""






    __magic_name__								=			key
    __magic_name__								=			val
    __magic_name__								=			None
    __magic_name__								=			None





  def __repr__(					self     :					int       )     ->      str:







    """simple docstring"""






    return (
        F'''Node: key: {self.key}, val: {self.val}, '''
        F'''has next: {bool(self.next       )}, has prev: {bool(self.prev       )}'''
    )







class 			UpperCAmelCase_     (					Generic[T, U]	):


  '''simple docstring'''







  def __init__(					self     :					Tuple       )     ->      None:







    """simple docstring"""






    __magic_name__								=			DoubleLinkedListNode(UpperCamelCase__     ,				UpperCamelCase__       )
    __magic_name__								=			DoubleLinkedListNode(UpperCamelCase__     ,				UpperCamelCase__       )
    __magic_name__	,       __magic_name__								=			self.rear, self.head
  def __repr__(					self     :					Optional[int]       )     ->      str:







    """simple docstring"""






    __magic_name__								=			["""DoubleLinkedList"""]
    __magic_name__								=			self.head
    while node.next is not None:
      rep.append(str(UpperCamelCase__       )       )
      __magic_name__								=			node.next
    rep.append(str(self.rear       )       )
    return ",\n    ".join(UpperCamelCase__       )
  def 				_lowercase				(					self     :					Union[str, Any]     ,				UpperCamelCase__     :					DoubleLinkedListNode[T, U]       )     ->      None:







    """simple docstring"""






    __magic_name__								=			self.rear.prev

    # All nodes other than self.head are guaranteed to have non-None previous
    assert previous is not None

    __magic_name__								=			node
    __magic_name__								=			previous
    __magic_name__								=			node
    __magic_name__								=			self.rear





  def 				_lowercase				(					self     :					str     ,				UpperCamelCase__     :					DoubleLinkedListNode[T, U]       )     ->      DoubleLinkedListNode[T, U] | None:







    """simple docstring"""






    if node.prev is None or node.next is None:
      return None

    __magic_name__								=			node.next
    __magic_name__								=			node.prev
    __magic_name__								=			None
    __magic_name__								=			None
    return node







class 			UpperCAmelCase_     (					Generic[T, U]	):


  '''simple docstring'''







  a__       			=						{}
  def __init__(					self     :					Optional[Any]     ,				UpperCamelCase__     :					int       )     ->      Any:







    """simple docstring"""






    __magic_name__								=			DoubleLinkedList()
    __magic_name__								=			capacity
    __magic_name__								=			0
    __magic_name__								=			0
    __magic_name__								=			0
    __magic_name__								=			{}
  def __repr__(					self     :					List[str]       )     ->      str:







    """simple docstring"""






    return (
        F'''CacheInfo(hits={self.hits}, misses={self.miss}, '''
        F'''capacity={self.capacity}, current size={self.num_keys})'''
    )
  def __contains__(					self     :					str     ,				UpperCamelCase__     :					T       )     ->      bool:







    """simple docstring"""






    return key in self.cache
  def 				_lowercase				(					self     :					Union[str, Any]     ,				UpperCamelCase__     :					T       )     ->      U | None:







    """simple docstring"""






    if key in self.cache:
      self.hits += 1
      __magic_name__								=			self.cache[key]
      __magic_name__								=			self.list.remove(self.cache[key]       )
      assert node == value_node

      # node is guaranteed not None because it is in self.cache
      assert node is not None
      self.list.add(UpperCamelCase__       )
      return node.val
    self.miss += 1
    return None
  def 				_lowercase				(					self     :					Optional[Any]     ,				UpperCamelCase__     :					T     ,				UpperCamelCase__     :					U       )     ->      None:







    """simple docstring"""






    if key not in self.cache:
      if self.num_keys >= self.capacity:
        # delete first node (oldest) when over capacity
        __magic_name__								=			self.list.head.next

        # guaranteed to have a non-None first node when num_keys > 0
        # explain to type checker via assertions
        assert first_node is not None
        assert first_node.key is not None
        assert (
            self.list.remove(UpperCamelCase__       ) is not None
        )  # node guaranteed to be in list assert node.key is not None

        del self.cache[first_node.key]
        self.num_keys -= 1
      __magic_name__								=			DoubleLinkedListNode(UpperCamelCase__     ,				UpperCamelCase__       )
      self.list.add(self.cache[key]       )
      self.num_keys += 1

    else:
      # bump node to the end of the list, update value
      __magic_name__								=			self.list.remove(self.cache[key]       )
      assert node is not None  # node guaranteed to be in list
      __magic_name__								=			value
      self.list.add(UpperCamelCase__       )





  @classmethod
  def 				_lowercase				(					cls     :					List[Any]     ,				UpperCamelCase__     :					int = 128       )     ->      Callable[[Callable[[T], U]], Callable[..., U]]:







    """simple docstring"""






    def cache_decorator_inner(UpperCamelCase__     :					Callable[[T], U]       ) -> Callable[..., U]:
      def cache_decorator_wrapper(*UpperCamelCase__     :					T       ) -> U:
        if func not in cls.decorator_function_to_instance_map:
          __magic_name__								=			LRUCache(UpperCamelCase__       )

        __magic_name__								=			cls.decorator_function_to_instance_map[func].get(args[0]       )
        if result is None:
          __magic_name__								=			func(*UpperCamelCase__       )
          cls.decorator_function_to_instance_map[func].put(args[0]     ,				UpperCamelCase__       )
        return result

      def cache_info() -> LRUCache[T, U]:
        return cls.decorator_function_to_instance_map[func]

      setattr(UpperCamelCase__     ,				"""cache_info"""     ,				UpperCamelCase__       )  # noqa: B010

      return cache_decorator_wrapper

    return cache_decorator_inner


if __name__ == "__main__":
    import doctest

    doctest.testmod()



from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowerCAmelCase     :	Union[str, Any]       			=  {
    'configuration_informer': [
        'INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'InformerConfig',
    ],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCAmelCase     :	Optional[Any]       			=  [
        'INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
        'InformerForPrediction',
        'InformerModel',
        'InformerPreTrainedModel',
    ]


if TYPE_CHECKING:
    from .configuration_informer import INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, InformerConfig

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_informer import (
            INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
            InformerForPrediction,
            InformerModel,
            InformerPreTrainedModel,
        )

else:
    import sys

    __lowerCAmelCase     :	List[str]       			=  _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

