





class 		snake_case_      :







	'''simple docstring'''




	def __init__(	self       :    Union[str, Any]				,			__lowerCamelCase       :    Optional[Any]      )					->   List[str]:

						'''simple docstring'''




						__lowercase					=    data
						__lowercase					=    None
						__lowercase					=    None






	def __str__(	self       :    List[Any]      )					->   Union[str, Any]:

						'''simple docstring'''




						return F"{self.data}"





class 		snake_case_      :







	'''simple docstring'''




	def __init__(	self       :    Union[str, Any]      )					->   Union[str, Any]:

						'''simple docstring'''




						__lowercase					=    None
						__lowercase					=    None




	def __iter__(	self       :    List[str]      )					->   Union[str, Any]:

						'''simple docstring'''




						__lowercase					=    self.head
						while node:
											yield node.data
											__lowercase					=    node.next




	def __str__(	self       :    Dict      )					->   Dict:

						'''simple docstring'''




						return "->".join([str(__lowerCamelCase      ) for item in self]      )




	def __len__(	self       :    Optional[int]      )					->   Any:

						'''simple docstring'''




						return sum(1 for _ in self      )




	def       UpperCAmelCase (	self       :    List[str]				,			__lowerCamelCase       :    List[Any]      )					->   List[Any]:

						'''simple docstring'''




						self.insert_at_nth(0				,			__lowerCamelCase      )




	def       UpperCAmelCase (	self       :    List[Any]				,			__lowerCamelCase       :    str      )					->   Optional[int]:

						'''simple docstring'''




						self.insert_at_nth(len(self      )				,			__lowerCamelCase      )




	def       UpperCAmelCase (	self       :    Tuple				,			__lowerCamelCase       :    int				,			__lowerCamelCase       :    Tuple      )					->   Tuple:

						'''simple docstring'''




						__lowercase					=    len(self      )

						if not 0 <= index <= length:
											raise IndexError('list index out of range'      )
						__lowercase					=    Node(__lowerCamelCase      )
						if self.head is None:
											__lowercase					=    __lowercase					=    new_node
						elif index == 0:
											__lowercase					=    new_node
											__lowercase					=    self.head
											__lowercase					=    new_node
						elif index == length:
											__lowercase					=    new_node
											__lowercase					=    self.tail
											__lowercase					=    new_node
						else:
											__lowercase					=    self.head
											for _ in range(0				,			__lowerCamelCase      ):
																__lowercase					=    temp.next
											__lowercase					=    new_node
											__lowercase					=    temp.previous
											__lowercase					=    temp
											__lowercase					=    new_node




	def       UpperCAmelCase (	self       :    int      )					->   Tuple:

						'''simple docstring'''




						return self.delete_at_nth(0      )




	def       UpperCAmelCase (	self       :    List[Any]      )					->   List[Any]:

						'''simple docstring'''




						return self.delete_at_nth(len(self      ) - 1      )




	def       UpperCAmelCase (	self       :    Tuple				,			__lowerCamelCase       :    int      )					->   str:

						'''simple docstring'''




						__lowercase					=    len(self      )

						if not 0 <= index <= length - 1:
											raise IndexError('list index out of range'      )
						__lowercase					=    self.head  # default first node
						if length == 1:
											__lowercase					=    __lowercase					=    None
						elif index == 0:
											__lowercase					=    self.head.next
											__lowercase					=    None
						elif index == length - 1:
											__lowercase					=    self.tail
											__lowercase					=    self.tail.previous
											__lowercase					=    None
						else:
											__lowercase					=    self.head
											for _ in range(0				,			__lowerCamelCase      ):
																__lowercase					=    temp.next
											__lowercase					=    temp
											__lowercase					=    temp.previous
											__lowercase					=    temp.next
						return delete_node.data




	def       UpperCAmelCase (	self       :    List[str]				,			__lowerCamelCase       :    Optional[int]      )					->   str:

						'''simple docstring'''




						__lowercase					=    self.head

						while current.data != data:  # Find the position to delete
											if current.next:
																__lowercase					=    current.next
											else:  # We have reached the end an no value matches
																raise ValueError('No data matching given value'      )

						if current == self.head:
											self.delete_head()

						elif current == self.tail:
											self.delete_tail()

						else:  # Before: 1 <--> 2(current) <--> 3
											__lowercase					=    current.next  # 1 --> 3
											__lowercase					=    current.previous  # 1 <--> 3
						return data






	def       UpperCAmelCase (	self       :    Optional[int]      )					->   Any:

						'''simple docstring'''




						return len(self      ) == 0





