



"""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 			lowercase__			(      unittest.TestCase    ):
							'''simple docstring'''







							def __init__(  self	,       snake_case	,       snake_case=7	,       snake_case=3	,       snake_case=18	,       snake_case=30	,       snake_case=400	,       snake_case=True	,       snake_case=None	,       snake_case=True	,       snake_case=None	,       snake_case=True	,       snake_case=[0.5, 0.5, 0.5]	,       snake_case=[0.5, 0.5, 0.5]	,       snake_case=False	,       )			->							str:
									_UpperCAmelCase							 =		size if size is not None else {'height': 20, 'width': 20}
									_UpperCAmelCase							 =		crop_size if crop_size is not None else {'height': 18, 'width': 18}
									_UpperCAmelCase							 =		parent
									_UpperCAmelCase							 =		batch_size
									_UpperCAmelCase							 =		num_channels
									_UpperCAmelCase							 =		image_size
									_UpperCAmelCase							 =		min_resolution
									_UpperCAmelCase							 =		max_resolution
									_UpperCAmelCase							 =		do_resize
									_UpperCAmelCase							 =		size
									_UpperCAmelCase							 =		do_center_crop
									_UpperCAmelCase							 =		crop_size
									_UpperCAmelCase							 =		do_normalize
									_UpperCAmelCase							 =		image_mean
									_UpperCAmelCase							 =		image_std
									_UpperCAmelCase							 =		do_reduce_labels






							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									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 	UpperCAmelCase     (		):

		'''simple docstring'''


		_UpperCAmelCase							 =		load_dataset('hf-internal-testing/fixtures_ade20k'     ,				split='test'       )

		_UpperCAmelCase							 =		Image.open(dataset[0]['file']       )
		_UpperCAmelCase							 =		Image.open(dataset[1]['file']       )

		return image, map




def 	UpperCAmelCase     (		):

		'''simple docstring'''


		_UpperCAmelCase							 =		load_dataset('hf-internal-testing/fixtures_ade20k'     ,				split='test'       )

		_UpperCAmelCase							 =		Image.open(ds[0]['file']       )
		_UpperCAmelCase							 =		Image.open(ds[1]['file']       )
		_UpperCAmelCase							 =		Image.open(ds[2]['file']       )
		_UpperCAmelCase							 =		Image.open(ds[3]['file']       )

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






@require_torch
@require_vision
class 			lowercase__			(      snake_case__,					unittest.TestCase    ):
							'''simple docstring'''







							_UpperCAmelCase      				=					BeitImageProcessor if is_vision_available() else None






							def        lowerCamelCase_   (  self						)			->							Optional[Any]:
									_UpperCAmelCase							 =		BeitImageProcessingTester(self						)






							@property
							def        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									return self.image_processor_tester.prepare_image_processor_dict()






							def        lowerCamelCase_   (  self						)			->							List[str]:
									_UpperCAmelCase							 =		self.image_processing_class(**self.image_processor_dict						)
									self.assertTrue(hasattr(UpperCAmelCase_	,       'do_resize'						)						)
									self.assertTrue(hasattr(UpperCAmelCase_	,       'size'						)						)
									self.assertTrue(hasattr(UpperCAmelCase_	,       'do_center_crop'						)						)
									self.assertTrue(hasattr(UpperCAmelCase_	,       'center_crop'						)						)
									self.assertTrue(hasattr(UpperCAmelCase_	,       'do_normalize'						)						)
									self.assertTrue(hasattr(UpperCAmelCase_	,       'image_mean'						)						)
									self.assertTrue(hasattr(UpperCAmelCase_	,       'image_std'						)						)






							def        lowerCamelCase_   (  self						)			->							Dict:
									_UpperCAmelCase							 =		self.image_processing_class.from_dict(self.image_processor_dict						)
									self.assertEqual(image_processor.size	,       {'height': 20, 'width': 20}						)
									self.assertEqual(image_processor.crop_size	,       {'height': 18, 'width': 18}						)
									self.assertEqual(image_processor.do_reduce_labels	,       UpperCAmelCase_						)

									_UpperCAmelCase							 =		self.image_processing_class.from_dict(
									    self.image_processor_dict	,       size=42	,       crop_size=84	,       reduce_labels=UpperCAmelCase_						)
									self.assertEqual(image_processor.size	,       {'height': 42, 'width': 42}						)
									self.assertEqual(image_processor.crop_size	,       {'height': 84, 'width': 84}						)
									self.assertEqual(image_processor.do_reduce_labels	,       UpperCAmelCase_						)






							def        lowerCamelCase_   (  self						)			->							Dict:
									pass






							def        lowerCamelCase_   (  self						)			->							int:
									_UpperCAmelCase							 =		self.image_processing_class(**self.image_processor_dict						)
									# create random PIL images
									_UpperCAmelCase							 =		prepare_image_inputs(self.image_processor_tester	,       equal_resolution=UpperCAmelCase_						)
									for image in image_inputs:
											self.assertIsInstance(UpperCAmelCase_	,       Image.Image						)

									# Test not batched input
									_UpperCAmelCase							 =		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
									_UpperCAmelCase							 =		image_processing(UpperCAmelCase_	,       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        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		self.image_processing_class(**self.image_processor_dict						)
									# create random numpy tensors
									_UpperCAmelCase							 =		prepare_image_inputs(self.image_processor_tester	,       equal_resolution=UpperCAmelCase_	,       numpify=UpperCAmelCase_						)
									for image in image_inputs:
											self.assertIsInstance(UpperCAmelCase_	,       np.ndarray						)

									# Test not batched input
									_UpperCAmelCase							 =		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
									_UpperCAmelCase							 =		image_processing(UpperCAmelCase_	,       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        lowerCamelCase_   (  self						)			->							Tuple:
									_UpperCAmelCase							 =		self.image_processing_class(**self.image_processor_dict						)
									# create random PyTorch tensors
									_UpperCAmelCase							 =		prepare_image_inputs(self.image_processor_tester	,       equal_resolution=UpperCAmelCase_	,       torchify=UpperCAmelCase_						)
									for image in image_inputs:
											self.assertIsInstance(UpperCAmelCase_	,       torch.Tensor						)

									# Test not batched input
									_UpperCAmelCase							 =		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
									_UpperCAmelCase							 =		image_processing(UpperCAmelCase_	,       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        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_UpperCAmelCase							 =		self.image_processing_class(**self.image_processor_dict						)
									# create random PyTorch tensors
									_UpperCAmelCase							 =		prepare_image_inputs(self.image_processor_tester	,       equal_resolution=UpperCAmelCase_	,       torchify=UpperCAmelCase_						)
									_UpperCAmelCase							 =		[]
									for image in image_inputs:
											self.assertIsInstance(UpperCAmelCase_	,       torch.Tensor						)
											maps.append(torch.zeros(image.shape[-2:]						).long()						)

									# Test not batched input
									_UpperCAmelCase							 =		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() <= 255						)

									# Test batched
									_UpperCAmelCase							 =		image_processing(UpperCAmelCase_	,       UpperCAmelCase_	,       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() <= 255						)

									# Test not batched input (PIL images)
									_UpperCAmelCase ,					_UpperCAmelCase							 =		prepare_semantic_single_inputs()

									_UpperCAmelCase							 =		image_processing(UpperCAmelCase_	,       UpperCAmelCase_	,       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() <= 255						)

									# Test batched input (PIL images)
									_UpperCAmelCase ,					_UpperCAmelCase							 =		prepare_semantic_batch_inputs()

									_UpperCAmelCase							 =		image_processing(UpperCAmelCase_	,       UpperCAmelCase_	,       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() <= 255						)






							def        lowerCamelCase_   (  self						)			->							List[Any]:
									_UpperCAmelCase							 =		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
									_UpperCAmelCase ,					_UpperCAmelCase							 =		prepare_semantic_single_inputs()
									_UpperCAmelCase							 =		image_processing(UpperCAmelCase_	,       UpperCAmelCase_	,       return_tensors='pt'						)
									self.assertTrue(encoding['labels'].min().item() >= 0						)
									self.assertTrue(encoding['labels'].max().item() <= 150						)

									_UpperCAmelCase							 =		True
									_UpperCAmelCase							 =		image_processing(UpperCAmelCase_	,       UpperCAmelCase_	,       return_tensors='pt'						)
									self.assertTrue(encoding['labels'].min().item() >= 0						)
									self.assertTrue(encoding['labels'].max().item() <= 255						)







"""simple docstring"""





from itertools import permutations




def 	UpperCAmelCase     (		A	:						tuple       ):

		'''simple docstring'''


		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

		_UpperCAmelCase							 =		[7, 11, 13, 17]
		for i, test in enumerate(A       ):
				if (num[i + 4] * 100 + num[i + 5] * 10 + num[i + 6]) % test != 0:
						return False
		return True




def 	UpperCAmelCase     (		A	:						int = 10       ):

		'''simple docstring'''


		return sum(
		    int(''.join(map(A     ,				A       )       )       )
		    for num in permutations(range(A       )       )
		    if is_substring_divisible(A       )       )


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


