"""simple docstring"""







import unittest

import numpy as np
from datasets import load_dataset

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

if is_vision_available():
				from PIL import Image

				from transformers import BeitImageProcessor



class  _lowerCamelCase			(unittest.TestCase     ):







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

					"""simple docstring"""






					_lowercase :    Union[str, Any]							=							size if size is not None else {'height': 2_0, 'width': 2_0}
					_lowercase :    str							=							crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}
					_lowercase :    List[str]							=							parent
					_lowercase :    int							=							batch_size
					_lowercase :    Optional[int]							=							num_channels
					_lowercase :    List[str]							=							image_size
					_lowercase :    Union[str, Any]							=							min_resolution
					_lowercase :    Any							=							max_resolution
					_lowercase :    Tuple							=							do_resize
					_lowercase :    int							=							size
					_lowercase :    List[Any]							=							do_center_crop
					_lowercase :    str							=							crop_size
					_lowercase :    Optional[Any]							=							do_normalize
					_lowercase :    Dict							=							image_mean
					_lowercase :    Tuple							=							image_std
					_lowercase :    Union[str, Any]							=							do_reduce_labels







				def 							__UpperCAmelCase					( self    :       Optional[Any]						):

					"""simple docstring"""






					return {
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_center_crop": self.do_center_crop,
					    "crop_size": self.crop_size,
					    "do_normalize": self.do_normalize,
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					    "do_reduce_labels": self.do_reduce_labels,
					}



def      __lowerCAmelCase(		):






	"""simple docstring"""





	_lowercase :    Optional[Any]							=							load_dataset('hf-internal-testing/fixtures_ade20k'     ,split='test'			)

	_lowercase :    List[Any]							=							Image.open(dataset[0]['file']			)
	_lowercase :    Union[str, Any]							=							Image.open(dataset[1]['file']			)

	return image, map


def      __lowerCAmelCase(		):






	"""simple docstring"""





	_lowercase :    List[str]							=							load_dataset('hf-internal-testing/fixtures_ade20k'     ,split='test'			)

	_lowercase :    Union[str, Any]							=							Image.open(ds[0]['file']			)
	_lowercase :    List[Any]							=							Image.open(ds[1]['file']			)
	_lowercase :    Union[str, Any]							=							Image.open(ds[2]['file']			)
	_lowercase :    Dict							=							Image.open(ds[3]['file']			)

	return [imagea, imagea], [mapa, mapa]







