






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:
	lowerCamelCase       :       Optional[int]        =				False

if is_vision_available():
	from PIL import Image

	from transformers import PixaStructImageProcessor

class 						lowerCAmelCase   (       unittest.TestCase	):

					'''simple docstring'''

					def __init__(     self :		Union[str, Any]						,   __a :		Dict						,   __a :		Tuple=7						,   __a :		str=3						,   __a :		Optional[Any]=18						,   __a :		int=30						,   __a :		Tuple=400						,   __a :		Optional[Any]=None						,   __a :		Optional[Any]=True						,   __a :		List[Any]=True						,   __a :		List[str]=None						,   )	->     Dict:


												"""simple docstring"""

												__lowercase					:							Union[str, Any]			=   size if size is not None else {"""height""": 20, """width""": 20}
												__lowercase					:							Optional[int]			=   parent
												__lowercase					:							Optional[Any]			=   batch_size
												__lowercase					:							Union[str, Any]			=   num_channels
												__lowercase					:							str			=   image_size
												__lowercase					:							List[str]			=   min_resolution
												__lowercase					:							Optional[Any]			=   max_resolution
												__lowercase					:							Tuple			=   size
												__lowercase					:							Union[str, Any]			=   do_normalize
												__lowercase					:							Tuple			=   do_convert_rgb
												__lowercase					:							int			=   [512, 1024, 2048, 4096]
												__lowercase					:							List[Any]			=   patch_size if patch_size is not None else {"""height""": 16, """width""": 16}



					def 					lowerCAmelCase (     self :		Any							)	->     Union[str, Any]:


												"""simple docstring"""

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



					def 					lowerCAmelCase (     self :		Union[str, Any]							)	->     Dict:


												"""simple docstring"""

												__lowercase					:							Tuple			=   """https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/australia.jpg"""
												__lowercase					:							int			=   Image.open(requests.get(__a						,   stream=__a							).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	):

					'''simple docstring'''

					_A  :	Tuple     =					PixaStructImageProcessor if is_vision_available() else None



					def 					lowerCAmelCase (     self :		Tuple							)	->     List[Any]:


												"""simple docstring"""

												__lowercase					:							Optional[int]			=   PixaStructImageProcessingTester(self							)



					@property
					def 					lowerCAmelCase (     self :		Optional[int]							)	->     List[str]:


												"""simple docstring"""

												return self.image_processor_tester.prepare_image_processor_dict()



					def 					lowerCAmelCase (     self :		Tuple							)	->     int:


												"""simple docstring"""

												__lowercase					:							Tuple			=   self.image_processing_class(**self.image_processor_dict							)
												self.assertTrue(hasattr(__a						,   """do_normalize"""							)							)
												self.assertTrue(hasattr(__a						,   """do_convert_rgb"""							)							)



					def 					lowerCAmelCase (     self :		Any							)	->     Optional[Any]:


												"""simple docstring"""

												__lowercase					:							List[Any]			=   self.image_processor_tester.prepare_dummy_image()

												__lowercase					:							List[Any]			=   self.image_processing_class(**self.image_processor_dict							)
												__lowercase					:							int			=   2048

												__lowercase					:							Dict			=   image_processor(__a						,   return_tensors="""pt"""						,   max_patches=__a							)
												self.assertTrue(torch.allclose(inputs.flattened_patches.mean()						,   torch.tensor(0.0606							)						,   atol=1E-3						,   rtol=1E-3							)							)



					def 					lowerCAmelCase (     self :		List[Any]							)	->     Dict:


												"""simple docstring"""

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

												# Test not batched input
												__lowercase					:							List[str]			=   (
												    (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					:							List[Any]			=   image_processor(
																			    image_inputs[0]						,   return_tensors="""pt"""						,   max_patches=__a							).flattened_patches
																			self.assertEqual(
																			    encoded_images.shape						,   (1, max_patch, expected_hidden_dim)						,   )

																			# Test batched
																			__lowercase					:							int			=   image_processor(
																			    __a						,   return_tensors="""pt"""						,   max_patches=__a							).flattened_patches
																			self.assertEqual(
																			    encoded_images.shape						,   (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)						,   )



					def 					lowerCAmelCase (     self :		str							)	->     Tuple:


												"""simple docstring"""

												__lowercase					:							List[Any]			=   self.image_processing_class(**self.image_processor_dict							)
												# create random PIL images
												__lowercase					:							int			=   prepare_image_inputs(self.image_processor_tester						,   equal_resolution=__a							)
												for image in image_inputs:
																			self.assertIsInstance(__a						,   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

												__lowercase					:							Optional[Any]			=   True

												for max_patch in self.image_processor_tester.max_patches:
																			# Test not batched input
																			with self.assertRaises(__a							):
																										__lowercase					:							str			=   image_processor(
																										    image_inputs[0]						,   return_tensors="""pt"""						,   max_patches=__a							).flattened_patches

																			__lowercase					:							int			=   """Hello"""

																			__lowercase					:							Union[str, Any]			=   image_processor(
																			    image_inputs[0]						,   return_tensors="""pt"""						,   max_patches=__a						,   header_text=__a							).flattened_patches
																			self.assertEqual(
																			    encoded_images.shape						,   (1, max_patch, expected_hidden_dim)						,   )

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



					def 					lowerCAmelCase (     self :		Any							)	->     Optional[Any]:


												"""simple docstring"""

												__lowercase					:							Tuple			=   self.image_processing_class(**self.image_processor_dict							)
												# create random numpy tensors
												__lowercase					:							str			=   prepare_image_inputs(self.image_processor_tester						,   equal_resolution=__a						,   numpify=__a							)
												for image in image_inputs:
																			self.assertIsInstance(__a						,   np.ndarray							)

												__lowercase					:							Tuple			=   (
												    (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					:							str			=   image_processor(
																			    image_inputs[0]						,   return_tensors="""pt"""						,   max_patches=__a							).flattened_patches
																			self.assertEqual(
																			    encoded_images.shape						,   (1, max_patch, expected_hidden_dim)						,   )

																			# Test batched
																			__lowercase					:							Tuple			=   image_processor(
																			    __a						,   return_tensors="""pt"""						,   max_patches=__a							).flattened_patches
																			self.assertEqual(
																			    encoded_images.shape						,   (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)						,   )



					def 					lowerCAmelCase (     self :		int							)	->     Optional[int]:


												"""simple docstring"""

												__lowercase					:							int			=   self.image_processing_class(**self.image_processor_dict							)
												# create random PyTorch tensors
												__lowercase					:							int			=   prepare_image_inputs(self.image_processor_tester						,   equal_resolution=__a						,   torchify=__a							)
												for image in image_inputs:
																			self.assertIsInstance(__a						,   torch.Tensor							)

												# 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
												) + 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=__a							).flattened_patches
																			self.assertEqual(
																			    encoded_images.shape						,   (1, max_patch, expected_hidden_dim)						,   )

																			# Test batched
																			__lowercase					:							List[str]			=   image_processor(
																			    __a						,   return_tensors="""pt"""						,   max_patches=__a							).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	):

					'''simple docstring'''

					_A  :	Dict     =					PixaStructImageProcessor if is_vision_available() else None



					def 					lowerCAmelCase (     self :		Union[str, Any]							)	->     str:


												"""simple docstring"""

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



					@property
					def 					lowerCAmelCase (     self :		Union[str, Any]							)	->     Dict:


												"""simple docstring"""

												return self.image_processor_tester.prepare_image_processor_dict()



					def 					lowerCAmelCase (     self :		Dict							)	->     Tuple:


												"""simple docstring"""

												__lowercase					:							Optional[int]			=   self.image_processing_class(**self.image_processor_dict							)
												self.assertTrue(hasattr(__a						,   """do_normalize"""							)							)
												self.assertTrue(hasattr(__a						,   """do_convert_rgb"""							)							)



					def 					lowerCAmelCase (     self :		Tuple							)	->     List[str]:


												"""simple docstring"""

												__lowercase					:							Union[str, Any]			=   self.image_processing_class(**self.image_processor_dict							)
												# create random PIL images
												__lowercase					:							int			=   prepare_image_inputs(self.image_processor_tester						,   equal_resolution=__a							)
												for image in image_inputs:
																			self.assertIsInstance(__a						,   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 - 1)
												) + 2

												for max_patch in self.image_processor_tester.max_patches:
																			# Test not batched input
																			__lowercase					:							List[Any]			=   image_processor(
																			    image_inputs[0]						,   return_tensors="""pt"""						,   max_patches=__a							).flattened_patches
																			self.assertEqual(
																			    encoded_images.shape						,   (1, max_patch, expected_hidden_dim)						,   )

																			# Test batched
																			__lowercase					:							Tuple			=   image_processor(
																			    __a						,   return_tensors="""pt"""						,   max_patches=__a							).flattened_patches
																			self.assertEqual(
																			    encoded_images.shape						,   (self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)						,   )







from itertools import permutations
def 					snake_case_						(   lowerCAmelCase_				:  tuple					):
							if num[3] % 2 != 0:
														return False

							if (num[2] + num[3] + num[4]) % 3 != 0:
														return False

							if num[5] % 5 != 0:
														return False

							__lowercase					:							Dict			=   [7, 11, 13, 17]
							for i, test in enumerate(lowerCAmelCase_					):
														if (num[i + 4] * 100 + num[i + 5] * 10 + num[i + 6]) % test != 0:
																					return False
							return True
def 					snake_case_						(   lowerCAmelCase_				:  int = 10					):
							return sum(
							    int("""""".join(map(lowerCAmelCase_				,				lowerCAmelCase_					)					)					)
							    for num in permutations(range(lowerCAmelCase_					)					)
							    if is_substring_divisible(lowerCAmelCase_					)					)


if __name__ == "__main__":
	print(f'''{solution() = }''')