"""simple docstring"""







import unittest

import numpy as np
import requests

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
				import torch

				from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
				SCREAMING_SNAKE_CASE									=						False

if is_vision_available():
				from PIL import Image

				from transformers import PixaStructImageProcessor



class  _lowerCamelCase			(unittest.TestCase     ):







				def __init__( self    :       List[Any]			,					lowerCamelCase_    :       Dict			,					lowerCamelCase_    :       int=7			,					lowerCamelCase_    :       Tuple=3			,					lowerCamelCase_    :       List[str]=1_8			,					lowerCamelCase_    :       Optional[int]=3_0			,					lowerCamelCase_    :       Any=4_0_0			,					lowerCamelCase_    :       Optional[Any]=None			,					lowerCamelCase_    :       str=True			,					lowerCamelCase_    :       Optional[int]=True			,					lowerCamelCase_    :       List[str]=None			,					):

					"""simple docstring"""






					_lowercase :    Tuple							=							size if size is not None else {'height': 2_0, 'width': 2_0}
					_lowercase :    List[Any]							=							parent
					_lowercase :    int							=							batch_size
					_lowercase :    Union[str, Any]							=							num_channels
					_lowercase :    Tuple							=							image_size
					_lowercase :    str							=							min_resolution
					_lowercase :    Optional[int]							=							max_resolution
					_lowercase :    List[str]							=							size
					_lowercase :    Optional[int]							=							do_normalize
					_lowercase :    Optional[int]							=							do_convert_rgb
					_lowercase :    Dict							=							[5_1_2, 1_0_2_4, 2_0_4_8, 4_0_9_6]
					_lowercase :    Union[str, Any]							=							patch_size if patch_size is not None else {'height': 1_6, 'width': 1_6}







				def 							__UpperCAmelCase					( self    :       List[str]						):

					"""simple docstring"""






					return {"do_normalize": self.do_normalize, "do_convert_rgb": self.do_convert_rgb}







				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






					_lowercase :    Dict							=							'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/australia.jpg'
					_lowercase :    List[Any]							=							Image.open(requests.get(snake_case_			,					stream=snake_case_						).raw						).convert('RGB'						)
					return raw_image



