




from __future__ import annotations

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

__SCREAMING_SNAKE_CASE 						=TypeVar("""T""")
__SCREAMING_SNAKE_CASE 						=TypeVar("""U""")

class  __magic_name__						(  Generic[T, U]):
				'''simple docstring'''







				def __init__(							self:   Optional[Any]		,					_lowerCamelCase:   T | None		,					_lowerCamelCase:   U | None		):
											SCREAMING_SNAKE_CASE_   	=    key
											SCREAMING_SNAKE_CASE_   	=    val
											SCREAMING_SNAKE_CASE_   	=    None
											SCREAMING_SNAKE_CASE_   	=    None





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






class  __magic_name__						(  Generic[T, U]):
				'''simple docstring'''







				def __init__(							self:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    DoubleLinkedListNode(_lowerCamelCase		,					_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    DoubleLinkedListNode(_lowerCamelCase		,					_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    self.rear, self.head


				def __repr__(							self:   Dict		):
											SCREAMING_SNAKE_CASE_   	=    ['''DoubleLinkedList''']
											SCREAMING_SNAKE_CASE_   	=    self.head
											while node.next is not None:
																		rep.append(str(_lowerCamelCase		)		)
																		SCREAMING_SNAKE_CASE_   	=    node.next
											rep.append(str(self.rear		)		)
											return ",\n    ".join(_lowerCamelCase		)


				def     _A							(							self:   Optional[Any]		,					_lowerCamelCase:   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     _A							(							self:   Optional[int]		,					_lowerCamelCase:   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  __magic_name__						(  Generic[T, U]):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							dict[Callable[[T], U], LRUCache[T, U]]	      =					{}


				def __init__(							self:   str		,					_lowerCamelCase:   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:   List[Any]		):
											return (
											    f"CacheInfo(hits={self.hits}, misses={self.miss}, "
											    f"capacity={self.capacity}, current size={self.num_keys})"
											)


				def __contains__(							self:   List[Any]		,					_lowerCamelCase:   T		):
											return key in self.cache


				def     _A							(							self:   int		,					_lowerCamelCase:   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(_lowerCamelCase		)
																		return node.val
											self.miss += 1
											return None


				def     _A							(							self:   List[Any]		,					_lowerCamelCase:   T		,					_lowerCamelCase:   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(_lowerCamelCase		) 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(_lowerCamelCase		,					_lowerCamelCase		)
																		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(_lowerCamelCase		)





				@classmethod
				def     _A							(							cls:   int		,					_lowerCamelCase:   int = 1_28		):

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

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

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

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

																		return cache_decorator_wrapper

											return cache_decorator_inner


if __name__ == "__main__":
			import doctest

			doctest.testmod()








import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer






class  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							List[str]	      =					"Wav2Vec2FeatureExtractor"
				SCREAMING_SNAKE_CASE__					:							List[Any]	      =					"AutoTokenizer"


				def __init__(							self:   Tuple		,					_lowerCamelCase:   str		,					_lowerCamelCase:   Optional[Any]		):
											super().__init__(_lowerCamelCase		,					_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    self.feature_extractor
											SCREAMING_SNAKE_CASE_   	=    False


				@classmethod
				def     _A							(							cls:   List[Any]		,					_lowerCamelCase:   Tuple		,					**_lowerCamelCase:   List[str]		):
											try:
																		return super().from_pretrained(_lowerCamelCase		,					**_lowerCamelCase		)
											except OSError:
																		warnings.warn(
																		    f"Loading a tokenizer inside {cls.__name__} from a config that does not"
																		    ''' include a `tokenizer_class` attribute is deprecated and will be '''
																		    '''removed in v5. Please add `\'tokenizer_class\': \'Wav2Vec2CTCTokenizer\'`'''
																		    ''' attribute to either your `config.json` or `tokenizer_config.json` '''
																		    '''file to suppress this warning: '''		,					_lowerCamelCase		,					)

																		SCREAMING_SNAKE_CASE_   	=    WavaVecaFeatureExtractor.from_pretrained(_lowerCamelCase		,					**_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    WavaVecaCTCTokenizer.from_pretrained(_lowerCamelCase		,					**_lowerCamelCase		)

																		return cls(feature_extractor=_lowerCamelCase		,					tokenizer=_lowerCamelCase		)


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

											if "raw_speech" in kwargs:
																		warnings.warn('''Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'''		)
																		SCREAMING_SNAKE_CASE_   	=    kwargs.pop('''raw_speech'''		)
											else:
																		SCREAMING_SNAKE_CASE_   	=    kwargs.pop('''audio'''		,					_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    kwargs.pop('''sampling_rate'''		,					_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    kwargs.pop('''text'''		,					_lowerCamelCase		)
											if len(_lowerCamelCase		) > 0:
																		SCREAMING_SNAKE_CASE_   	=    args[0]
																		SCREAMING_SNAKE_CASE_   	=    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:
																		SCREAMING_SNAKE_CASE_   	=    self.feature_extractor(_lowerCamelCase		,					*_lowerCamelCase		,					sampling_rate=_lowerCamelCase		,					**_lowerCamelCase		)
											if text is not None:
																		SCREAMING_SNAKE_CASE_   	=    self.tokenizer(_lowerCamelCase		,					**_lowerCamelCase		)

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


				def     _A							(							self:   Optional[int]		,					*_lowerCamelCase:   str		,					**_lowerCamelCase:   List[Any]		):
											# For backward compatibility
											if self._in_target_context_manager:
																		return self.current_processor.pad(*_lowerCamelCase		,					**_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    kwargs.pop('''input_features'''		,					_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    kwargs.pop('''labels'''		,					_lowerCamelCase		)
											if len(_lowerCamelCase		) > 0:
																		SCREAMING_SNAKE_CASE_   	=    args[0]
																		SCREAMING_SNAKE_CASE_   	=    args[1:]

											if input_features is not None:
																		SCREAMING_SNAKE_CASE_   	=    self.feature_extractor.pad(_lowerCamelCase		,					*_lowerCamelCase		,					**_lowerCamelCase		)
											if labels is not None:
																		SCREAMING_SNAKE_CASE_   	=    self.tokenizer.pad(_lowerCamelCase		,					**_lowerCamelCase		)

											if labels is None:
																		return input_features
											elif input_features is None:
																		return labels
											else:
																		SCREAMING_SNAKE_CASE_   	=    labels['''input_ids''']
																		return input_features


				def     _A							(							self:   str		,					*_lowerCamelCase:   Dict		,					**_lowerCamelCase:   Dict		):
											return self.tokenizer.batch_decode(*_lowerCamelCase		,					**_lowerCamelCase		)


				def     _A							(							self:   Optional[int]		,					*_lowerCamelCase:   Optional[int]		,					**_lowerCamelCase:   Tuple		):
											return self.tokenizer.decode(*_lowerCamelCase		,					**_lowerCamelCase		)





				@contextmanager
				def     _A							(							self:   Tuple		):
											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.'''		)
											SCREAMING_SNAKE_CASE_   	=    True
											SCREAMING_SNAKE_CASE_   	=    self.tokenizer
											yield
											SCREAMING_SNAKE_CASE_   	=    self.feature_extractor
											SCREAMING_SNAKE_CASE_   	=    False


