


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    UpperCAmelCase					(       unittest.TestCase    ):




			def __init__(						self							:		Any       ,       __magic_name__							:		str       ,       __magic_name__							:		Union[str, Any]=7       ,       __magic_name__							:		List[Any]=3       ,       __magic_name__							:		Any=1_8       ,       __magic_name__							:		Dict=3_0       ,       __magic_name__							:		List[str]=4_0_0       ,       __magic_name__							:		Any=True       ,       __magic_name__							:		Dict=None       ,       __magic_name__							:		Optional[int]=True       ,       __magic_name__							:		Union[str, Any]=None       ,       __magic_name__							:		Optional[Any]=True       ,       __magic_name__							:		Union[str, Any]=[0.48_145_466, 0.4_578_275, 0.40_821_073]       ,       __magic_name__							:		Any=[0.26_862_954, 0.26_130_258, 0.27_577_711]       ,       __magic_name__							:		Union[str, Any]=True       ,       ):







						"""simple docstring"""







						UpperCamelCase         =					size if size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
						UpperCamelCase         =					crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}
						UpperCamelCase         =					parent
						UpperCamelCase         =					batch_size
						UpperCamelCase         =					num_channels
						UpperCamelCase         =					image_size
						UpperCamelCase         =					min_resolution
						UpperCamelCase         =					max_resolution
						UpperCamelCase         =					do_resize
						UpperCamelCase         =					size
						UpperCamelCase         =					do_center_crop
						UpperCamelCase         =					crop_size
						UpperCamelCase         =					do_normalize
						UpperCamelCase         =					image_mean
						UpperCamelCase         =					image_std
						UpperCamelCase         =					do_convert_rgb




			def   lowerCamelCase_					(						self							:		List[str]						):







						"""simple docstring"""







						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   lowerCamelCase_					(						self							:		int       ,       __magic_name__							:		int=False       ,       __magic_name__							:		List[str]=False       ,       __magic_name__							:		Any=False						):







						"""simple docstring"""







						assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

						if torchify:
									UpperCamelCase         =					[torch.from_numpy(__magic_name__						) for x in image_inputs]

						return image_inputs




@require_torch
@require_vision
class    UpperCAmelCase					(       __snake_case      , unittest.TestCase    ):
			lowercase						= ChineseCLIPImageProcessor if is_vision_available() else None




			def   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







						UpperCamelCase         =					ChineseCLIPImageProcessingTester(self       ,       do_center_crop=__magic_name__						)




			@property
			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						return self.image_processor_tester.prepare_image_processor_dict()




			def   lowerCamelCase_					(						self							:		Optional[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					self.image_processing_class(**self.image_processor_dict						)
						self.assertTrue(hasattr(__magic_name__       ,       """do_resize"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """size"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """do_center_crop"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """center_crop"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """do_normalize"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """image_mean"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """image_std"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """do_convert_rgb"""						)						)




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					self.image_processing_class.from_dict(self.image_processor_dict						)
						self.assertEqual(image_processor.size       ,       {"""height""": 2_2_4, """width""": 2_2_4}						)
						self.assertEqual(image_processor.crop_size       ,       {"""height""": 1_8, """width""": 1_8}						)

						UpperCamelCase         =					self.image_processing_class.from_dict(self.image_processor_dict       ,       size=4_2       ,       crop_size=8_4						)
						self.assertEqual(image_processor.size       ,       {"""shortest_edge""": 4_2}						)
						self.assertEqual(image_processor.crop_size       ,       {"""height""": 8_4, """width""": 8_4}						)




			def   lowerCamelCase_					(						self							:		List[str]						):







						"""simple docstring"""







						pass




			def   lowerCamelCase_					(						self							:		Union[str, Any]						):







						"""simple docstring"""







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

						# Test batched
						UpperCamelCase         =					image_processing(__magic_name__       ,       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   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







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

						# Test batched
						UpperCamelCase         =					image_processing(__magic_name__       ,       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   lowerCamelCase_					(						self							:		Optional[Any]						):







						"""simple docstring"""







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

						# Test batched
						UpperCamelCase         =					image_processing(__magic_name__       ,       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					(       __snake_case      , unittest.TestCase    ):
			lowercase						= ChineseCLIPImageProcessor if is_vision_available() else None




			def   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







						UpperCamelCase         =					ChineseCLIPImageProcessingTester(self       ,       num_channels=4       ,       do_center_crop=__magic_name__						)
						UpperCamelCase         =					3




			@property
			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						return self.image_processor_tester.prepare_image_processor_dict()




			def   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







						UpperCamelCase         =					self.image_processing_class(**self.image_processor_dict						)
						self.assertTrue(hasattr(__magic_name__       ,       """do_resize"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """size"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """do_center_crop"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """center_crop"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """do_normalize"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """image_mean"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """image_std"""						)						)
						self.assertTrue(hasattr(__magic_name__       ,       """do_convert_rgb"""						)						)




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						pass





			def   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						UpperCamelCase         =					self.image_processing_class(**self.image_processor_dict						)
						# create random PIL images
						UpperCamelCase         =					self.image_processor_tester.prepare_inputs(equal_resolution=__magic_name__						)
						for image in image_inputs:
									self.assertIsInstance(__magic_name__       ,       Image.Image						)

						# Test not batched input
						UpperCamelCase         =					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
						UpperCamelCase         =					image_processing(__magic_name__       ,       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 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			assert (
			    isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	) and number_of_steps > 0
			), f'number_of_steps needs to be positive integer, your input {number_of_steps}'
			if number_of_steps == 1:
						return 1
			UpperCamelCase  ,  UpperCamelCase         =					1, 1
			for _ in range(number_of_steps - 1	):
						UpperCamelCase  ,  UpperCamelCase         =					current + previous, current
			return current


if __name__ == "__main__":
			import doctest

			doctest.testmod()




