






'''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 ChineseCLIPImageProcessor





class 	SCREAMING_SNAKE_CASE					(					unittest.TestCase       ):






			def __init__( self      :			int  ,						__SCREAMING_SNAKE_CASE      :			Tuple  ,						__SCREAMING_SNAKE_CASE      :			List[str]=7  ,						__SCREAMING_SNAKE_CASE      :			int=3  ,						__SCREAMING_SNAKE_CASE      :			int=18  ,						__SCREAMING_SNAKE_CASE      :			int=30  ,						__SCREAMING_SNAKE_CASE      :			Optional[Any]=400  ,						__SCREAMING_SNAKE_CASE      :			Tuple=True  ,						__SCREAMING_SNAKE_CASE      :			Dict=None  ,						__SCREAMING_SNAKE_CASE      :			List[str]=True  ,						__SCREAMING_SNAKE_CASE      :			Dict=None  ,						__SCREAMING_SNAKE_CASE      :			Tuple=True  ,						__SCREAMING_SNAKE_CASE      :			List[Any]=[0.4814_5466, 0.457_8275, 0.4082_1073]  ,						__SCREAMING_SNAKE_CASE      :			Any=[0.2686_2954, 0.2613_0258, 0.2757_7711]  ,						__SCREAMING_SNAKE_CASE      :			Optional[int]=True  ,						)			->			str:
							a_		:  Dict											=      size if size is not None else {'''height''': 224, '''width''': 224}
							a_		:  str											=      crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
							a_		:  Dict											=      parent
							a_		:  Optional[int]											=      batch_size
							a_		:  Optional[Any]											=      num_channels
							a_		:  Optional[int]											=      image_size
							a_		:  List[Any]											=      min_resolution
							a_		:  Tuple											=      max_resolution
							a_		:  Union[str, Any]											=      do_resize
							a_		:  Tuple											=      size
							a_		:  Any											=      do_center_crop
							a_		:  Optional[int]											=      crop_size
							a_		:  Optional[int]											=      do_normalize
							a_		:  Optional[int]											=      image_mean
							a_		:  Union[str, Any]											=      image_std
							a_		:  Optional[int]											=      do_convert_rgb






			def 			SCREAMING_SNAKE_CASE      ( self      :			List[str]					)			->			List[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_convert_rgb": self.do_convert_rgb,
							}







			def 			SCREAMING_SNAKE_CASE      ( self      :			str  ,						__SCREAMING_SNAKE_CASE      :			Any=False  ,						__SCREAMING_SNAKE_CASE      :			Dict=False  ,						__SCREAMING_SNAKE_CASE      :			Any=False					)			->			Optional[Any]:
							assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

							if equal_resolution:
											a_		:  Dict											=      []
											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:
											a_		:  Optional[int]											=      []
											for i in range(self.batch_size					):
															a_				,			a_		:  Union[str, Any]											=      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
											a_		:  List[str]											=      [Image.fromarray(np.moveaxis(__SCREAMING_SNAKE_CASE  ,						0  ,						-1					)					) for x in image_inputs]

							if torchify:
											a_		:  Union[str, Any]											=      [torch.from_numpy(__SCREAMING_SNAKE_CASE					) for x in image_inputs]

							return image_inputs





@require_torch
@require_vision
class 	SCREAMING_SNAKE_CASE					(					SCREAMING_SNAKE_CASE_	,   unittest.TestCase       ):
			snake_case__  =				ChineseCLIPImageProcessor if is_vision_available() else None






			def 			SCREAMING_SNAKE_CASE      ( self      :			Optional[Any]					)			->			Union[str, Any]:
							a_		:  Dict											=      ChineseCLIPImageProcessingTester(self  ,						do_center_crop=__SCREAMING_SNAKE_CASE					)






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






			def 			SCREAMING_SNAKE_CASE      ( self      :			Dict					)			->			Any:
							a_		:  Optional[int]											=      self.image_processing_class(**self.image_processor_dict					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''do_resize'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''size'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''do_center_crop'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''center_crop'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''do_normalize'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''image_mean'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''image_std'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''do_convert_rgb'''					)					)






			def 			SCREAMING_SNAKE_CASE      ( self      :			Tuple					)			->			List[str]:
							a_		:  List[Any]											=      self.image_processing_class.from_dict(self.image_processor_dict					)
							self.assertEqual(image_processor.size  ,						{'''height''': 224, '''width''': 224}					)
							self.assertEqual(image_processor.crop_size  ,						{'''height''': 18, '''width''': 18}					)

							a_		:  Tuple											=      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 			SCREAMING_SNAKE_CASE      ( self      :			Optional[int]					)			->			List[str]:
							pass






			def 			SCREAMING_SNAKE_CASE      ( self      :			Union[str, Any]					)			->			int:
							# Initialize image_processing
							a_		:  int											=      self.image_processing_class(**self.image_processor_dict					)
							# create random PIL images
							a_		:  Dict											=      self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE					)
							for image in image_inputs:
											self.assertIsInstance(__SCREAMING_SNAKE_CASE  ,						Image.Image					)

							# Test not batched input
							a_		:  Tuple											=      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
							a_		:  List[Any]											=      image_processing(__SCREAMING_SNAKE_CASE  ,						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 			SCREAMING_SNAKE_CASE      ( self      :			int					)			->			int:
							# Initialize image_processing
							a_		:  Optional[int]											=      self.image_processing_class(**self.image_processor_dict					)
							# create random numpy tensors
							a_		:  int											=      self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE  ,						numpify=__SCREAMING_SNAKE_CASE					)
							for image in image_inputs:
											self.assertIsInstance(__SCREAMING_SNAKE_CASE  ,						np.ndarray					)

							# Test not batched input
							a_		:  str											=      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
							a_		:  int											=      image_processing(__SCREAMING_SNAKE_CASE  ,						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 			SCREAMING_SNAKE_CASE      ( self      :			List[Any]					)			->			int:
							# Initialize image_processing
							a_		:  Dict											=      self.image_processing_class(**self.image_processor_dict					)
							# create random PyTorch tensors
							a_		:  Tuple											=      self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE  ,						torchify=__SCREAMING_SNAKE_CASE					)
							for image in image_inputs:
											self.assertIsInstance(__SCREAMING_SNAKE_CASE  ,						torch.Tensor					)

							# Test not batched input
							a_		:  Optional[Any]											=      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
							a_		:  Union[str, Any]											=      image_processing(__SCREAMING_SNAKE_CASE  ,						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 	SCREAMING_SNAKE_CASE					(					SCREAMING_SNAKE_CASE_	,   unittest.TestCase       ):
			snake_case__  =				ChineseCLIPImageProcessor if is_vision_available() else None






			def 			SCREAMING_SNAKE_CASE      ( self      :			Dict					)			->			List[str]:
							a_		:  Optional[int]											=      ChineseCLIPImageProcessingTester(self  ,						num_channels=4  ,						do_center_crop=__SCREAMING_SNAKE_CASE					)
							a_		:  Union[str, Any]											=      3






			@property
			def 			SCREAMING_SNAKE_CASE      ( self      :			List[Any]					)			->			Dict:
							return self.image_processor_tester.prepare_image_processor_dict()






			def 			SCREAMING_SNAKE_CASE      ( self      :			Union[str, Any]					)			->			str:
							a_		:  Optional[Any]											=      self.image_processing_class(**self.image_processor_dict					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''do_resize'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''size'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''do_center_crop'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''center_crop'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''do_normalize'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''image_mean'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''image_std'''					)					)
							self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE  ,						'''do_convert_rgb'''					)					)






			def 			SCREAMING_SNAKE_CASE      ( self      :			str					)			->			str:
							pass







			def 			SCREAMING_SNAKE_CASE      ( self      :			List[str]					)			->			Dict:
							# Initialize image_processing
							a_		:  Optional[Any]											=      self.image_processing_class(**self.image_processor_dict					)
							# create random PIL images
							a_		:  List[str]											=      self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE					)
							for image in image_inputs:
											self.assertIsInstance(__SCREAMING_SNAKE_CASE  ,						Image.Image					)

							# Test not batched input
							a_		:  Any											=      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
							a_		:  List[Any]											=      image_processing(__SCREAMING_SNAKE_CASE  ,						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 		_UpperCAmelCase   (							__A							:   list[int]      ):
				a_		:  int											=      len(__A      ) // 2

				# choose the middle 3 elements
				a_		:  Dict											=      lst[m - 1 : m + 2]

				# if middle element is peak
				if three[1] > three[0] and three[1] > three[2]:
								return three[1]

				# if increasing, recurse on right
				elif three[0] < three[2]:
								if len(lst[:m]      ) == 2:
												m -= 1
								return peak(lst[m:]      )

				# decreasing
				else:
								if len(lst[:m]      ) == 2:
												m += 1
								return peak(lst[:m]      )


if __name__ == "__main__":
		import doctest

		doctest.testmod()




