





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, prepare_image_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import ViTImageProcessor







class 	_UpperCamelCase	(							unittest.TestCase	):







					'''simple docstring'''

					def __init__(    self     :	List[str]			,       __lowercase     :	Union[str, Any]			,       __lowercase     :	int=7			,       __lowercase     :	Any=3			,       __lowercase     :	Dict=18			,       __lowercase     :	Union[str, Any]=30			,       __lowercase     :	int=4_00			,       __lowercase     :	Tuple=True			,       __lowercase     :	Any=None			,       __lowercase     :	int=True			,       __lowercase     :	List[Any]=[0.5, 0.5, 0.5]			,       __lowercase     :	Union[str, Any]=[0.5, 0.5, 0.5]			,       ):






						'''simple docstring'''







						UpperCAmelCase_		    =  size if 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_normalize
						UpperCAmelCase_		    =  image_mean
						UpperCAmelCase_		    =  image_std





					def 							SCREAMING_SNAKE_CASE				(    self     :	Tuple		):






						'''simple docstring'''







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







@require_torch
@require_vision
class 	_UpperCamelCase	(							A_    ,							unittest.TestCase	):







					'''simple docstring'''

					lowerCamelCase  :  Union[str, Any]           =							ViTImageProcessor if is_vision_available() else None





					def 							SCREAMING_SNAKE_CASE				(    self     :	Dict		):






						'''simple docstring'''







						UpperCAmelCase_		    =  ViTImageProcessingTester(self		)





					@property
					def 							SCREAMING_SNAKE_CASE				(    self     :	Tuple		):






						'''simple docstring'''







						return self.image_processor_tester.prepare_image_processor_dict()





					def 							SCREAMING_SNAKE_CASE				(    self     :	Any		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.image_processing_class(**self.image_processor_dict		)
						self.assertTrue(hasattr(__lowercase			,       """image_mean"""		)		)
						self.assertTrue(hasattr(__lowercase			,       """image_std"""		)		)
						self.assertTrue(hasattr(__lowercase			,       """do_normalize"""		)		)
						self.assertTrue(hasattr(__lowercase			,       """do_resize"""		)		)
						self.assertTrue(hasattr(__lowercase			,       """size"""		)		)





					def 							SCREAMING_SNAKE_CASE				(    self     :	List[Any]		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.image_processing_class.from_dict(self.image_processor_dict		)
						self.assertEqual(image_processor.size			,       {"""height""": 18, """width""": 18}		)

						UpperCAmelCase_		    =  self.image_processing_class.from_dict(self.image_processor_dict			,       size=42		)
						self.assertEqual(image_processor.size			,       {"""height""": 42, """width""": 42}		)





					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[int]		):






						'''simple docstring'''







						pass





					def 							SCREAMING_SNAKE_CASE				(    self     :	Any		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.image_processing_class(**self.image_processor_dict		)
						# create random PIL images
						UpperCAmelCase_		    =  prepare_image_inputs(self.image_processor_tester			,       equal_resolution=__lowercase		)
						for image in image_inputs:
							self.assertIsInstance(__lowercase			,       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.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    )			,       )

						# Test batched
						UpperCAmelCase_		    =  image_processing(__lowercase			,       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.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    )			,       )





					def 							SCREAMING_SNAKE_CASE				(    self     :	List[str]		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.image_processing_class(**self.image_processor_dict		)
						# create random numpy tensors
						UpperCAmelCase_		    =  prepare_image_inputs(self.image_processor_tester			,       equal_resolution=__lowercase			,       numpify=__lowercase		)
						for image in image_inputs:
							self.assertIsInstance(__lowercase			,       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.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    )			,       )

						# Test batched
						UpperCAmelCase_		    =  image_processing(__lowercase			,       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.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    )			,       )





					def 							SCREAMING_SNAKE_CASE				(    self     :	int		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.image_processing_class(**self.image_processor_dict		)
						# create random PyTorch tensors
						UpperCAmelCase_		    =  prepare_image_inputs(self.image_processor_tester			,       equal_resolution=__lowercase			,       torchify=__lowercase		)
						for image in image_inputs:
							self.assertIsInstance(__lowercase			,       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.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    )			,       )

						# Test batched
						UpperCAmelCase_		    =  image_processing(__lowercase			,       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.size["""height"""],
						        self.image_processor_tester.size["""width"""],
						    )			,       )









def  A_(      A ):
	if not isinstance(A					,   A ):
		UpperCAmelCase_		    =  f"""Input value of [number={number}] must be an integer"""
		raise TypeError(A )
	if number < 0 or number % 2 == 1:
		return False
	UpperCAmelCase_		    =  int(number**0.5 )
	return number == number_sqrt * (number_sqrt + 1)


if __name__ == "__main__":
				import doctest

				doctest.testmod()


