
import unittest

import numpy as np

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


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import SwinaSRImageProcessor
		from transformers.image_transforms import get_image_size



class       a_   ( unittest.TestCase						):






			def __init__(			self							, __UpperCamelCase							, __UpperCamelCase=7							, __UpperCamelCase=3							, __UpperCamelCase=18							, __UpperCamelCase=30							, __UpperCamelCase=400							, __UpperCamelCase=True							, __UpperCamelCase=1 / 255							, __UpperCamelCase=True							, __UpperCamelCase=8							, ):
									_lowercase									=				parent
									_lowercase									=				batch_size
									_lowercase									=				num_channels
									_lowercase									=				image_size
									_lowercase									=				min_resolution
									_lowercase									=				max_resolution
									_lowercase									=				do_rescale
									_lowercase									=				rescale_factor
									_lowercase									=				do_pad
									_lowercase									=				pad_size






			def       UpperCamelCase_							(			self     ):
									return {
									    "do_rescale": self.do_rescale,
									    "rescale_factor": self.rescale_factor,
									    "do_pad": self.do_pad,
									    "pad_size": self.pad_size,
									}






			def       UpperCamelCase_							(			self							, __UpperCamelCase=False							, __UpperCamelCase=False							, __UpperCamelCase=False     ):
									assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

									if equal_resolution:
															_lowercase									=				[]
															for i in range(self.batch_size     ):
																					image_inputs.append(
																					    np.random.randint(
																					        255							, size=(self.num_channels, self.max_resolution, self.max_resolution)							, dtype=np.uinta     )     )
									else:
															_lowercase									=				[]
															for i in range(self.batch_size     ):
																					_lowercase					,	_lowercase									=				np.random.choice(np.arange(self.min_resolution							, self.max_resolution     )							, 2     )
																					image_inputs.append(np.random.randint(255							, size=(self.num_channels, width, height)							, dtype=np.uinta     )     )

									if not numpify and not torchify:
															# PIL expects the channel dimension as last dimension
															_lowercase									=				[Image.fromarray(np.moveaxis(__UpperCamelCase							, 0							, -1     )     ) for x in image_inputs]

									if torchify:
															_lowercase									=				[torch.from_numpy(__UpperCamelCase     ) for x in image_inputs]

									return image_inputs







@require_torch
@require_vision
class       a_   ( _a				, unittest.TestCase						):
			a  : List[Any]				      =       SwinaSRImageProcessor if is_vision_available() else None






			def       UpperCamelCase_							(			self     ):
									_lowercase									=				SwinaSRImageProcessingTester(self     )






			@property
			def       UpperCamelCase_							(			self     ):
									return self.image_processor_tester.prepare_image_processor_dict()






			def       UpperCamelCase_							(			self     ):
									_lowercase									=				self.image_processing_class(**self.image_processor_dict     )
									self.assertTrue(hasattr(__UpperCamelCase							, """do_rescale"""     )     )
									self.assertTrue(hasattr(__UpperCamelCase							, """rescale_factor"""     )     )
									self.assertTrue(hasattr(__UpperCamelCase							, """do_pad"""     )     )
									self.assertTrue(hasattr(__UpperCamelCase							, """pad_size"""     )     )






			def       UpperCamelCase_							(			self     ):
									pass






			def       UpperCamelCase_							(			self							, __UpperCamelCase     ):
									_lowercase					,	_lowercase									=				get_image_size(__UpperCamelCase     )
									_lowercase									=				self.image_processor_tester.pad_size

									_lowercase									=				(old_height // size + 1) * size - old_height
									_lowercase									=				(old_width // size + 1) * size - old_width
									return old_height + pad_height, old_width + pad_width






			def       UpperCamelCase_							(			self     ):
									# Initialize image_processor
									_lowercase									=				self.image_processing_class(**self.image_processor_dict     )
									# create random PIL images
									_lowercase									=				self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase     )
									for image in image_inputs:
															self.assertIsInstance(__UpperCamelCase							, Image.Image     )

									# Test not batched input
									_lowercase									=				image_processor(image_inputs[0]							, return_tensors="""pt"""     ).pixel_values
									_lowercase					,	_lowercase									=				self.calculate_expected_size(np.array(image_inputs[0]     )     )
									self.assertEqual(
									    encoded_images.shape							, (
									        1,
									        self.image_processor_tester.num_channels,
									        expected_height,
									        expected_width,
									    )							, )






			def       UpperCamelCase_							(			self     ):
									# Initialize image_processor
									_lowercase									=				self.image_processing_class(**self.image_processor_dict     )
									# create random numpy tensors
									_lowercase									=				self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase							, numpify=__UpperCamelCase     )
									for image in image_inputs:
															self.assertIsInstance(__UpperCamelCase							, np.ndarray     )

									# Test not batched input
									_lowercase									=				image_processor(image_inputs[0]							, return_tensors="""pt"""     ).pixel_values
									_lowercase					,	_lowercase									=				self.calculate_expected_size(image_inputs[0]     )
									self.assertEqual(
									    encoded_images.shape							, (
									        1,
									        self.image_processor_tester.num_channels,
									        expected_height,
									        expected_width,
									    )							, )






			def       UpperCamelCase_							(			self     ):
									# Initialize image_processor
									_lowercase									=				self.image_processing_class(**self.image_processor_dict     )
									# create random PyTorch tensors
									_lowercase									=				self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase							, torchify=__UpperCamelCase     )
									for image in image_inputs:
															self.assertIsInstance(__UpperCamelCase							, torch.Tensor     )

									# Test not batched input
									_lowercase									=				image_processor(image_inputs[0]							, return_tensors="""pt"""     ).pixel_values
									_lowercase					,	_lowercase									=				self.calculate_expected_size(image_inputs[0]     )
									self.assertEqual(
									    encoded_images.shape							, (
									        1,
									        self.image_processor_tester.num_channels,
									        expected_height,
									        expected_width,
									    )							, )

def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    int:
						return n * (2 * n - 1)




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    bool:
						_lowercase									=				(1 + 24 * n) ** 0.5
						return ((1 + root) / 6) % 1 == 0




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int = 1_44					)     ->    int:
						_lowercase									=				start
						_lowercase									=				hexagonal_num(SCREAMING_SNAKE_CASE_					)
						while not is_pentagonal(SCREAMING_SNAKE_CASE_					):
												n += 1
												_lowercase									=				hexagonal_num(SCREAMING_SNAKE_CASE_					)
						return num


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