





"""simple docstring"""



import unittest

from .lib import (
    Matrix,
    Vector,
    axpy,
    square_zero_matrix,
    unit_basis_vector,
    zero_vector,
)






class 		__snake_case (		unittest.TestCase					):





 """simple docstring"""


 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Dict									=					Vector([1, 2, 3]  )
     self.assertEqual(x.component(0  ) ,						1  )
     self.assertEqual(x.component(2  ) ,						3  )
     __A   :						Tuple									=					Vector()

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						int									=					Vector([0, 0, 0, 0, 0, 1]  )
     self.assertEqual(str(__lowerCamelCase  ) ,						'''(0,0,0,0,0,1)'''  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						int									=					Vector([1, 2, 3, 4]  )
     self.assertEqual(len(__lowerCamelCase  ) ,						4  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Union[str, Any]									=					Vector([1, 2]  )
     __A   :						List[str]									=					Vector([1, 2, 3, 4, 5]  )
     __A   :						List[Any]									=					Vector([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]  )
     __A   :						Union[str, Any]									=					Vector([1, -1, 1, -1, 2, -3, 4, -5]  )
     self.assertAlmostEqual(x.euclidean_length() ,						2.2_3_6 ,						3  )
     self.assertAlmostEqual(y.euclidean_length() ,						7.4_1_6 ,						3  )
     self.assertEqual(z.euclidean_length() ,						0  )
     self.assertAlmostEqual(w.euclidean_length() ,						7.6_1_6 ,						3  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Optional[int]									=					Vector([1, 2, 3]  )
     __A   :						Tuple									=					Vector([1, 1, 1]  )
     self.assertEqual((x + y).component(0  ) ,						2  )
     self.assertEqual((x + y).component(1  ) ,						3  )
     self.assertEqual((x + y).component(2  ) ,						4  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						int									=					Vector([1, 2, 3]  )
     __A   :						str									=					Vector([1, 1, 1]  )
     self.assertEqual((x - y).component(0  ) ,						0  )
     self.assertEqual((x - y).component(1  ) ,						1  )
     self.assertEqual((x - y).component(2  ) ,						2  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[str]									=					Vector([1, 2, 3]  )
     __A   :						List[str]									=					Vector([2, -1, 4]  )  # for test of dot product
     __A   :						Union[str, Any]									=					Vector([1, -2, -1]  )
     self.assertEqual(str(x * 3.0  ) ,						'''(3.0,6.0,9.0)'''  )
     self.assertEqual((a * b) ,						0  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     self.assertEqual(str(zero_vector(10  )  ).count('''0'''  ) ,						10  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     self.assertEqual(str(unit_basis_vector(3 ,						1  )  ) ,						'''(0,1,0)'''  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						str									=					Vector([1, 2, 3]  )
     __A   :						Union[str, Any]									=					Vector([1, 0, 1]  )
     self.assertEqual(str(axpy(2 ,						__lowerCamelCase ,						__lowerCamelCase  )  ) ,						'''(3,4,7)'''  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						int									=					Vector([1, 0, 0, 0, 0, 0]  )
     __A   :						List[Any]									=					x.copy()
     self.assertEqual(str(__lowerCamelCase  ) ,						str(__lowerCamelCase  )  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[Any]									=					Vector([1, 0, 0]  )
     x.change_component(0 ,						0  )
     x.change_component(1 ,						1  )
     self.assertEqual(str(__lowerCamelCase  ) ,						'''(0,1,0)'''  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Dict									=					Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]] ,						3 ,						3  )
     self.assertEqual('''|1,2,3|\n|2,4,5|\n|6,7,8|\n''' ,						str(__lowerCamelCase  )  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Optional[Any]									=					Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]] ,						3 ,						3  )
     __A   :						int									=					[[-3, -14, -10], [-5, -10, -5], [-2, -1, 0]]
     for x in range(a.height()  ):
         for y in range(a.width()  ):
             self.assertEqual(minors[x][y] ,						a.minor(__lowerCamelCase ,						__lowerCamelCase  )  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						str									=					Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]] ,						3 ,						3  )
     __A   :						Optional[Any]									=					[[-3, 14, -10], [5, -10, 5], [-2, 1, 0]]
     for x in range(a.height()  ):
         for y in range(a.width()  ):
             self.assertEqual(cofactors[x][y] ,						a.cofactor(__lowerCamelCase ,						__lowerCamelCase  )  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Optional[int]									=					Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]] ,						3 ,						3  )
     self.assertEqual(-5 ,						a.determinant()  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[Any]									=					Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]] ,						3 ,						3  )
     __A   :						Dict									=					Vector([1, 2, 3]  )
     self.assertEqual('''(14,32,50)''' ,						str(a * x  )  )
     self.assertEqual('''|2,4,6|\n|8,10,12|\n|14,16,18|\n''' ,						str(a * 2  )  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Tuple									=					Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]] ,						3 ,						3  )
     a.change_component(0 ,						2 ,						5  )
     self.assertEqual('''|1,2,5|\n|2,4,5|\n|6,7,8|\n''' ,						str(__lowerCamelCase  )  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[str]									=					Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]] ,						3 ,						3  )
     self.assertEqual(7 ,						a.component(2 ,						1  ) ,						0.0_1  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Dict									=					Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]] ,						3 ,						3  )
     __A   :						str									=					Matrix([[1, 2, 7], [2, 4, 5], [6, 7, 10]] ,						3 ,						3  )
     self.assertEqual('''|2,4,10|\n|4,8,10|\n|12,14,18|\n''' ,						str(a + b  )  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Dict									=					Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]] ,						3 ,						3  )
     __A   :						str									=					Matrix([[1, 2, 7], [2, 4, 5], [6, 7, 10]] ,						3 ,						3  )
     self.assertEqual('''|0,0,-4|\n|0,0,0|\n|0,0,-2|\n''' ,						str(a - b  )  )







 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     self.assertEqual(
         '''|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n''' ,						str(square_zero_matrix(5  )  ) ,						)


