

from __future__ import annotations

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

_lowerCamelCase							       =TypeVar("T")
_lowerCamelCase							       =TypeVar("U")



class 		a_       (							Generic[T, U]     ):



      """simple docstring"""







      def __init__(      self     :							Optional[int]			,snake_case     :							T | None			,snake_case     :							U | None				):
           SCREAMING_SNAKE_CASE      						=key
           SCREAMING_SNAKE_CASE      						=val
           SCREAMING_SNAKE_CASE      						=None
           SCREAMING_SNAKE_CASE      						=None


      def __repr__(      self     :							int				):
           return (
               f'Node: key: {self.key}, val: {self.val}, '
               f'has next: {bool(self.next				)}, has prev: {bool(self.prev				)}'
           )







class 		a_       (							Generic[T, U]     ):



      """simple docstring"""







      def __init__(      self     :							Any				):
           SCREAMING_SNAKE_CASE      						=DoubleLinkedListNode(__snake_case			,__snake_case				)
           SCREAMING_SNAKE_CASE      						=DoubleLinkedListNode(__snake_case			,__snake_case				)
           SCREAMING_SNAKE_CASE      						=self.rear, self.head
      def __repr__(      self     :							List[str]				):
           SCREAMING_SNAKE_CASE      						=['''DoubleLinkedList''']
           SCREAMING_SNAKE_CASE      						=self.head
           while node.next is not None:
                rep.append(str(__snake_case				)				)
                SCREAMING_SNAKE_CASE      						=node.next
           rep.append(str(self.rear				)				)
           return ",\n    ".join(__snake_case				)
      def        _lowerCAmelCase     (      self     :							List[str]			,snake_case     :							DoubleLinkedListNode[T, U]				):
           SCREAMING_SNAKE_CASE      						=self.rear.prev

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

           SCREAMING_SNAKE_CASE      						=node
           SCREAMING_SNAKE_CASE      						=previous
           SCREAMING_SNAKE_CASE      						=node
           SCREAMING_SNAKE_CASE      						=self.rear


      def        _lowerCAmelCase     (      self     :							Dict			,snake_case     :							DoubleLinkedListNode[T, U]				):

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

           SCREAMING_SNAKE_CASE      						=node.next
           SCREAMING_SNAKE_CASE      						=node.prev
           SCREAMING_SNAKE_CASE      						=None
           SCREAMING_SNAKE_CASE      						=None
           return node







class 		a_       (							Generic[T, U]     ):



      """simple docstring"""







      __UpperCAmelCase					=      {}
      def __init__(      self     :							Dict			,snake_case     :							int				):
           SCREAMING_SNAKE_CASE      						=DoubleLinkedList()
           SCREAMING_SNAKE_CASE      						=capacity
           SCREAMING_SNAKE_CASE      						=0
           SCREAMING_SNAKE_CASE      						=0
           SCREAMING_SNAKE_CASE      						=0
           SCREAMING_SNAKE_CASE      						={}
      def __repr__(      self     :							Optional[int]				):
           return (
               f'CacheInfo(hits={self.hits}, misses={self.miss}, '
               f'capacity={self.capacity}, current size={self.num_keys})'
           )
      def __contains__(      self     :							str			,snake_case     :							T				):
           return key in self.cache
      def        _lowerCAmelCase     (      self     :							Optional[Any]			,snake_case     :							T				):
           # Note: pythonic interface would throw KeyError rather than return None

           if key in self.cache:
                self.hits += 1
                SCREAMING_SNAKE_CASE      						=self.cache[key]
                SCREAMING_SNAKE_CASE      						=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(__snake_case				)
                return node.val
           self.miss += 1
           return None
      def        _lowerCAmelCase     (      self     :							str			,snake_case     :							T			,snake_case     :							U				):

           if key not in self.cache:
                if self.num_keys >= self.capacity:
                     # delete first node (oldest) when over capacity
                     SCREAMING_SNAKE_CASE      						=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(__snake_case				) 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
                SCREAMING_SNAKE_CASE      						=DoubleLinkedListNode(__snake_case			,__snake_case				)
                self.list.add(self.cache[key]				)
                self.num_keys += 1

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


      @classmethod
      def        _lowerCAmelCase     (      cls     :							List[str]			,snake_case     :							int = 128				):

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

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

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

                setattr(__snake_case			,'cache_info'			,__snake_case				)  # noqa: B010

                return cache_decorator_wrapper

           return cache_decorator_inner


