





"""simple docstring"""



import json
import os
import shutil
import tempfile
import unittest

import numpy as np

from transformers import BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES, BertTokenizer
from transformers.testing_utils import require_tokenizers, require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
       from PIL import Image

       from transformers import VisionTextDualEncoderProcessor, ViTImageProcessor






@require_tokenizers
@require_vision
class 		__snake_case (		unittest.TestCase					):





 """simple docstring"""


 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Dict									=					tempfile.mkdtemp()

     # fmt: off
     __A   :						int									=					["""[UNK]""", """[CLS]""", """[SEP]""", """[PAD]""", """[MASK]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing""", """,""", """low""", """lowest"""]
     # fmt: on
     __A   :						Any									=					os.path.join(self.tmpdirname ,						VOCAB_FILES_NAMES['''vocab_file''']  )
     with open(self.vocab_file ,						'''w''' ,						encoding='''utf-8'''  ) as vocab_writer:
         vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]  )  )

     __A   :						List[str]									=					{
         """do_resize""": True,
         """size""": {"""height""": 18, """width""": 18},
         """do_normalize""": True,
         """image_mean""": [0.5, 0.5, 0.5],
         """image_std""": [0.5, 0.5, 0.5],
     }
     __A   :						Union[str, Any]									=					os.path.join(self.tmpdirname ,						lowerCamelCase_  )
     with open(self.image_processor_file ,						'''w''' ,						encoding='''utf-8'''  ) as fp:
         json.dump(lowerCamelCase_ ,						lowerCamelCase_  )

 def  UpperCamelCase__(   self ,						**__lowerCamelCase  ):



     '''simple docstring'''




     return BertTokenizer.from_pretrained(self.tmpdirname ,						**lowerCamelCase_  )

 def  UpperCamelCase__(   self ,						**__lowerCamelCase  ):



     '''simple docstring'''




     return ViTImageProcessor.from_pretrained(self.tmpdirname ,						**lowerCamelCase_  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     shutil.rmtree(self.tmpdirname  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[Any]									=					[np.random.randint(255 ,						size=(3, 30, 400) ,						dtype=np.uinta  )]

     __A   :						List[str]									=					[Image.fromarray(np.moveaxis(lowerCamelCase_ ,						0 ,						-1  )  ) for x in image_inputs]

     return image_inputs

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						int									=					self.get_tokenizer()
     __A   :						Union[str, Any]									=					self.get_image_processor()

     __A   :						Union[str, Any]									=					VisionTextDualEncoderProcessor(tokenizer=lowerCamelCase_ ,						image_processor=lowerCamelCase_  )

     processor.save_pretrained(self.tmpdirname  )
     __A   :						Dict									=					VisionTextDualEncoderProcessor.from_pretrained(self.tmpdirname  )

     self.assertEqual(processor.tokenizer.get_vocab() ,						tokenizer.get_vocab()  )
     self.assertIsInstance(processor.tokenizer ,						(BertTokenizer, BertTokenizerFast)  )

     self.assertEqual(processor.image_processor.to_json_string() ,						image_processor.to_json_string()  )
     self.assertIsInstance(processor.image_processor ,						lowerCamelCase_  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Any									=					VisionTextDualEncoderProcessor(
         tokenizer=self.get_tokenizer() ,						image_processor=self.get_image_processor()  )
     processor.save_pretrained(self.tmpdirname  )

     __A   :						List[str]									=					self.get_tokenizer(bos_token='''(BOS)''' ,						eos_token='''(EOS)'''  )
     __A   :						List[str]									=					self.get_image_processor(do_normalize=lowerCamelCase_ ,						padding_value=1.0  )

     __A   :						Optional[Any]									=					VisionTextDualEncoderProcessor.from_pretrained(
         self.tmpdirname ,						bos_token='''(BOS)''' ,						eos_token='''(EOS)''' ,						do_normalize=lowerCamelCase_ ,						padding_value=1.0  )

     self.assertEqual(processor.tokenizer.get_vocab() ,						tokenizer_add_kwargs.get_vocab()  )
     self.assertIsInstance(processor.tokenizer ,						(BertTokenizer, BertTokenizerFast)  )

     self.assertEqual(processor.image_processor.to_json_string() ,						image_processor_add_kwargs.to_json_string()  )
     self.assertIsInstance(processor.image_processor ,						lowerCamelCase_  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Tuple									=					self.get_image_processor()
     __A   :						Dict									=					self.get_tokenizer()

     __A   :						Optional[Any]									=					VisionTextDualEncoderProcessor(tokenizer=lowerCamelCase_ ,						image_processor=lowerCamelCase_  )

     __A   :						int									=					self.prepare_image_inputs()

     __A   :						List[str]									=					image_processor(lowerCamelCase_ ,						return_tensors='''np'''  )
     __A   :						Union[str, Any]									=					processor(images=lowerCamelCase_ ,						return_tensors='''np'''  )

     for key in input_feat_extract.keys():
         self.assertAlmostEqual(input_feat_extract[key].sum() ,						input_processor[key].sum() ,						delta=1e-2  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						int									=					self.get_image_processor()
     __A   :						List[str]									=					self.get_tokenizer()

     __A   :						Optional[Any]									=					VisionTextDualEncoderProcessor(tokenizer=lowerCamelCase_ ,						image_processor=lowerCamelCase_  )

     __A   :						Tuple									=					"""lower newer"""

     __A   :						Tuple									=					processor(text=lowerCamelCase_  )

     __A   :						Any									=					tokenizer(lowerCamelCase_  )

     for key in encoded_tok.keys():
         self.assertListEqual(encoded_tok[key] ,						encoded_processor[key]  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[Any]									=					self.get_image_processor()
     __A   :						Optional[Any]									=					self.get_tokenizer()

     __A   :						Optional[Any]									=					VisionTextDualEncoderProcessor(tokenizer=lowerCamelCase_ ,						image_processor=lowerCamelCase_  )

     __A   :						Optional[Any]									=					"""lower newer"""
     __A   :						List[str]									=					self.prepare_image_inputs()

     __A   :						List[Any]									=					processor(text=lowerCamelCase_ ,						images=lowerCamelCase_  )

     self.assertListEqual(list(inputs.keys()  ) ,						['''input_ids''', '''token_type_ids''', '''attention_mask''', '''pixel_values''']  )

     # test if it raises when no input is passed
     with self.assertRaises(lowerCamelCase_  ):
         processor()

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Optional[int]									=					self.get_image_processor()
     __A   :						Tuple									=					self.get_tokenizer()

     __A   :						List[str]									=					VisionTextDualEncoderProcessor(tokenizer=lowerCamelCase_ ,						image_processor=lowerCamelCase_  )

     __A   :						List[Any]									=					[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

     __A   :						Optional[int]									=					processor.batch_decode(lowerCamelCase_  )
     __A   :						Optional[Any]									=					tokenizer.batch_decode(lowerCamelCase_  )

     self.assertListEqual(lowerCamelCase_ ,						lowerCamelCase_  )







 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						int									=					self.get_image_processor()
     __A   :						Tuple									=					self.get_tokenizer()

     __A   :						str									=					VisionTextDualEncoderProcessor(tokenizer=lowerCamelCase_ ,						image_processor=lowerCamelCase_  )

     __A   :						int									=					"""lower newer"""
     __A   :						str									=					self.prepare_image_inputs()

     __A   :						str									=					processor(text=lowerCamelCase_ ,						images=lowerCamelCase_  )

     self.assertListEqual(list(inputs.keys()  ) ,						processor.model_input_names  )










"""simple docstring"""



from math import factorial







def 		__lowercase					(       snake_case_  :  int    ,snake_case_  :  int						)       ->int:



    '''simple docstring'''







    if n < k or k < 0:
        raise ValueError('''Please enter positive integers for n and k where n >= k'''						)
    return factorial(snake_case_						) // (factorial(snake_case_						) * factorial(n - k						))


if __name__ == "__main__":
       print(
           """The number of five-card hands possible from a standard""",
           f'''fifty-two card deck is: {combinations(52, 5)}\n''',
       )

       print(
           """If a class of 40 students must be arranged into groups of""",
           f'''4 for group projects, there are {combinations(40, 4)} ways''',
           """to arrange them.\n""",
       )

       print(
           """If 10 teams are competing in a Formula One race, there""",
           f'''are {combinations(10, 3)} ways that first, second and''',
           """third place can be awarded.""",
       )