def    SCREAMING_SNAKE_CASE							(			)		->						None:
					__lowercase					=    DoublyLinkedList()
					assert linked_list.is_empty() is True
					assert str(snake_case       ) == ""

					try:
										linked_list.delete_head()
										raise AssertionError  # This should not happen.
					except IndexError:
										assert True  # This should happen.

					try:
										linked_list.delete_tail()
										raise AssertionError  # This should not happen.
					except IndexError:
										assert True  # This should happen.

					for i in range(10       ):
										assert len(snake_case       ) == i
										linked_list.insert_at_nth(snake_case	,      i + 1       )
					assert str(snake_case       ) == "->".join(str(snake_case       ) for i in range(1	,      11       )       )

					linked_list.insert_at_head(0       )
					linked_list.insert_at_tail(11       )
					assert str(snake_case       ) == "->".join(str(snake_case       ) for i in range(0	,      12       )       )

					assert linked_list.delete_head() == 0
					assert linked_list.delete_at_nth(9       ) == 10
					assert linked_list.delete_tail() == 11
					assert len(snake_case       ) == 9
					assert str(snake_case       ) == "->".join(str(snake_case       ) for i in range(1	,      10       )       )


if __name__ == "__main__":
		from doctest import testmod

		testmod()











import shutil
import tempfile
import unittest
from pathlib import Path
from shutil import copyfile

from transformers import SpeechaTextTokenizer, is_speech_available
from transformers.models.speech_to_text.tokenization_speech_to_text import VOCAB_FILES_NAMES, save_json
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_torch, require_torchaudio
from transformers.utils import FEATURE_EXTRACTOR_NAME

from .test_feature_extraction_speech_to_text import floats_list


if is_speech_available():
		from transformers import SpeechaTextFeatureExtractor, SpeechaTextProcessor


SCREAMING_SNAKE_CASE_      :			Union[str, Any]		  =      get_tests_dir('''fixtures/test_sentencepiece.model''')

