


'''simple docstring'''
import inspect
import json
import os
import tempfile
import unittest

from transformers.models.speech_to_text_a import SpeechaTextaTokenizer
from transformers.models.speech_to_text_a.tokenization_speech_to_text_a import VOCAB_FILES_NAMES

from ...test_tokenization_common import TokenizerTesterMixin






class 				__lowerCAmelCase      (      lowercase							, unittest.TestCase	):

						"""simple docstring"""






						_UpperCAmelCase		:					Tuple      	=SpeechaTextaTokenizer
						_UpperCAmelCase		:					List[str]      	=False






						def 							_UpperCAmelCase					(     self       :			Dict  ):
													super().setUp()

													A_ 						=		"<s> <pad> </s> <unk> here@@ a couple of@@ words for the he@@ re@@ vocab".split(" "  )
													A_ 						=		["he re</w> 123", "here a 1456"]
													A_ 						=		dict(zip(lowerCAmelCase   ,     range(len(lowerCAmelCase  )  )  )  )

													A_ 						=		{"pad_token": "<pad>", "unk_token": "<unk>", "bos_token": "<s>", "eos_token": "</s>"}

													A_ 						=		tempfile.mkdtemp()
													A_ 						=		os.path.join(self.tmpdirname   ,     VOCAB_FILES_NAMES["vocab_file"]  )
													A_ 						=		os.path.join(self.tmpdirname   ,     VOCAB_FILES_NAMES["merges_file"]  )

													with open(self.vocab_file   ,     "w"   ,     encoding="utf-8"  ) as fp:
																				fp.write(json.dumps(lowerCAmelCase  ) + "\n"  )

													with open(self.merges_file   ,     "w"  ) as fp:
																				fp.write("\n".join(lowerCAmelCase  )  )






						def 							_UpperCAmelCase					(     self       :			str  ):
													A_ 						=		list(self.get_tokenizer().get_vocab().keys()  )

													self.assertEqual(vocab_keys[0]   ,     "<s>"  )
													self.assertEqual(vocab_keys[1]   ,     "<pad>"  )
													self.assertEqual(vocab_keys[-1]   ,     "vocab"  )
													self.assertEqual(len(lowerCAmelCase  )   ,     14  )






						def 							_UpperCAmelCase					(     self       :			Optional[Any]  ):
													self.assertEqual(self.get_tokenizer().vocab_size   ,     14  )






						def 							_UpperCAmelCase					(     self       :			int  ):
													A_ 						=		SpeechaTextaTokenizer.from_pretrained(self.tmpdirname  )

													# make sure @@ is correctly concatenated
													A_ 						=		[4, 6, 8, 7, 10]  # ["here@@", "couple", "words", "of@@", "the"]
													A_ 						=		tokenizer.decode(lowerCAmelCase  )

													self.assertTrue(output_string == "herecouple words ofthe"  )






						def 							_UpperCAmelCase					(     self       :			Any  ):
													A_ 						=		SpeechaTextaTokenizer.from_pretrained(self.tmpdirname  )

													with tempfile.TemporaryDirectory() as tmp_dirname:
																				tokenizer.save_pretrained(lowerCAmelCase  )
																				os.remove(os.path.join(lowerCAmelCase   ,     "merges.txt"  )  )

																				# load tokenizer without merges file should not throw an error
																				A_ 						=		SpeechaTextaTokenizer.from_pretrained(lowerCAmelCase  )

													with tempfile.TemporaryDirectory() as tmp_dirname:
																				# save tokenizer and load again
																				tokenizer.save_pretrained(lowerCAmelCase  )
																				A_ 						=		SpeechaTextaTokenizer.from_pretrained(lowerCAmelCase  )

													self.assertIsNotNone(lowerCAmelCase  )






						def 							_UpperCAmelCase					(     self       :			Dict  ):
													if not self.test_slow_tokenizer:
																				return

													A_ 						=		inspect.signature(self.tokenizer_class.__init__  )
													A_ 						=		self.get_tokenizer()

													for parameter_name, parameter in signature.parameters.items():
																				if parameter.default != inspect.Parameter.empty and parameter_name != "merges_file":
																											self.assertIn(lowerCAmelCase   ,     tokenizer.init_kwargs  )









'''simple docstring'''
def 			a_							(  UpperCamelCase_	,     UpperCamelCase_ = 1_0_0_0   ):
							if (not isinstance(UpperCamelCase_	,     UpperCamelCase_   )) or (digit_position <= 0):
														raise ValueError("Digit position must be a positive integer"   )
							elif (not isinstance(UpperCamelCase_	,     UpperCamelCase_   )) or (precision < 0):
														raise ValueError("Precision must be a nonnegative integer"   )

							# compute an approximation of (16 ** (n - 1)) * pi whose fractional part is mostly
							# accurate
							A_ 						=		(
							    4 * _subsum(UpperCamelCase_	,     1	,     UpperCamelCase_   )
							    - 2 * _subsum(UpperCamelCase_	,     4	,     UpperCamelCase_   )
							    - _subsum(UpperCamelCase_	,     5	,     UpperCamelCase_   )
							    - _subsum(UpperCamelCase_	,     6	,     UpperCamelCase_   )
							)

							# return the first hex digit of the fractional part of the result
							return hex(int((sum_result % 1) * 1_6   )   )[2:]







def 			a_							(  UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_   ):
							A_ 						=		0.0
							for sum_index in range(digit_pos_to_extract + precision   ):
														A_ 						=		8 * sum_index + denominator_addend
														if sum_index < digit_pos_to_extract:
																					# if the exponential term is an integer and we mod it by the denominator
																					# before dividing, only the integer part of the sum will change;
																					# the fractional part will not
																					A_ 						=		pow(
																					    1_6	,     digit_pos_to_extract - 1 - sum_index	,     UpperCamelCase_   )
														else:
																					A_ 						=		pow(1_6	,     digit_pos_to_extract - 1 - sum_index   )
														total += exponential_term / denominator
							return total


if __name__ == "__main__":
							import doctest

							doctest.testmod()





