"""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     ):

				def __init__(				self     ,			_lowerCamelCase     ,			_lowerCamelCase=7     ,			_lowerCamelCase=3     ,			_lowerCamelCase=18     ,			_lowerCamelCase=30     ,			_lowerCamelCase=400     ,			_lowerCamelCase=True     ,			_lowerCamelCase=None     ,			_lowerCamelCase=True     ,			_lowerCamelCase=None     ,			_lowerCamelCase=True     ,			_lowerCamelCase=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]     ,			_lowerCamelCase=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]     ,			_lowerCamelCase=True     ,			):
										lowerCamelCase__ =size if size is not None else {"shortest_edge": 20}
										lowerCamelCase__ =crop_size if crop_size is not None else {"height": 18, "width": 18}
										lowerCamelCase__ =parent
										lowerCamelCase__ =batch_size
										lowerCamelCase__ =num_channels
										lowerCamelCase__ =image_size
										lowerCamelCase__ =min_resolution
										lowerCamelCase__ =max_resolution
										lowerCamelCase__ =do_resize
										lowerCamelCase__ =size
										lowerCamelCase__ =do_center_crop
										lowerCamelCase__ =crop_size
										lowerCamelCase__ =do_normalize
										lowerCamelCase__ =image_mean
										lowerCamelCase__ =image_std
										lowerCamelCase__ =do_convert_rgb

				def 		_a     (				self				):
										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 		_a     (				self     ,			_lowerCamelCase=False     ,			_lowerCamelCase=False     ,			_lowerCamelCase=False				):
										assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

										if equal_resolution:
																lowerCamelCase__ =[]
																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:
																lowerCamelCase__ =[]
																for i in range(self.batch_size				):
																						lowerCamelCase__ ,				lowerCamelCase__ =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
																lowerCamelCase__ =[Image.fromarray(np.moveaxis(_lowerCamelCase     ,			0     ,			-1				)				) for x in image_inputs]

										if torchify:
																lowerCamelCase__ =[torch.from_numpy(_lowerCamelCase				) for x in image_inputs]

										return image_inputs






@require_torch
@require_vision
class        __UpperCAmelCase						(     __lowerCAmelCase				,				unittest.TestCase     ):
				A__				:       Optional[Any]  							=	CLIPImageProcessor if is_vision_available() else None

				def 		_a     (				self				):
										lowerCamelCase__ =CLIPImageProcessingTester(self				)

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

				def 		_a     (				self				):
										lowerCamelCase__ =self.image_processing_class(**self.image_processor_dict				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"do_resize"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"size"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"do_center_crop"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"center_crop"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"do_normalize"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"image_mean"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"image_std"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"do_convert_rgb"				)				)

				def 		_a     (				self				):
										lowerCamelCase__ =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}				)

										lowerCamelCase__ =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 		_a     (				self				):
										pass

				def 		_a     (				self				):
										# Initialize image_processing
										lowerCamelCase__ =self.image_processing_class(**self.image_processor_dict				)
										# create random PIL images
										lowerCamelCase__ =self.image_processor_tester.prepare_inputs(equal_resolution=_lowerCamelCase				)
										for image in image_inputs:
																self.assertIsInstance(_lowerCamelCase     ,			Image.Image				)

										# Test not batched input
										lowerCamelCase__ =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
										lowerCamelCase__ =image_processing(_lowerCamelCase     ,			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 		_a     (				self				):
										# Initialize image_processing
										lowerCamelCase__ =self.image_processing_class(**self.image_processor_dict				)
										# create random numpy tensors
										lowerCamelCase__ =self.image_processor_tester.prepare_inputs(equal_resolution=_lowerCamelCase     ,			numpify=_lowerCamelCase				)
										for image in image_inputs:
																self.assertIsInstance(_lowerCamelCase     ,			np.ndarray				)

										# Test not batched input
										lowerCamelCase__ =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
										lowerCamelCase__ =image_processing(_lowerCamelCase     ,			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 		_a     (				self				):
										# Initialize image_processing
										lowerCamelCase__ =self.image_processing_class(**self.image_processor_dict				)
										# create random PyTorch tensors
										lowerCamelCase__ =self.image_processor_tester.prepare_inputs(equal_resolution=_lowerCamelCase     ,			torchify=_lowerCamelCase				)
										for image in image_inputs:
																self.assertIsInstance(_lowerCamelCase     ,			torch.Tensor				)

										# Test not batched input
										lowerCamelCase__ =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
										lowerCamelCase__ =image_processing(_lowerCamelCase     ,			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						(     __lowerCAmelCase				,				unittest.TestCase     ):
				A__				:       str  							=	CLIPImageProcessor if is_vision_available() else None

				def 		_a     (				self				):
										lowerCamelCase__ =CLIPImageProcessingTester(self     ,			num_channels=4				)
										lowerCamelCase__ =3

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

				def 		_a     (				self				):
										lowerCamelCase__ =self.image_processing_class(**self.image_processor_dict				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"do_resize"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"size"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"do_center_crop"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"center_crop"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"do_normalize"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"image_mean"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"image_std"				)				)
										self.assertTrue(hasattr(_lowerCamelCase     ,			"do_convert_rgb"				)				)

				def 		_a     (				self				):
										pass






				def 		_a     (				self				):
										# Initialize image_processing
										lowerCamelCase__ =self.image_processing_class(**self.image_processor_dict				)
										# create random PIL images
										lowerCamelCase__ =self.image_processor_tester.prepare_inputs(equal_resolution=_lowerCamelCase				)
										for image in image_inputs:
																self.assertIsInstance(_lowerCamelCase     ,			Image.Image				)

										# Test not batched input
										lowerCamelCase__ =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
										lowerCamelCase__ =image_processing(_lowerCamelCase     ,			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"],
										    )     ,			)



"""simple docstring"""


from __future__ import annotations





def       lowerCamelCase_			( __lowerCAmelCase    )							-> int | float:




						'''simple docstring'''



						lowerCamelCase__ =sorted(__lowerCAmelCase    )
						lowerCamelCase__ =len(__lowerCAmelCase    )
						lowerCamelCase__ =length >> 1
						return (
						    (sorted_list[mid_index] + sorted_list[mid_index - 1]) / 2
						    if length % 2 == 0
						    else sorted_list[mid_index]
						)





def       lowerCamelCase_			( )							-> Tuple:




						'''simple docstring'''



						import doctest

						doctest.testmod()


if __name__ == "__main__":
	main()