@require_torch
@require_torchaudio
@require_sentencepiece
class 		snake_case_      (       unittest.TestCase	):







	'''simple docstring'''




	def       UpperCAmelCase (	self       :    List[Any]      )					->   str:

			'''simple docstring'''




			__lowercase					=    tempfile.mkdtemp()

			__lowercase					=    ['<s>', '<pad>', '</s>', '<unk>', '▁This', '▁is', '▁a', '▁t', 'est']
			__lowercase					=    dict(zip(__lowerCamelCase				,			range(len(__lowerCamelCase      )      )      )      )
			__lowercase					=    Path(self.tmpdirname      )
			save_json(__lowerCamelCase				,			save_dir / VOCAB_FILES_NAMES['vocab_file']      )
			if not (save_dir / VOCAB_FILES_NAMES["spm_file"]).exists():
					copyfile(__lowerCamelCase				,			save_dir / VOCAB_FILES_NAMES['spm_file']      )

			__lowercase					=    SpeechaTextTokenizer.from_pretrained(self.tmpdirname      )
			tokenizer.save_pretrained(self.tmpdirname      )

			__lowercase					=    {
			    'feature_size': 24,
			    'num_mel_bins': 24,
			    'padding_value': 0.0,
			    'sampling_rate': 16_000,
			    'return_attention_mask': False,
			    'do_normalize': True,
			}
			save_json(__lowerCamelCase				,			save_dir / FEATURE_EXTRACTOR_NAME      )




	def       UpperCAmelCase (	self       :    Dict				,			**__lowerCamelCase       :    Dict      )					->   Union[str, Any]:

			'''simple docstring'''




			return SpeechaTextTokenizer.from_pretrained(self.tmpdirname				,			**__lowerCamelCase      )




	def       UpperCAmelCase (	self       :    str				,			**__lowerCamelCase       :    List[str]      )					->   Tuple:

			'''simple docstring'''




			return SpeechaTextFeatureExtractor.from_pretrained(self.tmpdirname				,			**__lowerCamelCase      )




	def       UpperCAmelCase (	self       :    Optional[int]      )					->   str:

			'''simple docstring'''




			shutil.rmtree(self.tmpdirname      )




	def       UpperCAmelCase (	self       :    str      )					->   Any:

			'''simple docstring'''




			__lowercase					=    self.get_tokenizer()
			__lowercase					=    self.get_feature_extractor()

			__lowercase					=    SpeechaTextProcessor(tokenizer=__lowerCamelCase				,			feature_extractor=__lowerCamelCase      )

			processor.save_pretrained(self.tmpdirname      )
			__lowercase					=    SpeechaTextProcessor.from_pretrained(self.tmpdirname      )

			self.assertEqual(processor.tokenizer.get_vocab()				,			tokenizer.get_vocab()      )
			self.assertIsInstance(processor.tokenizer				,			__lowerCamelCase      )

			self.assertEqual(processor.feature_extractor.to_json_string()				,			feature_extractor.to_json_string()      )
			self.assertIsInstance(processor.feature_extractor				,			__lowerCamelCase      )




	def       UpperCAmelCase (	self       :    List[str]      )					->   Optional[Any]:

			'''simple docstring'''




			__lowercase					=    SpeechaTextProcessor(
			    tokenizer=self.get_tokenizer()				,			feature_extractor=self.get_feature_extractor()      )
			processor.save_pretrained(self.tmpdirname      )

			__lowercase					=    self.get_tokenizer(bos_token='(BOS)'				,			eos_token='(EOS)'      )
			__lowercase					=    self.get_feature_extractor(do_normalize=__lowerCamelCase				,			padding_value=1.0      )

			__lowercase					=    SpeechaTextProcessor.from_pretrained(
			    self.tmpdirname				,			bos_token='(BOS)'				,			eos_token='(EOS)'				,			do_normalize=__lowerCamelCase				,			padding_value=1.0      )

			self.assertEqual(processor.tokenizer.get_vocab()				,			tokenizer_add_kwargs.get_vocab()      )
			self.assertIsInstance(processor.tokenizer				,			__lowerCamelCase      )

			self.assertEqual(processor.feature_extractor.to_json_string()				,			feature_extractor_add_kwargs.to_json_string()      )
			self.assertIsInstance(processor.feature_extractor				,			__lowerCamelCase      )




	def       UpperCAmelCase (	self       :    Dict      )					->   str:

			'''simple docstring'''




			__lowercase					=    self.get_feature_extractor()
			__lowercase					=    self.get_tokenizer()

			__lowercase					=    SpeechaTextProcessor(tokenizer=__lowerCamelCase				,			feature_extractor=__lowerCamelCase      )

			__lowercase					=    floats_list((3, 1_000)      )

			__lowercase					=    feature_extractor(__lowerCamelCase				,			return_tensors='np'      )
			__lowercase					=    processor(__lowerCamelCase				,			return_tensors='np'      )

			for key in input_feat_extract.keys():
					self.assertAlmostEqual(input_feat_extract[key].sum()				,			input_processor[key].sum()				,			delta=1E-2      )




	def       UpperCAmelCase (	self       :    Union[str, Any]      )					->   str:

			'''simple docstring'''




			__lowercase					=    self.get_feature_extractor()
			__lowercase					=    self.get_tokenizer()

			__lowercase					=    SpeechaTextProcessor(tokenizer=__lowerCamelCase				,			feature_extractor=__lowerCamelCase      )

			__lowercase					=    'This is a test string'

			__lowercase					=    processor(text=__lowerCamelCase      )

			__lowercase					=    tokenizer(__lowerCamelCase      )

			for key in encoded_tok.keys():
					self.assertListEqual(encoded_tok[key]				,			encoded_processor[key]      )




	def       UpperCAmelCase (	self       :    str      )					->   str:

			'''simple docstring'''




			__lowercase					=    self.get_feature_extractor()
			__lowercase					=    self.get_tokenizer()

			__lowercase					=    SpeechaTextProcessor(tokenizer=__lowerCamelCase				,			feature_extractor=__lowerCamelCase      )

			__lowercase					=    [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

			__lowercase					=    processor.batch_decode(__lowerCamelCase      )
			__lowercase					=    tokenizer.batch_decode(__lowerCamelCase      )

			self.assertListEqual(__lowerCamelCase				,			__lowerCamelCase      )






	def       UpperCAmelCase (	self       :    Tuple      )					->   str:

			'''simple docstring'''




			__lowercase					=    self.get_feature_extractor()
			__lowercase					=    self.get_tokenizer()

			__lowercase					=    SpeechaTextProcessor(tokenizer=__lowerCamelCase				,			feature_extractor=__lowerCamelCase      )

			self.assertListEqual(
			    processor.model_input_names				,			feature_extractor.model_input_names				,			msg='`processor` and `feature_extractor` model input names do not match'				,			)