if __name__ == "__main__":
 import doctest

 doctest.testmod()






'''simple docstring'''






import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin

class 				SCREAMING_SNAKE_CASE(							A__			):







	"""simple docstring"""






	lowerCamelCase__			 =       """MCTCTFeatureExtractor"""
	lowerCamelCase__			 =       """AutoTokenizer"""







	def __init__(						self			:     Dict		,			__snake_case			:     Optional[int]		,			__snake_case			:     List[str]		)			->		str:
								super().__init__(__snake_case		,			__snake_case		)
								UpperCAmelCase :       List[Any] 							=		self.feature_extractor
								UpperCAmelCase :       Union[str, Any] 							=		False







	def __call__(						self			:     Any		,			*__snake_case			:     List[str]		,			**__snake_case			:     Any		)			->		List[Any]:
								# For backward compatibility
								if self._in_target_context_manager:
															return self.current_processor(*__snake_case		,			**__snake_case		)

								if "raw_speech" in kwargs:
															warnings.warn('''Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'''		)
															UpperCAmelCase :       int 							=		kwargs.pop('''raw_speech'''		)
								else:
															UpperCAmelCase :       Union[str, Any] 							=		kwargs.pop('''audio'''		,			__snake_case		)
								UpperCAmelCase :       Optional[Any] 							=		kwargs.pop('''sampling_rate'''		,			__snake_case		)
								UpperCAmelCase :       Dict 							=		kwargs.pop('''text'''		,			__snake_case		)
								if len(__snake_case		) > 0:
															UpperCAmelCase :       Any 							=		args[0]
															UpperCAmelCase :       Optional[int] 							=		args[1:]

								if audio is None and text is None:
															raise ValueError('''You need to specify either an `audio` or `text` input to process.'''		)

								if audio is not None:
															UpperCAmelCase :       List[str] 							=		self.feature_extractor(__snake_case		,			*__snake_case		,			sampling_rate=__snake_case		,			**__snake_case		)
								if text is not None:
															UpperCAmelCase :       int 							=		self.tokenizer(__snake_case		,			**__snake_case		)

								if text is None:
															return inputs
								elif audio is None:
															return encodings
								else:
															UpperCAmelCase :       str 							=		encodings['''input_ids''']
															return inputs







	def      A	(						self			:     List[Any]		,			*__snake_case			:     List[Any]		,			**__snake_case			:     List[Any]		)			->		str:
								return self.tokenizer.batch_decode(*__snake_case		,			**__snake_case		)







	def      A	(						self			:     List[Any]		,			*__snake_case			:     int		,			**__snake_case			:     Optional[int]		)			->		Any:
								# For backward compatibility
								if self._in_target_context_manager:
															return self.current_processor.pad(*__snake_case		,			**__snake_case		)

								UpperCAmelCase :       List[Any] 							=		kwargs.pop('''input_features'''		,			__snake_case		)
								UpperCAmelCase :       Optional[Any] 							=		kwargs.pop('''labels'''		,			__snake_case		)
								if len(__snake_case		) > 0:
															UpperCAmelCase :       List[str] 							=		args[0]
															UpperCAmelCase :       List[Any] 							=		args[1:]

								if input_features is not None:
															UpperCAmelCase :       Tuple 							=		self.feature_extractor.pad(__snake_case		,			*__snake_case		,			**__snake_case		)
								if labels is not None:
															UpperCAmelCase :       Optional[int] 							=		self.tokenizer.pad(__snake_case		,			**__snake_case		)

								if labels is None:
															return input_features
								elif input_features is None:
															return labels
								else:
															UpperCAmelCase :       List[str] 							=		labels['''input_ids''']
															return input_features







	def      A	(						self			:     Union[str, Any]		,			*__snake_case			:     Optional[Any]		,			**__snake_case			:     Optional[int]		)			->		Optional[Any]:
								return self.tokenizer.decode(*__snake_case		,			**__snake_case		)







	@contextmanager
	def      A	(						self			:     Any		)			->		Optional[int]:
								warnings.warn(
								    '''`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '''
								    '''labels by using the argument `text` of the regular `__call__` method (either in the same call as '''
								    '''your audio inputs, or in a separate call.'''		)
								UpperCAmelCase :       Dict 							=		True
								UpperCAmelCase :       List[Any] 							=		self.tokenizer
								yield
								UpperCAmelCase :       Tuple 							=		self.feature_extractor
								UpperCAmelCase :       List[Any] 							=		False