if __name__ == "__main__":
       unittest.main()











"""simple docstring"""



import json
import os
import unittest

from transformers.models.xlm.tokenization_xlm import VOCAB_FILES_NAMES, XLMTokenizer
from transformers.testing_utils import slow

from ...test_tokenization_common import TokenizerTesterMixin






class 		__snake_case (		SCREAMING_SNAKE_CASE__							,							unittest.TestCase					):





 """simple docstring"""


 _lowerCamelCase				=					XLMTokenizer
 _lowerCamelCase				=					False

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     super().setUp()

     # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
     __A   :						Tuple									=					[
         '''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									=					dict(zip(__lowerCamelCase ,						range(len(__lowerCamelCase  )  )  )  )
     __A   :						Union[str, Any]									=					['''l o 123''', '''lo w 1456''', '''e r</w> 1789''', '''''']

     __A   :						Optional[Any]									=					os.path.join(self.tmpdirname ,						VOCAB_FILES_NAMES['''vocab_file''']  )
     __A   :						Optional[Any]									=					os.path.join(self.tmpdirname ,						VOCAB_FILES_NAMES['''merges_file''']  )
     with open(self.vocab_file ,						'''w'''  ) as fp:
         fp.write(json.dumps(__lowerCamelCase  )  )
     with open(self.merges_file ,						'''w'''  ) as fp:
         fp.write('''\n'''.join(__lowerCamelCase  )  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						Optional[int]									=					'''lower newer'''
     __A   :						int									=					'''lower newer'''
     return input_text, output_text

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Union[str, Any]									=					XLMTokenizer(self.vocab_file ,						self.merges_file  )

     __A   :						Optional[Any]									=					'''lower'''
     __A   :						Any									=					['''low''', '''er</w>''']
     __A   :						Tuple									=					tokenizer.tokenize(__lowerCamelCase  )
     self.assertListEqual(__lowerCamelCase ,						__lowerCamelCase  )

     __A   :						str									=					tokens + ['''<unk>''']
     __A   :						List[str]									=					[14, 15, 20]
     self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowerCamelCase  ) ,						__lowerCamelCase  )







 @slow
 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Optional[int]									=					XLMTokenizer.from_pretrained('''xlm-mlm-en-2048'''  )

     __A   :						Union[str, Any]									=					tokenizer.encode('''sequence builders''' ,						add_special_tokens=__lowerCamelCase  )
     __A   :						int									=					tokenizer.encode('''multi-sequence build''' ,						add_special_tokens=__lowerCamelCase  )

     __A   :						int									=					tokenizer.build_inputs_with_special_tokens(__lowerCamelCase  )
     __A   :						List[Any]									=					tokenizer.build_inputs_with_special_tokens(__lowerCamelCase ,						__lowerCamelCase  )

     assert encoded_sentence == [0] + text + [1]
     assert encoded_pair == [0] + text + [1] + text_a + [1]




