




import unittest

from transformers import CamembertTokenizer, CamembertTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow
from transformers.utils import is_torch_available

from ...test_tokenization_common import TokenizerTesterMixin


_snake_case										=       get_tests_dir("fixtures/test_sentencepiece.model")
_snake_case										=       get_tests_dir("fixtures/test_sentencepiece_bpe.model")

_snake_case										=       "pt" if is_torch_available() else "tf"







@require_sentencepiece
@require_tokenizers
class 						lowercase							(   UpperCamelCase__,unittest.TestCase		):
     _a							 =						CamembertTokenizer
     _a							 =						CamembertTokenizerFast
     _a							 =						True
     _a							 =						True

     def 					a__	(  self				)						->							Tuple:
           super().setUp()

           # We have a SentencePiece fixture for testing
           _A							:     Optional[Any]			=						CamembertTokenizer(_a				)
           tokenizer.save_pretrained(self.tmpdirname				)

     def 					a__	(  self				)						->							Any:
           _A							:     str			=						"""<pad>"""
           _A							:     Optional[Any]			=						1

           self.assertEqual(self.get_tokenizer()._convert_token_to_id(_a				)		,     _a				)
           self.assertEqual(self.get_tokenizer()._convert_id_to_token(_a				)		,     _a				)

     def 					a__	(  self				)						->							List[Any]:
           _A							:     Any			=						list(self.get_tokenizer().get_vocab().keys()				)

           self.assertEqual(vocab_keys[0]		,     """<s>NOTUSED"""				)
           self.assertEqual(vocab_keys[1]		,     """<pad>"""				)
           self.assertEqual(vocab_keys[-1]		,     """<mask>"""				)
           self.assertEqual(len(_a				)		,     1004				)

     def 					a__	(  self				)						->							Union[str, Any]:
           self.assertEqual(self.get_tokenizer().vocab_size		,     1005				)

     def 					a__	(  self				)						->							Union[str, Any]:
           _A							:     Optional[int]			=						CamembertTokenizer(_a				)
           tokenizer.save_pretrained(self.tmpdirname				)
           _A							:     List[Any]			=						CamembertTokenizerFast.from_pretrained(self.tmpdirname				)

           _A							:     int			=						"""I was born in 92000, and this is falsé."""

           _A							:     Any			=						tokenizer.encode(_a				)
           _A							:     int			=						rust_tokenizer.encode(_a				)
           self.assertListEqual(_a		,     _a				)

           _A							:     Tuple			=						tokenizer.encode(_a		,     add_special_tokens=_a				)
           _A							:     Any			=						rust_tokenizer.encode(_a		,     add_special_tokens=_a				)
           self.assertListEqual(_a		,     _a				)

           # <unk> tokens are not the same for `rust` than for `slow`.
           # Because spm gives back raw token instead of `unk` in EncodeAsPieces
           # tokens = tokenizer.tokenize(sequence)
           _A							:     Optional[int]			=						tokenizer.convert_ids_to_tokens(_a				)
           _A							:     List[str]			=						rust_tokenizer.tokenize(_a				)
           self.assertListEqual(_a		,     _a				)

     def 					a__	(  self				)						->							Any:
           if not self.test_rust_tokenizer:
                 return

           _A							:     Optional[int]			=						self.get_tokenizer()
           _A							:     Dict			=						self.get_rust_tokenizer()

           _A							:     Any			=						"""I was born in 92000, and this is falsé."""

           _A							:     Any			=						tokenizer.tokenize(_a				)
           _A							:     Tuple			=						rust_tokenizer.tokenize(_a				)
           self.assertListEqual(_a		,     _a				)

           _A							:     Tuple			=						tokenizer.encode(_a		,     add_special_tokens=_a				)
           _A							:     Tuple			=						rust_tokenizer.encode(_a		,     add_special_tokens=_a				)
           self.assertListEqual(_a		,     _a				)

           _A							:     List[Any]			=						self.get_rust_tokenizer()
           _A							:     List[Any]			=						tokenizer.encode(_a				)
           _A							:     Union[str, Any]			=						rust_tokenizer.encode(_a				)
           self.assertListEqual(_a		,     _a				)



     @slow
     def 					a__	(  self				)						->							Tuple:
           # fmt: off
           _A							:     Any			=						{"""input_ids""": [[5, 54, 7196, 297, 30, 23, 776, 18, 11, 3215, 3705, 8252, 22, 3164, 1181, 2116, 29, 16, 813, 25, 791, 3314, 20, 3446, 38, 2_7575, 120, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [5, 468, 17, 11, 9088, 20, 1517, 8, 2_2804, 1_8818, 10, 38, 629, 607, 607, 142, 19, 7196, 867, 56, 1_0326, 24, 2267, 20, 416, 5072, 1_5612, 233, 734, 7, 2399, 27, 16, 3015, 1649, 7, 24, 20, 4338, 2399, 27, 13, 3400, 14, 13, 6189, 8, 930, 9, 6]], """attention_mask""": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}  # noqa: E501
           # fmt: on

           # camembert is a french model. So we also use french texts.
           _A							:     List[str]			=						[
               """Le transformeur est un modèle d'apprentissage profond introduit en 2017, """
               """utilisé principalement dans le domaine du traitement automatique des langues (TAL).""",
               """À l'instar des réseaux de neurones récurrents (RNN), les transformeurs sont conçus """
               """pour gérer des données séquentielles, telles que le langage naturel, pour des tâches """
               """telles que la traduction et la synthèse de texte.""",
           ]

           self.tokenizer_integration_test_util(
               expected_encoding=_a		,     model_name="""camembert-base"""		,     revision="""3a0641d9a1aeb7e848a74299e7e4c4bca216b4cf"""		,     sequences=_a		,     )







from math import asin, atan, cos, radians, sin, sqrt, tan

_snake_case										=       6_3_7_8_1_3_7.0
_snake_case										=       6_3_5_6_7_5_2.3_1_4_2_4_5
_snake_case										=       6378137







def 				lowerCAmelCase_	(     snake_case_,snake_case_,snake_case_,snake_case_     ):
      _A							:     Any			=						(AXIS_A - AXIS_B) / AXIS_A
      _A							:     Optional[int]			=						atan((1 - flattening) * tan(radians(snake_case_     )     )     )
      _A							:     List[str]			=						atan((1 - flattening) * tan(radians(snake_case_     )     )     )
      _A							:     Optional[Any]			=						radians(snake_case_     )
      _A							:     str			=						radians(snake_case_     )
      # Equation
      _A							:     Dict			=						sin((phi_a - phi_a) / 2     )
      _A							:     List[str]			=						sin((lambda_a - lambda_a) / 2     )
      # Square both values
      sin_sq_phi *= sin_sq_phi
      sin_sq_lambda *= sin_sq_lambda
      _A							:     Optional[int]			=						sqrt(sin_sq_phi + (cos(snake_case_     ) * cos(snake_case_     ) * sin_sq_lambda)     )
      return 2 * RADIUS * asin(snake_case_     )


if __name__ == "__main__":
  import doctest

  doctest.testmod()

