




import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

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


if is_vision_available():
     from PIL import Image

     from transformers import AlignProcessor, EfficientNetImageProcessor

@require_vision
class   __a(					unittest.TestCase       ):






    """simple docstring"""





    def 							a__				(				self  )			->		Tuple:
         UpperCAmelCase_      :							List[str]       =      tempfile.mkdtemp()

         UpperCAmelCase_      :							List[Any]       =      [
             '''[UNK]''',
             '''[CLS]''',
             '''[SEP]''',
             '''[PAD]''',
             '''[MASK]''',
             '''want''',
             '''##want''',
             '''##ed''',
             '''wa''',
             '''un''',
             '''runn''',
             '''##ing''',
             ''',''',
             '''low''',
             '''lowest''',
         ]
         UpperCAmelCase_      :							int       =      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]  )  )

         UpperCAmelCase_      :							Tuple       =      {
             '''do_resize''': True,
             '''size''': 20,
             '''do_center_crop''': True,
             '''crop_size''': 18,
             '''do_normalize''': True,
             '''image_mean''': [0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73],
             '''image_std''': [0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11],
         }
         UpperCAmelCase_      :							Tuple       =      os.path.join(self.tmpdirname       ,_SCREAMING_SNAKE_CASE  )
         with open(self.image_processor_file       ,'''w'''       ,encoding='''utf-8'''  ) as fp:
              json.dump(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self       ,**_SCREAMING_SNAKE_CASE  )			->		Any:
         return BertTokenizer.from_pretrained(self.tmpdirname       ,**_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self       ,**_SCREAMING_SNAKE_CASE  )			->		List[str]:
         return BertTokenizerFast.from_pretrained(self.tmpdirname       ,**_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self       ,**_SCREAMING_SNAKE_CASE  )			->		int:
         return EfficientNetImageProcessor.from_pretrained(self.tmpdirname       ,**_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		int:
         shutil.rmtree(self.tmpdirname  )





    def 							a__				(				self  )			->		Tuple:
         UpperCAmelCase_      :							Optional[Any]       =      [np.random.randint(255       ,size=(3, 30, 400)       ,dtype=np.uinta  )]
         UpperCAmelCase_      :							Tuple       =      [Image.fromarray(np.moveaxis(_SCREAMING_SNAKE_CASE       ,0       ,-1  )  ) for x in image_inputs]
         return image_inputs





    def 							a__				(				self  )			->		List[Any]:
         UpperCAmelCase_      :							Optional[int]       =      self.get_tokenizer()
         UpperCAmelCase_      :							List[str]       =      self.get_rust_tokenizer()
         UpperCAmelCase_      :							str       =      self.get_image_processor()

         UpperCAmelCase_      :							Tuple       =      AlignProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )
         processor_slow.save_pretrained(self.tmpdirname  )
         UpperCAmelCase_      :							Union[str, Any]       =      AlignProcessor.from_pretrained(self.tmpdirname       ,use_fast=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Tuple       =      AlignProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )
         processor_fast.save_pretrained(self.tmpdirname  )
         UpperCAmelCase_      :							Tuple       =      AlignProcessor.from_pretrained(self.tmpdirname  )

         self.assertEqual(processor_slow.tokenizer.get_vocab()       ,tokenizer_slow.get_vocab()  )
         self.assertEqual(processor_fast.tokenizer.get_vocab()       ,tokenizer_fast.get_vocab()  )
         self.assertEqual(tokenizer_slow.get_vocab()       ,tokenizer_fast.get_vocab()  )
         self.assertIsInstance(processor_slow.tokenizer       ,_SCREAMING_SNAKE_CASE  )
         self.assertIsInstance(processor_fast.tokenizer       ,_SCREAMING_SNAKE_CASE  )

         self.assertEqual(processor_slow.image_processor.to_json_string()       ,image_processor.to_json_string()  )
         self.assertEqual(processor_fast.image_processor.to_json_string()       ,image_processor.to_json_string()  )
         self.assertIsInstance(processor_slow.image_processor       ,_SCREAMING_SNAKE_CASE  )
         self.assertIsInstance(processor_fast.image_processor       ,_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		Dict:
         UpperCAmelCase_      :							Optional[Any]       =      AlignProcessor(tokenizer=self.get_tokenizer()       ,image_processor=self.get_image_processor()  )
         processor.save_pretrained(self.tmpdirname  )

         UpperCAmelCase_      :							Union[str, Any]       =      self.get_tokenizer(bos_token='''(BOS)'''       ,eos_token='''(EOS)'''  )
         UpperCAmelCase_      :							Union[str, Any]       =      self.get_image_processor(do_normalize=_SCREAMING_SNAKE_CASE       ,padding_value=1.0  )

         UpperCAmelCase_      :							Dict       =      AlignProcessor.from_pretrained(
             self.tmpdirname       ,bos_token='''(BOS)'''       ,eos_token='''(EOS)'''       ,do_normalize=_SCREAMING_SNAKE_CASE       ,padding_value=1.0  )

         self.assertEqual(processor.tokenizer.get_vocab()       ,tokenizer_add_kwargs.get_vocab()  )
         self.assertIsInstance(processor.tokenizer       ,_SCREAMING_SNAKE_CASE  )

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





    def 							a__				(				self  )			->		List[Any]:
         UpperCAmelCase_      :							List[str]       =      self.get_image_processor()
         UpperCAmelCase_      :							Optional[Any]       =      self.get_tokenizer()

         UpperCAmelCase_      :							Tuple       =      AlignProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							str       =      self.prepare_image_inputs()

         UpperCAmelCase_      :							Union[str, Any]       =      image_processor(_SCREAMING_SNAKE_CASE       ,return_tensors='''np'''  )
         UpperCAmelCase_      :							int       =      processor(images=_SCREAMING_SNAKE_CASE       ,return_tensors='''np'''  )

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





    def 							a__				(				self  )			->		str:
         UpperCAmelCase_      :							Optional[int]       =      self.get_image_processor()
         UpperCAmelCase_      :							Tuple       =      self.get_tokenizer()

         UpperCAmelCase_      :							Any       =      AlignProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Optional[int]       =      '''lower newer'''

         UpperCAmelCase_      :							str       =      processor(text=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							str       =      tokenizer(_SCREAMING_SNAKE_CASE       ,padding='''max_length'''       ,max_length=64  )

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





    def 							a__				(				self  )			->		Tuple:
         UpperCAmelCase_      :							Dict       =      self.get_image_processor()
         UpperCAmelCase_      :							Optional[Any]       =      self.get_tokenizer()

         UpperCAmelCase_      :							Tuple       =      AlignProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							str       =      '''lower newer'''
         UpperCAmelCase_      :							Any       =      self.prepare_image_inputs()

         UpperCAmelCase_      :							Union[str, Any]       =      processor(text=_SCREAMING_SNAKE_CASE       ,images=_SCREAMING_SNAKE_CASE  )

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

         # test if it raises when no input is passed
         with pytest.raises(_SCREAMING_SNAKE_CASE  ):
              processor()





    def 							a__				(				self  )			->		List[Any]:
         UpperCAmelCase_      :							Tuple       =      self.get_image_processor()
         UpperCAmelCase_      :							Any       =      self.get_tokenizer()

         UpperCAmelCase_      :							str       =      AlignProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Union[str, Any]       =      [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

         UpperCAmelCase_      :							Optional[Any]       =      processor.batch_decode(_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							Tuple       =      tokenizer.batch_decode(_SCREAMING_SNAKE_CASE  )

         self.assertListEqual(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		Any:
         UpperCAmelCase_      :							List[str]       =      self.get_image_processor()
         UpperCAmelCase_      :							Dict       =      self.get_tokenizer()

         UpperCAmelCase_      :							Union[str, Any]       =      AlignProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							str       =      '''lower newer'''
         UpperCAmelCase_      :							List[Any]       =      self.prepare_image_inputs()

         UpperCAmelCase_      :							int       =      processor(text=_SCREAMING_SNAKE_CASE       ,images=_SCREAMING_SNAKE_CASE  )

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





from __future__ import annotations

from fractions import Fraction







def lowerCamelCase__       (      _lowercase			,						_lowercase				):

     '''simple docstring'''


     return (
         num != den and num % 10 == den // 10 and (num // 10) / (den % 10) == num / den
     )







def lowerCamelCase__       (      _lowercase				):

     '''simple docstring'''


     UpperCAmelCase_      :							Optional[int]       =      []
     UpperCAmelCase_      :							Tuple       =      11
     UpperCAmelCase_      :							int       =      int('''1''' + '''0''' * digit_len				)
     for num in range(_lowercase			,						_lowercase				):
          while den <= 99:
               if (num != den) and (num % 10 == den // 10) and (den % 10 != 0):
                    if is_digit_cancelling(_lowercase			,						_lowercase				):
                         solutions.append(f'''{num}/{den}'''				)
               den += 1
          num += 1
          UpperCAmelCase_      :							Any       =      10
     return solutions







def lowerCamelCase__       (      _lowercase = 2				):

     '''simple docstring'''


     UpperCAmelCase_      :							Tuple       =      1.0
     for fraction in fraction_list(_lowercase				):
          UpperCAmelCase_      :							Optional[Any]       =      Fraction(_lowercase				)
          result *= frac.denominator / frac.numerator
     return int(_lowercase				)


if __name__ == "__main__":
     print(solution())