






"""simple docstring"""




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 CLIPImageProcessor




class 			UpperCamelCase_				(      unittest.TestCase    ):



	'''simple docstring'''




	def __init__(	self	,      a	,      a=7	,      a=3	,      a=18	,      a=30	,      a=4_00	,      a=True	,      a=None	,      a=True	,      a=None	,      a=True	,      a=[0.48_145_466, 0.4_578_275, 0.40_821_073]	,      a=[0.26_862_954, 0.26_130_258, 0.27_577_711]	,      a=True	,      )	->   str:
								snake_case_           =							size if size is not None else {'shortest_edge': 20}
								snake_case_           =							crop_size if crop_size is not None else {'height': 18, 'width': 18}
								snake_case_           =							parent
								snake_case_           =							batch_size
								snake_case_           =							num_channels
								snake_case_           =							image_size
								snake_case_           =							min_resolution
								snake_case_           =							max_resolution
								snake_case_           =							do_resize
								snake_case_           =							size
								snake_case_           =							do_center_crop
								snake_case_           =							crop_size
								snake_case_           =							do_normalize
								snake_case_           =							image_mean
								snake_case_           =							image_std
								snake_case_           =							do_convert_rgb




	def 							_UpperCamelCase      (	self )	->   Tuple:
								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_convert_rgb": self.do_convert_rgb,
								}






	def 							_UpperCamelCase      (	self	,      a=False	,      a=False	,      a=False )	->   Tuple:
								assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

								if torchify:
															snake_case_           =							[torch.from_numpy(lowercase_ ) for x in image_inputs]

								return image_inputs






@require_torch
@require_vision
class 			UpperCamelCase_				(      UpperCamelCase_	, unittest.TestCase    ):



	'''simple docstring'''




	lowerCAmelCase													=			CLIPImageProcessor if is_vision_available() else None




	def 							_UpperCamelCase      (	self )	->   Dict:
								snake_case_           =							CLIPImageProcessingTester(self )




	@property
	def 							_UpperCamelCase      (	self )	->   Dict:
								return self.image_processor_tester.prepare_image_processor_dict()




	def 							_UpperCamelCase      (	self )	->   str:
								snake_case_           =							self.image_processing_class(**self.image_processor_dict )
								self.assertTrue(hasattr(lowercase_	,      'do_resize' ) )
								self.assertTrue(hasattr(lowercase_	,      'size' ) )
								self.assertTrue(hasattr(lowercase_	,      'do_center_crop' ) )
								self.assertTrue(hasattr(lowercase_	,      'center_crop' ) )
								self.assertTrue(hasattr(lowercase_	,      'do_normalize' ) )
								self.assertTrue(hasattr(lowercase_	,      'image_mean' ) )
								self.assertTrue(hasattr(lowercase_	,      'image_std' ) )
								self.assertTrue(hasattr(lowercase_	,      'do_convert_rgb' ) )




	def 							_UpperCamelCase      (	self )	->   Tuple:
								snake_case_           =							self.image_processing_class.from_dict(self.image_processor_dict )
								self.assertEqual(image_processor.size	,      {'shortest_edge': 20} )
								self.assertEqual(image_processor.crop_size	,      {'height': 18, 'width': 18} )

								snake_case_           =							self.image_processing_class.from_dict(self.image_processor_dict	,      size=42	,      crop_size=84 )
								self.assertEqual(image_processor.size	,      {'shortest_edge': 42} )
								self.assertEqual(image_processor.crop_size	,      {'height': 84, 'width': 84} )




	def 							_UpperCamelCase      (	self )	->   Optional[Any]:
								pass




	def 							_UpperCamelCase      (	self )	->   Union[str, Any]:
								snake_case_           =							self.image_processing_class(**self.image_processor_dict )
								# create random PIL images
								snake_case_           =							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase_ )
								for image in image_inputs:
															self.assertIsInstance(lowercase_	,      Image.Image )

								# Test not batched input
								snake_case_           =							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
								snake_case_           =							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.crop_size['height'],
								        self.image_processor_tester.crop_size['width'],
								    )	,      )




	def 							_UpperCamelCase      (	self )	->   Optional[int]:
								snake_case_           =							self.image_processing_class(**self.image_processor_dict )
								# create random numpy tensors
								snake_case_           =							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase_	,      numpify=lowercase_ )
								for image in image_inputs:
															self.assertIsInstance(lowercase_	,      np.ndarray )

								# Test not batched input
								snake_case_           =							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
								snake_case_           =							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.crop_size['height'],
								        self.image_processor_tester.crop_size['width'],
								    )	,      )






	def 							_UpperCamelCase      (	self )	->   Tuple:
								snake_case_           =							self.image_processing_class(**self.image_processor_dict )
								# create random PyTorch tensors
								snake_case_           =							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase_	,      torchify=lowercase_ )
								for image in image_inputs:
															self.assertIsInstance(lowercase_	,      torch.Tensor )

								# Test not batched input
								snake_case_           =							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
								snake_case_           =							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.crop_size['height'],
								        self.image_processor_tester.crop_size['width'],
								    )	,      )






@require_torch
@require_vision
class 			UpperCamelCase_				(      UpperCamelCase_	, unittest.TestCase    ):



	'''simple docstring'''




	lowerCAmelCase													=			CLIPImageProcessor if is_vision_available() else None




	def 							_UpperCamelCase      (	self )	->   str:
								snake_case_           =							CLIPImageProcessingTester(self	,      num_channels=4 )
								snake_case_           =							3




	@property
	def 							_UpperCamelCase      (	self )	->   Tuple:
								return self.image_processor_tester.prepare_image_processor_dict()




	def 							_UpperCamelCase      (	self )	->   Any:
								snake_case_           =							self.image_processing_class(**self.image_processor_dict )
								self.assertTrue(hasattr(lowercase_	,      'do_resize' ) )
								self.assertTrue(hasattr(lowercase_	,      'size' ) )
								self.assertTrue(hasattr(lowercase_	,      'do_center_crop' ) )
								self.assertTrue(hasattr(lowercase_	,      'center_crop' ) )
								self.assertTrue(hasattr(lowercase_	,      'do_normalize' ) )
								self.assertTrue(hasattr(lowercase_	,      'image_mean' ) )
								self.assertTrue(hasattr(lowercase_	,      'image_std' ) )
								self.assertTrue(hasattr(lowercase_	,      'do_convert_rgb' ) )




	def 							_UpperCamelCase      (	self )	->   Optional[int]:
								pass






	def 							_UpperCamelCase      (	self )	->   Any:
								snake_case_           =							self.image_processing_class(**self.image_processor_dict )
								# create random PIL images
								snake_case_           =							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase_ )
								for image in image_inputs:
															self.assertIsInstance(lowercase_	,      Image.Image )

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

								# Test batched
								snake_case_           =							image_processing(lowercase_	,      return_tensors='pt' ).pixel_values
								self.assertEqual(
								    encoded_images.shape	,      (
								        self.image_processor_tester.batch_size,
								        self.expected_encoded_image_num_channels,
								        self.image_processor_tester.crop_size['height'],
								        self.image_processor_tester.crop_size['width'],
								    )	,      )













def 						__UpperCAmelCase      (					a_):
							return 1 if input_a == 0 else 0





def 						__UpperCAmelCase      (					):
							assert not_gate(0) == 1
							assert not_gate(1) == 0


if __name__ == "__main__":
	print(not_gate(0))
	print(not_gate(1))





