



"""simple docstring"""






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        __snake_case       (	unittest.TestCase):




  def 						SCREAMING_SNAKE_CASE				( self     :						Dict		):






         """simple docstring"""






         _lowerCamelCase						:				List[str]    			= tempfile.mkdtemp()

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

         _lowerCamelCase						:				List[str]    			= {
             '''do_resize''': True,
             '''size''': 2_0,
             '''do_center_crop''': True,
             '''crop_size''': 1_8,
             '''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],
         }
         _lowerCamelCase						:				str    			= os.path.join(self.tmpdirname						,					__lowerCAmelCase		)
         with open(self.image_processor_file						,					'''w'''						,					encoding='''utf-8'''		) as fp:
                json.dump(__lowerCAmelCase						,					__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Union[str, Any]						,					**__lowerCAmelCase     :						int		):






         """simple docstring"""






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




  def 						SCREAMING_SNAKE_CASE				( self     :						List[str]						,					**__lowerCAmelCase     :						Union[str, Any]		):






         """simple docstring"""






         return BertTokenizerFast.from_pretrained(self.tmpdirname						,					**__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Tuple						,					**__lowerCAmelCase     :						Optional[int]		):






         """simple docstring"""






         return EfficientNetImageProcessor.from_pretrained(self.tmpdirname						,					**__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Union[str, Any]		):






         """simple docstring"""






         shutil.rmtree(self.tmpdirname		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Any		):






         """simple docstring"""






         _lowerCamelCase						:				Union[str, Any]    			= [np.random.randint(2_5_5						,					size=(3, 3_0, 4_0_0)						,					dtype=np.uinta		)]
         _lowerCamelCase						:				Dict    			= [Image.fromarray(np.moveaxis(__lowerCAmelCase						,					0						,					-1		)		) for x in image_inputs]
         return image_inputs




  def 						SCREAMING_SNAKE_CASE				( self     :						List[str]		):






         """simple docstring"""






         _lowerCamelCase						:				int    			= self.get_tokenizer()
         _lowerCamelCase						:				List[Any]    			= self.get_rust_tokenizer()
         _lowerCamelCase						:				Tuple    			= self.get_image_processor()

         _lowerCamelCase						:				List[Any]    			= AlignProcessor(tokenizer=__lowerCAmelCase						,					image_processor=__lowerCAmelCase		)
         processor_slow.save_pretrained(self.tmpdirname		)
         _lowerCamelCase						:				str    			= AlignProcessor.from_pretrained(self.tmpdirname						,					use_fast=__lowerCAmelCase		)

         _lowerCamelCase						:				str    			= AlignProcessor(tokenizer=__lowerCAmelCase						,					image_processor=__lowerCAmelCase		)
         processor_fast.save_pretrained(self.tmpdirname		)
         _lowerCamelCase						:				List[Any]    			= 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						,					__lowerCAmelCase		)
         self.assertIsInstance(processor_fast.tokenizer						,					__lowerCAmelCase		)

         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						,					__lowerCAmelCase		)
         self.assertIsInstance(processor_fast.image_processor						,					__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Union[str, Any]		):






         """simple docstring"""






         _lowerCamelCase						:				Tuple    			= AlignProcessor(tokenizer=self.get_tokenizer()						,					image_processor=self.get_image_processor()		)
         processor.save_pretrained(self.tmpdirname		)

         _lowerCamelCase						:				Any    			= self.get_tokenizer(bos_token='''(BOS)'''						,					eos_token='''(EOS)'''		)
         _lowerCamelCase						:				Tuple    			= self.get_image_processor(do_normalize=__lowerCAmelCase						,					padding_value=1.0		)

         _lowerCamelCase						:				int    			= AlignProcessor.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						,					__lowerCAmelCase		)

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




  def 						SCREAMING_SNAKE_CASE				( self     :						Tuple		):






         """simple docstring"""






         _lowerCamelCase						:				Dict    			= self.get_image_processor()
         _lowerCamelCase						:				str    			= self.get_tokenizer()

         _lowerCamelCase						:				Optional[int]    			= AlignProcessor(tokenizer=__lowerCAmelCase						,					image_processor=__lowerCAmelCase		)

         _lowerCamelCase						:				Tuple    			= self.prepare_image_inputs()

         _lowerCamelCase						:				Optional[Any]    			= image_processor(__lowerCAmelCase						,					return_tensors='''np'''		)
         _lowerCamelCase						:				Tuple    			= processor(images=__lowerCAmelCase						,					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 						SCREAMING_SNAKE_CASE				( self     :						Any		):






         """simple docstring"""






         _lowerCamelCase						:				Union[str, Any]    			= self.get_image_processor()
         _lowerCamelCase						:				List[Any]    			= self.get_tokenizer()

         _lowerCamelCase						:				List[str]    			= AlignProcessor(tokenizer=__lowerCAmelCase						,					image_processor=__lowerCAmelCase		)

         _lowerCamelCase						:				List[Any]    			= '''lower newer'''

         _lowerCamelCase						:				Tuple    			= processor(text=__lowerCAmelCase		)

         _lowerCamelCase						:				str    			= tokenizer(__lowerCAmelCase						,					padding='''max_length'''						,					max_length=6_4		)

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




  def 						SCREAMING_SNAKE_CASE				( self     :						Union[str, Any]		):






         """simple docstring"""






         _lowerCamelCase						:				int    			= self.get_image_processor()
         _lowerCamelCase						:				Optional[Any]    			= self.get_tokenizer()

         _lowerCamelCase						:				str    			= AlignProcessor(tokenizer=__lowerCAmelCase						,					image_processor=__lowerCAmelCase		)

         _lowerCamelCase						:				Union[str, Any]    			= '''lower newer'''
         _lowerCamelCase						:				int    			= self.prepare_image_inputs()

         _lowerCamelCase						:				int    			= 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 pytest.raises(__lowerCAmelCase		):
                processor()




  def 						SCREAMING_SNAKE_CASE				( self     :						Dict		):






         """simple docstring"""






         _lowerCamelCase						:				int    			= self.get_image_processor()
         _lowerCamelCase						:				int    			= self.get_tokenizer()

         _lowerCamelCase						:				Any    			= AlignProcessor(tokenizer=__lowerCAmelCase						,					image_processor=__lowerCAmelCase		)

         _lowerCamelCase						:				List[str]    			= [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

         _lowerCamelCase						:				Optional[int]    			= processor.batch_decode(__lowerCAmelCase		)
         _lowerCamelCase						:				List[Any]    			= tokenizer.batch_decode(__lowerCAmelCase		)

         self.assertListEqual(__lowerCAmelCase						,					__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Union[str, Any]		):






         """simple docstring"""






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

         _lowerCamelCase						:				Optional[Any]    			= AlignProcessor(tokenizer=__lowerCAmelCase						,					image_processor=__lowerCAmelCase		)

         _lowerCamelCase						:				Optional[int]    			= '''lower newer'''
         _lowerCamelCase						:				Tuple    			= self.prepare_image_inputs()

         _lowerCamelCase						:				Union[str, Any]    			= processor(text=__lowerCAmelCase						,					images=__lowerCAmelCase		)

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



'''simple docstring'''




import math




def 							lowerCamelCase	(      UpperCAmelCase__       :					int )			->      int:

							if not isinstance(UpperCAmelCase__      ,      UpperCAmelCase__ ):
														lowercase_					:			List[Any]										=       F'''Input value of [number={number}] must be an integer'''
														raise TypeError(UpperCAmelCase__ )

							if number < 1:
														lowercase_					:			Tuple										=       F'''Input value of [number={number}] must be > 0'''
														raise ValueError(UpperCAmelCase__ )
							elif number == 1:
														return 3
							elif number == 2:
														return 5
							else:
														lowercase_					:			Union[str, Any]										=       int(math.log(number // 3      ,      2 ) ) + 2

														lowercase_					:			Any										=       [3, 5]
														lowercase_					:			List[Any]										=       2
														lowercase_					:			Optional[Any]										=       3
														for block in range(1      ,      UpperCAmelCase__ ):
																					for _ in range(UpperCAmelCase__ ):
																												proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1] )
																												proth_index += 1
																					increment *= 2

							return proth_list[number - 1]


if __name__ == "__main__":
						import doctest

						doctest.testmod()

						for number in range(11):
												_lowercase						: Optional[Any]						=						0
												try:
																		_lowercase						: str						=						proth(number)
												except ValueError:
																		print(f"""ValueError: there is no {number}th Proth number""")
																		continue

												print(f"""The {number}th Proth number: {value}""")