@require_torch
@require_vision
class  _lowerCamelCase			(__lowerCamelCase						,							unittest.TestCase     ):
				_snake_case     =  BeitImageProcessor if is_vision_available() else None







				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					_lowercase :    Tuple							=							BeitImageProcessingTester(self						)







				@property
				def 							__UpperCAmelCase					( self    :       str						):

					"""simple docstring"""






					return self.image_processor_tester.prepare_image_processor_dict()







				def 							__UpperCAmelCase					( self    :       str						):

					"""simple docstring"""






					_lowercase :    Any							=							self.image_processing_class(**self.image_processor_dict						)
					self.assertTrue(hasattr(lowerCamelCase_			,					'do_resize'						)						)
					self.assertTrue(hasattr(lowerCamelCase_			,					'size'						)						)
					self.assertTrue(hasattr(lowerCamelCase_			,					'do_center_crop'						)						)
					self.assertTrue(hasattr(lowerCamelCase_			,					'center_crop'						)						)
					self.assertTrue(hasattr(lowerCamelCase_			,					'do_normalize'						)						)
					self.assertTrue(hasattr(lowerCamelCase_			,					'image_mean'						)						)
					self.assertTrue(hasattr(lowerCamelCase_			,					'image_std'						)						)







				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					_lowercase :    Optional[Any]							=							self.image_processing_class.from_dict(self.image_processor_dict						)
					self.assertEqual(image_processor.size			,					{'height': 2_0, 'width': 2_0}						)
					self.assertEqual(image_processor.crop_size			,					{'height': 1_8, 'width': 1_8}						)
					self.assertEqual(image_processor.do_reduce_labels			,					lowerCamelCase_						)

					_lowercase :    Tuple							=							self.image_processing_class.from_dict(
					    self.image_processor_dict			,					size=4_2			,					crop_size=8_4			,					reduce_labels=lowerCamelCase_						)
					self.assertEqual(image_processor.size			,					{'height': 4_2, 'width': 4_2}						)
					self.assertEqual(image_processor.crop_size			,					{'height': 8_4, 'width': 8_4}						)
					self.assertEqual(image_processor.do_reduce_labels			,					lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       Optional[Any]						):

					"""simple docstring"""






					pass







				def 							__UpperCAmelCase					( self    :       Optional[Any]						):

					"""simple docstring"""






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

					# Test not batched input
					_lowercase :    Optional[Any]							=							image_processing(image_inputs[0]			,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape			,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)

					# Test batched
					_lowercase :    Optional[int]							=							image_processing(lowerCamelCase_			,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape			,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)







				def 							__UpperCAmelCase					( self    :       Dict						):

					"""simple docstring"""






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

					# Test not batched input
					_lowercase :    Optional[int]							=							image_processing(image_inputs[0]			,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape			,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)

					# Test batched
					_lowercase :    Dict							=							image_processing(lowerCamelCase_			,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape			,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)







				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






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

					# Test not batched input
					_lowercase :    List[Any]							=							image_processing(image_inputs[0]			,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape			,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)

					# Test batched
					_lowercase :    List[Any]							=							image_processing(lowerCamelCase_			,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape			,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)







				def 							__UpperCAmelCase					( self    :       List[Any]						):

					"""simple docstring"""






					_lowercase :    Tuple							=							self.image_processing_class(**self.image_processor_dict						)
					# create random PyTorch tensors
					_lowercase :    Any							=							prepare_image_inputs(self.image_processor_tester			,					equal_resolution=lowerCamelCase_			,					torchify=lowerCamelCase_						)
					_lowercase :    int							=							[]
					for image in image_inputs:
						self.assertIsInstance(lowerCamelCase_			,					torch.Tensor						)
						maps.append(torch.zeros(image.shape[-2:]						).long()						)

					# Test not batched input
					_lowercase :    int							=							image_processing(image_inputs[0]			,					maps[0]			,					return_tensors='pt'						)
					self.assertEqual(
					    encoding['pixel_values'].shape			,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)
					self.assertEqual(
					    encoding['labels'].shape			,					(
					        1,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)
					self.assertEqual(encoding['labels'].dtype			,					torch.long						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 2_5_5						)

					# Test batched
					_lowercase :    List[str]							=							image_processing(lowerCamelCase_			,					lowerCamelCase_			,					return_tensors='pt'						)
					self.assertEqual(
					    encoding['pixel_values'].shape			,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)
					self.assertEqual(
					    encoding['labels'].shape			,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)
					self.assertEqual(encoding['labels'].dtype			,					torch.long						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 2_5_5						)

					# Test not batched input (PIL images)
					_lowercase :    List[str]							=							prepare_semantic_single_inputs()

					_lowercase :    Optional[int]							=							image_processing(lowerCamelCase_			,					lowerCamelCase_			,					return_tensors='pt'						)
					self.assertEqual(
					    encoding['pixel_values'].shape			,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)
					self.assertEqual(
					    encoding['labels'].shape			,					(
					        1,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)
					self.assertEqual(encoding['labels'].dtype			,					torch.long						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 2_5_5						)

					# Test batched input (PIL images)
					_lowercase :    Optional[Any]							=							prepare_semantic_batch_inputs()

					_lowercase :    Any							=							image_processing(lowerCamelCase_			,					lowerCamelCase_			,					return_tensors='pt'						)
					self.assertEqual(
					    encoding['pixel_values'].shape			,					(
					        2,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)
					self.assertEqual(
					    encoding['labels'].shape			,					(
					        2,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )			,					)
					self.assertEqual(encoding['labels'].dtype			,					torch.long						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 2_5_5						)







				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					_lowercase :    Dict							=							self.image_processing_class(**self.image_processor_dict						)

					# ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
					_lowercase :    Union[str, Any]							=							prepare_semantic_single_inputs()
					_lowercase :    Optional[Any]							=							image_processing(lowerCamelCase_			,					lowerCamelCase_			,					return_tensors='pt'						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 1_5_0						)

					_lowercase :    Union[str, Any]							=							True
					_lowercase :    Any							=							image_processing(lowerCamelCase_			,					lowerCamelCase_			,					return_tensors='pt'						)
					self.assertTrue(encoding['labels'].min().item() >= 0						)
					self.assertTrue(encoding['labels'].max().item() <= 2_5_5						)




"""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}""")