@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11						,							reason="`Pix2StructImageProcessor` requires `torch>=1.11.0`."						,							)
@require_torch
@require_vision
class  _lowerCamelCase			(_a						,							unittest.TestCase     ):
				_snake_case     =  PixaStructImageProcessor if is_vision_available() else None







				def 							__UpperCAmelCase					( self    :       List[Any]						):

					"""simple docstring"""






					_lowercase :    Union[str, Any]							=							PixaStructImageProcessingTester(self						)







				@property
				def 							__UpperCAmelCase					( self    :       str						):

					"""simple docstring"""






					return self.image_processor_tester.prepare_image_processor_dict()







				def 							__UpperCAmelCase					( self    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    Union[str, Any]							=							self.image_processing_class(**self.image_processor_dict						)
					self.assertTrue(hasattr(snake_case_			,					'do_normalize'						)						)
					self.assertTrue(hasattr(snake_case_			,					'do_convert_rgb'						)						)







				def 							__UpperCAmelCase					( self    :       Any						):

					"""simple docstring"""






					_lowercase :    Tuple							=							self.image_processor_tester.prepare_dummy_image()

					_lowercase :    Tuple							=							self.image_processing_class(**self.image_processor_dict						)
					_lowercase :    Optional[Any]							=							2_0_4_8

					_lowercase :    Optional[Any]							=							image_processor(snake_case_			,					return_tensors='pt'			,					max_patches=snake_case_						)
					self.assertTrue(torch.allclose(inputs.flattened_patches.mean()			,					torch.tensor(0.0606						)			,					atol=1E-3			,					rtol=1E-3						)						)







				def 							__UpperCAmelCase					( self    :       List[Any]						):

					"""simple docstring"""






					_lowercase :    Union[str, Any]							=							self.image_processing_class(**self.image_processor_dict						)
					# create random PIL images
					_lowercase :    Tuple							=							prepare_image_inputs(self.image_processor_tester			,					equal_resolution=snake_case_						)
					for image in image_inputs:
						self.assertIsInstance(snake_case_			,					Image.Image						)

					# Test not batched input
					_lowercase :    Union[str, Any]							=							(
					    (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
					    * self.image_processor_tester.num_channels
					) + 2

					for max_patch in self.image_processor_tester.max_patches:
						# Test not batched input
						_lowercase :    Tuple							=							image_processor(
						    image_inputs[0]			,					return_tensors='pt'			,					max_patches=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(1, max_patch, expected_hidden_dim)			,					)

						# Test batched
						_lowercase :    List[str]							=							image_processor(
						    snake_case_			,					return_tensors='pt'			,					max_patches=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)			,					)







				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






					_lowercase :    List[str]							=							self.image_processing_class(**self.image_processor_dict						)
					# create random PIL images
					_lowercase :    Optional[Any]							=							prepare_image_inputs(self.image_processor_tester			,					equal_resolution=snake_case_						)
					for image in image_inputs:
						self.assertIsInstance(snake_case_			,					Image.Image						)

					# Test not batched input
					_lowercase :    List[Any]							=							(
					    (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
					    * self.image_processor_tester.num_channels
					) + 2

					_lowercase :    Optional[Any]							=							True

					for max_patch in self.image_processor_tester.max_patches:
						# Test not batched input
						with self.assertRaises(snake_case_						):
							_lowercase :    Any							=							image_processor(
							    image_inputs[0]			,					return_tensors='pt'			,					max_patches=snake_case_						).flattened_patches

						_lowercase :    Any							=							'Hello'

						_lowercase :    List[Any]							=							image_processor(
						    image_inputs[0]			,					return_tensors='pt'			,					max_patches=snake_case_			,					header_text=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(1, max_patch, expected_hidden_dim)			,					)

						# Test batched
						_lowercase :    int							=							image_processor(
						    snake_case_			,					return_tensors='pt'			,					max_patches=snake_case_			,					header_text=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)			,					)







				def 							__UpperCAmelCase					( self    :       Optional[Any]						):

					"""simple docstring"""






					_lowercase :    int							=							self.image_processing_class(**self.image_processor_dict						)
					# create random numpy tensors
					_lowercase :    List[str]							=							prepare_image_inputs(self.image_processor_tester			,					equal_resolution=snake_case_			,					numpify=snake_case_						)
					for image in image_inputs:
						self.assertIsInstance(snake_case_			,					np.ndarray						)

					_lowercase :    Optional[int]							=							(
					    (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
					    * self.image_processor_tester.num_channels
					) + 2

					for max_patch in self.image_processor_tester.max_patches:
						# Test not batched input
						_lowercase :    Union[str, Any]							=							image_processor(
						    image_inputs[0]			,					return_tensors='pt'			,					max_patches=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(1, max_patch, expected_hidden_dim)			,					)

						# Test batched
						_lowercase :    List[str]							=							image_processor(
						    snake_case_			,					return_tensors='pt'			,					max_patches=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)			,					)







				def 							__UpperCAmelCase					( self    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    Dict							=							self.image_processing_class(**self.image_processor_dict						)
					# create random PyTorch tensors
					_lowercase :    str							=							prepare_image_inputs(self.image_processor_tester			,					equal_resolution=snake_case_			,					torchify=snake_case_						)
					for image in image_inputs:
						self.assertIsInstance(snake_case_			,					torch.Tensor						)

					# Test not batched input
					_lowercase :    List[Any]							=							(
					    (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
					    * self.image_processor_tester.num_channels
					) + 2

					for max_patch in self.image_processor_tester.max_patches:
						# Test not batched input
						_lowercase :    Dict							=							image_processor(
						    image_inputs[0]			,					return_tensors='pt'			,					max_patches=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(1, max_patch, expected_hidden_dim)			,					)

						# Test batched
						_lowercase :    Tuple							=							image_processor(
						    snake_case_			,					return_tensors='pt'			,					max_patches=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)			,					)



@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11						,							reason="`Pix2StructImageProcessor` requires `torch>=1.11.0`."						,							)
@require_torch
@require_vision
class  _lowerCamelCase			(_a						,							unittest.TestCase     ):
				_snake_case     =  PixaStructImageProcessor if is_vision_available() else None







				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






					_lowercase :    List[Any]							=							PixaStructImageProcessingTester(self			,					num_channels=4						)
					_lowercase :    List[Any]							=							3







				@property
				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






					return self.image_processor_tester.prepare_image_processor_dict()







				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






					_lowercase :    int							=							self.image_processing_class(**self.image_processor_dict						)
					self.assertTrue(hasattr(snake_case_			,					'do_normalize'						)						)
					self.assertTrue(hasattr(snake_case_			,					'do_convert_rgb'						)						)







				def 							__UpperCAmelCase					( self    :       Dict						):

					"""simple docstring"""






					_lowercase :    Optional[int]							=							self.image_processing_class(**self.image_processor_dict						)
					# create random PIL images
					_lowercase :    Optional[Any]							=							prepare_image_inputs(self.image_processor_tester			,					equal_resolution=snake_case_						)
					for image in image_inputs:
						self.assertIsInstance(snake_case_			,					Image.Image						)

					# Test not batched input
					_lowercase :    Optional[int]							=							(
					    (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
					    * (self.image_processor_tester.num_channels - 1)
					) + 2

					for max_patch in self.image_processor_tester.max_patches:
						# Test not batched input
						_lowercase :    str							=							image_processor(
						    image_inputs[0]			,					return_tensors='pt'			,					max_patches=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(1, max_patch, expected_hidden_dim)			,					)

						# Test batched
						_lowercase :    List[str]							=							image_processor(
						    snake_case_			,					return_tensors='pt'			,					max_patches=snake_case_						).flattened_patches
						self.assertEqual(
						    encoded_images.shape			,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)			,					)




"""simple docstring"""







import math


def      __lowerCAmelCase(		__UpperCAmelCase			):






	"""simple docstring"""





	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 :    List[Any]							=							F'''Input value of [number={number}] must be > 0'''
		raise ValueError(__UpperCAmelCase			)
	elif number == 1:
		return 3
	elif number == 2:
		return 5
	else:
		_lowercase :    str							=							int(math.log(number // 3     ,2			)			) + 2

		_lowercase :    Union[str, Any]							=							[3, 5]
		_lowercase :    Optional[int]							=							2
		_lowercase :    List[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):
												SCREAMING_SNAKE_CASE									=						0
												try:
																		SCREAMING_SNAKE_CASE									=						proth(number)
												except ValueError:
																		print(f"""ValueError: there is no {number}th Proth number""")
																		continue

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



