


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





			'''simple docstring'''

			def 					lowerCAmelCase     (  self							:			int	)      ->		List[str]:
						__A=	tempfile.mkdtemp()

						# fmt: off
						__A=	['[UNK]', '[CLS]', '[SEP]', '[PAD]', '[MASK]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing', ',', 'low', 'lowest']
						# fmt: on
						__A=	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=	{
						    '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=	os.path.join(self.tmpdirname			,    lowerCAmelCase_	)
						with open(self.image_processor_file			,    'w'			,    encoding='utf-8'	) as fp:
									json.dump(lowerCAmelCase_			,    lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			Dict			,    **lowerCAmelCase_							:			Any	)      ->		int:
						return BertTokenizer.from_pretrained(self.tmpdirname			,    **lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			str			,    **lowerCAmelCase_							:			Optional[Any]	)      ->		Dict:
						return ViTImageProcessor.from_pretrained(self.tmpdirname			,    **lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			Optional[Any]	)      ->		Any:
						shutil.rmtree(self.tmpdirname	)
			def 					lowerCAmelCase     (  self							:			Optional[Any]	)      ->		Tuple:
						__A=	[np.random.randint(255			,    size=(3, 30, 400)			,    dtype=np.uinta	)]

						__A=	[Image.fromarray(np.moveaxis(lowerCAmelCase_			,    0			,    -1	)	) for x in image_inputs]

						return image_inputs
			def 					lowerCAmelCase     (  self							:			str	)      ->		int:
						__A=	self.get_tokenizer()
						__A=	self.get_image_processor()

						__A=	VisionTextDualEncoderProcessor(tokenizer=lowerCAmelCase_			,    image_processor=lowerCAmelCase_	)

						processor.save_pretrained(self.tmpdirname	)
						__A=	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 					lowerCAmelCase     (  self							:			Optional[int]	)      ->		Union[str, Any]:
						__A=	VisionTextDualEncoderProcessor(
						    tokenizer=self.get_tokenizer()			,    image_processor=self.get_image_processor()	)
						processor.save_pretrained(self.tmpdirname	)

						__A=	self.get_tokenizer(bos_token='(BOS)'			,    eos_token='(EOS)'	)
						__A=	self.get_image_processor(do_normalize=lowerCAmelCase_			,    padding_value=1.0	)

						__A=	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 					lowerCAmelCase     (  self							:			List[Any]	)      ->		Tuple:
						__A=	self.get_image_processor()
						__A=	self.get_tokenizer()

						__A=	VisionTextDualEncoderProcessor(tokenizer=lowerCAmelCase_			,    image_processor=lowerCAmelCase_	)

						__A=	self.prepare_image_inputs()

						__A=	image_processor(lowerCAmelCase_			,    return_tensors='np'	)
						__A=	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 					lowerCAmelCase     (  self							:			Union[str, Any]	)      ->		Any:
						__A=	self.get_image_processor()
						__A=	self.get_tokenizer()

						__A=	VisionTextDualEncoderProcessor(tokenizer=lowerCAmelCase_			,    image_processor=lowerCAmelCase_	)

						__A=	'lower newer'

						__A=	processor(text=lowerCAmelCase_	)

						__A=	tokenizer(lowerCAmelCase_	)

						for key in encoded_tok.keys():
									self.assertListEqual(encoded_tok[key]			,    encoded_processor[key]	)
			def 					lowerCAmelCase     (  self							:			Union[str, Any]	)      ->		int:
						__A=	self.get_image_processor()
						__A=	self.get_tokenizer()

						__A=	VisionTextDualEncoderProcessor(tokenizer=lowerCAmelCase_			,    image_processor=lowerCAmelCase_	)

						__A=	'lower newer'
						__A=	self.prepare_image_inputs()

						__A=	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 					lowerCAmelCase     (  self							:			str	)      ->		str:
						__A=	self.get_image_processor()
						__A=	self.get_tokenizer()

						__A=	VisionTextDualEncoderProcessor(tokenizer=lowerCAmelCase_			,    image_processor=lowerCAmelCase_	)

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

						__A=	processor.batch_decode(lowerCAmelCase_	)
						__A=	tokenizer.batch_decode(lowerCAmelCase_	)

						self.assertListEqual(lowerCAmelCase_			,    lowerCAmelCase_	)

			def 					lowerCAmelCase     (  self							:			int	)      ->		Optional[int]:
						__A=	self.get_image_processor()
						__A=	self.get_tokenizer()

						__A=	VisionTextDualEncoderProcessor(tokenizer=lowerCAmelCase_			,    image_processor=lowerCAmelCase_	)

						__A=	'lower newer'
						__A=	self.prepare_image_inputs()

						__A=	processor(text=lowerCAmelCase_			,    images=lowerCAmelCase_	)

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







'''simple docstring'''





import math






def 						UpperCAmelCase__(				_SCREAMING_SNAKE_CASE					: int ):






			"""simple docstring"""




			if not isinstance(_SCREAMING_SNAKE_CASE,_SCREAMING_SNAKE_CASE ):
						__A=	f"""Input value of [number={number}] must be an integer"""
						raise TypeError(_SCREAMING_SNAKE_CASE )

			if number < 1:
						__A=	f"""Input value of [number={number}] must be > 0"""
						raise ValueError(_SCREAMING_SNAKE_CASE )
			elif number == 1:
						return 3
			elif number == 2:
						return 5
			else:
						__A=	int(math.log(number // 3,2 ) ) + 2

						__A=	[3, 5]
						__A=	2
						__A=	3
						for block in range(1,_SCREAMING_SNAKE_CASE ):
									for _ in range(_SCREAMING_SNAKE_CASE ):
												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(1_1):
										UpperCAmelCase__  			=				0
										try:
															UpperCAmelCase__  			=				proth(number)
										except ValueError:
															print(F"""ValueError: there is no {number}th Proth number""")
															continue

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



