





"""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    __SCREAMING_SNAKE_CASE			(  _UpperCamelCase						,     unittest.TestCase      ):







  '''simple docstring'''


  SCREAMING_SNAKE_CASE__							:Optional[Any]		   =    SpeechaTextaTokenizer
  SCREAMING_SNAKE_CASE__							:int		   =    False

  def       __SCREAMING_SNAKE_CASE (						self      :				Union[str, Any]		)						-> Optional[int]:
        super().setUp()

        _UpperCamelCase					:		Tuple  =				"<s> <pad> </s> <unk> here@@ a couple of@@ words for the he@@ re@@ vocab".split(" "		)
        _UpperCamelCase					:		List[str]  =				["he re</w> 123", "here a 1456"]
        _UpperCamelCase					:		Optional[Any]  =				dict(zip(__a    ,      range(len(__a		)		)		)		)

        _UpperCamelCase					:		Optional[int]  =				{"pad_token": "<pad>", "unk_token": "<unk>", "bos_token": "<s>", "eos_token": "</s>"}

        _UpperCamelCase					:		Any  =				tempfile.mkdtemp()
        _UpperCamelCase					:		Tuple  =				os.path.join(self.tmpdirname    ,      VOCAB_FILES_NAMES["vocab_file"]		)
        _UpperCamelCase					:		int  =				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(__a		) + "\n"		)

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

  def       __SCREAMING_SNAKE_CASE (						self      :				int		)						-> Dict:
        _UpperCamelCase					:		Union[str, Any]  =				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(__a		)    ,      14		)

  def       __SCREAMING_SNAKE_CASE (						self      :				Any		)						-> Dict:
        self.assertEqual(self.get_tokenizer().vocab_size    ,      14		)

  def       __SCREAMING_SNAKE_CASE (						self      :				int		)						-> Union[str, Any]:
        _UpperCamelCase					:		Optional[Any]  =				SpeechaTextaTokenizer.from_pretrained(self.tmpdirname		)

        # make sure @@ is correctly concatenated
        _UpperCamelCase					:		List[str]  =				[4, 6, 8, 7, 10]  # ["here@@", "couple", "words", "of@@", "the"]
        _UpperCamelCase					:		List[str]  =				tokenizer.decode(__a		)

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

  def       __SCREAMING_SNAKE_CASE (						self      :				Optional[int]		)						-> Union[str, Any]:
        _UpperCamelCase					:		Optional[Any]  =				SpeechaTextaTokenizer.from_pretrained(self.tmpdirname		)

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

              # load tokenizer without merges file should not throw an error
              _UpperCamelCase					:		List[Any]  =				SpeechaTextaTokenizer.from_pretrained(__a		)

        with tempfile.TemporaryDirectory() as tmp_dirname:
              # save tokenizer and load again
              tokenizer.save_pretrained(__a		)
              _UpperCamelCase					:		int  =				SpeechaTextaTokenizer.from_pretrained(__a		)

        self.assertIsNotNone(__a		)


  def       __SCREAMING_SNAKE_CASE (						self      :				int		)						-> Any:
        if not self.test_slow_tokenizer:
              return

        _UpperCamelCase					:		Any  =				inspect.signature(self.tokenizer_class.__init__		)
        _UpperCamelCase					:		Optional[int]  =				self.get_tokenizer()

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







"""simple docstring"""


from __future__ import annotations




def     lowercase__			(    lowercase_						,lowercase_						,lowercase_	)    ->						int:




      """simple docstring"""

      assert n > 1 and a > 0 and greatest_common_divisor(lowercase_						,lowercase_	) == 1
      ((_UpperCamelCase),     (_UpperCamelCase),     (_UpperCamelCase))					:		int  =				extended_gcd(lowercase_						,lowercase_	)  # Implemented below
      _UpperCamelCase					:		Any  =				(b * s) % n
      return x




def     lowercase__			(    lowercase_						,lowercase_	)    ->						int:




      """simple docstring"""

      ((_UpperCamelCase),     (_UpperCamelCase))					:		List[Any]  =				extended_euclid(lowercase_						,lowercase_	)  # Implemented below
      if b < 0:
            _UpperCamelCase					:		Any  =				(b % n + n) % n
      return b




def     lowercase__			(    lowercase_						,lowercase_						,lowercase_	)    ->						int:




      """simple docstring"""

      _UpperCamelCase					:		Union[str, Any]  =				invert_modulo(lowercase_						,lowercase_	)
      _UpperCamelCase					:		Any  =				(b * s) % n
      return x




def     lowercase__			(    lowercase_						,lowercase_	)    ->						tuple[int, int, int]:




      """simple docstring"""

      assert a >= 0 and b >= 0

      if b == 0:
            _UpperCamelCase,     _UpperCamelCase,     _UpperCamelCase					:		str  =				a, 1, 0
      else:
            ((_UpperCamelCase),     (_UpperCamelCase),     (_UpperCamelCase))					:		str  =				extended_gcd(lowercase_						,a % b	)
            _UpperCamelCase					:		Dict  =				q
            _UpperCamelCase					:		Tuple  =				p - q * (a // b)

      assert a % d == 0 and b % d == 0
      assert d == a * x + b * y

      return (d, x, y)




def     lowercase__			(    lowercase_						,lowercase_	)    ->						tuple[int, int]:




      """simple docstring"""

      if b == 0:
            return (1, 0)
      ((_UpperCamelCase),     (_UpperCamelCase))					:		Optional[Any]  =				extended_euclid(lowercase_						,a % b	)
      _UpperCamelCase					:		Dict  =				a // b
      return (y, x - k * y)




def     lowercase__			(    lowercase_						,lowercase_	)    ->						int:




      """simple docstring"""

      if a < b:
            _UpperCamelCase,     _UpperCamelCase					:		List[Any]  =				b, a

      while a % b != 0:
            _UpperCamelCase,     _UpperCamelCase					:		List[Any]  =				b, a % b

      return b


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

  testmod(name="modular_division", verbose=True)
  testmod(name="modular_division2", verbose=True)
  testmod(name="invert_modulo", verbose=True)
  testmod(name="extended_gcd", verbose=True)
  testmod(name="extended_euclid", verbose=True)
  testmod(name="greatest_common_divisor", verbose=True)
