



import json
import os
import unittest

from transformers import OpenAIGPTTokenizer, OpenAIGPTTokenizerFast
from transformers.models.openai.tokenization_openai import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_spacy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class 	UpperCAmelCase	(		UpperCamelCase__					,	unittest.TestCase):


 '''simple docstring'''




 __magic_name__					: Tuple  =      OpenAIGPTTokenizer
 __magic_name__					: int  =      OpenAIGPTTokenizerFast
 __magic_name__					: int  =      True
 __magic_name__					: List[Any]  =      False




 def       lowercase_  (   self) ->      Dict:



      """simple docstring"""







      super().setUp()

      # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
      a_       		=[
          "l",
          "o",
          "w",
          "e",
          "r",
          "s",
          "t",
          "i",
          "d",
          "n",
          "w</w>",
          "r</w>",
          "t</w>",
          "lo",
          "low",
          "er</w>",
          "low</w>",
          "lowest</w>",
          "newer</w>",
          "wider</w>",
          "<unk>",
      ]
      a_       		=dict(zip(__A							,  range(len(__A))))
      a_       		=["#version: 0.2", "l o", "lo w", "e r</w>", ""]

      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") as fp:
           fp.write(json.dumps(__A))
      with open(self.merges_file							,  "w") as fp:
           fp.write("\n".join(__A))




 def       lowercase_  (   self							,  lowerCAmelCase_) ->      List[Any]:



      """simple docstring"""







      return "lower newer", "lower newer"




 def       lowercase_  (   self) ->      Tuple:



      """simple docstring"""







      a_       		=OpenAIGPTTokenizer(self.vocab_file							,  self.merges_file)

      a_       		="lower"
      a_       		=["low", "er</w>"]
      a_       		=tokenizer.tokenize(__A)
      self.assertListEqual(__A							,  __A)

      a_       		=tokens + ["<unk>"]
      a_       		=[1_4, 1_5, 2_0]
      self.assertListEqual(tokenizer.convert_tokens_to_ids(__A)							,  __A)




 def       lowercase_  (   self							,  lowerCAmelCase_=1_5) ->      Any:



      """simple docstring"""







      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
           with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""):
                a_       		=self.rust_tokenizer_class.from_pretrained(__A							,  **__A)

                # Simple input
                a_       		="This is a simple input"
                a_       		=["This is a simple input 1", "This is a simple input 2"]
                a_       		=("This is a simple input", "This is a pair")
                a_       		=[
                    ("This is a simple input 1", "This is a simple input 2"),
                    ("This is a simple pair 1", "This is a simple pair 2"),
                ]

                # Simple input tests
                self.assertRaises(__A							,  tokenizer_r.encode							,  __A							,  max_length=__A							,  padding="max_length")

                # Simple input
                self.assertRaises(__A							,  tokenizer_r.encode_plus							,  __A							,  max_length=__A							,  padding="max_length")

                # Simple input
                self.assertRaises(
                    __A							,  tokenizer_r.batch_encode_plus							,  __A							,  max_length=__A							,  padding="max_length"							,  )

                # Pair input
                self.assertRaises(__A							,  tokenizer_r.encode							,  __A							,  max_length=__A							,  padding="max_length")

                # Pair input
                self.assertRaises(__A							,  tokenizer_r.encode_plus							,  __A							,  max_length=__A							,  padding="max_length")

                # Pair input
                self.assertRaises(
                    __A							,  tokenizer_r.batch_encode_plus							,  __A							,  max_length=__A							,  padding="max_length"							,  )




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



      """simple docstring"""







      pass







@require_ftfy
@require_spacy
@require_tokenizers
class 	UpperCAmelCase	(		UpperCamelCase__):


 '''simple docstring'''




 pass







'''simple docstring'''


from __future__ import annotations






def  UpperCAmelCase_       (		lowercase__       ,	lowercase__       ):


     '''simple docstring'''







     if b == 0:
          return (1, 0)
     ((a_)		,						(a_))       		=extended_euclid(lowercase__       ,	a % b       )
     a_       		=a // b
     return (y, x - k * y)






def  UpperCAmelCase_       (		lowercase__       ,	lowercase__       ,	lowercase__       ,	lowercase__       ):


     '''simple docstring'''







     ((a_)		,						(a_))       		=extended_euclid(lowercase__       ,	lowercase__       )
     a_       		=na * na
     a_       		=ra * x * na + ra * y * na
     return (n % m + m) % m






def  UpperCAmelCase_       (		lowercase__       ,	lowercase__       ):


     '''simple docstring'''







     ((a_)		,						(a_))       		=extended_euclid(lowercase__       ,	lowercase__       )
     if b < 0:
          a_       		=(b % n + n) % n
     return b






def  UpperCAmelCase_       (		lowercase__       ,	lowercase__       ,	lowercase__       ,	lowercase__       ):


     '''simple docstring'''







     a_		,						a_       		=invert_modulo(lowercase__       ,	lowercase__       ), invert_modulo(lowercase__       ,	lowercase__       )
     a_       		=na * na
     a_       		=ra * x * na + ra * y * na
     return (n % m + m) % m


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

  testmod(name='''chinese_remainder_theorem''', verbose=True)
  testmod(name='''chinese_remainder_theorem2''', verbose=True)
  testmod(name='''invert_modulo''', verbose=True)
  testmod(name='''extended_euclid''', verbose=True)


