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

						def __init__(	self				:      Any							,							__lowerCamelCase				:      Optional[int]							,							__lowerCamelCase				:      Any=7							,							__lowerCamelCase				:      Optional[Any]=3							,							__lowerCamelCase				:      Union[str, Any]=18							,							__lowerCamelCase				:      Dict=30							,							__lowerCamelCase				:      Optional[Any]=4_00							,							__lowerCamelCase				:      Union[str, Any]=True							,							__lowerCamelCase				:      str=None							,							__lowerCamelCase				:      Union[str, Any]=True							,							__lowerCamelCase				:      List[str]=None							,							__lowerCamelCase				:      Dict=True							,							__lowerCamelCase				:      Dict=[0.4814_5466, 0.457_8275, 0.4082_1073]							,							__lowerCamelCase				:      Dict=[0.2686_2954, 0.2613_0258, 0.2757_7711]							,							__lowerCamelCase				:      int=True							,							)							->		Any:


									'''simple docstring'''

									lowercase							=		size if size is not None else {'''height''': 2_24, '''width''': 2_24}
									lowercase							=		crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
									lowercase							=		parent
									lowercase							=		batch_size
									lowercase							=		num_channels
									lowercase							=		image_size
									lowercase							=		min_resolution
									lowercase							=		max_resolution
									lowercase							=		do_resize
									lowercase							=		size
									lowercase							=		do_center_crop
									lowercase							=		crop_size
									lowercase							=		do_normalize
									lowercase							=		image_mean
									lowercase							=		image_std
									lowercase							=		do_convert_rgb

						def        __a		(	self				:      Tuple   )							->		Any:


									'''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        __a		(	self				:      Union[str, Any]							,							__lowerCamelCase				:      Tuple=False							,							__lowerCamelCase				:      Optional[int]=False							,							__lowerCamelCase				:      Dict=False   )							->		Tuple:


									'''simple docstring'''

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

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

									if torchify:
												lowercase							=		[torch.from_numpy(__lowerCamelCase   ) for x in image_inputs]

									return image_inputs






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

						def        __a		(	self				:      int   )							->		Union[str, Any]:


									'''simple docstring'''

									lowercase							=		ChineseCLIPImageProcessingTester(self							,							do_center_crop=__lowerCamelCase   )

						@property
						def        __a		(	self				:      Optional[Any]   )							->		Optional[Any]:


									'''simple docstring'''

									return self.image_processor_tester.prepare_image_processor_dict()

						def        __a		(	self				:      Dict   )							->		Optional[Any]:


									'''simple docstring'''

									lowercase							=		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				:      int   )							->		str:


									'''simple docstring'''

									lowercase							=		self.image_processing_class.from_dict(self.image_processor_dict   )
									self.assertEqual(image_processor.size							,							{'''height''': 2_24, '''width''': 2_24}   )
									self.assertEqual(image_processor.crop_size							,							{'''height''': 18, '''width''': 18}   )

									lowercase							=		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				:      Any   )							->		str:


									'''simple docstring'''

									pass

						def        __a		(	self				:      int   )							->		Tuple:


									'''simple docstring'''

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

									# Test not batched input
									lowercase							=		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
									lowercase							=		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				:      Optional[int]   )							->		str:


									'''simple docstring'''

									lowercase							=		self.image_processing_class(**self.image_processor_dict   )
									# create random numpy tensors
									lowercase							=		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
									lowercase							=		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
									lowercase							=		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				:      Optional[Any]   )							->		Optional[int]:


									'''simple docstring'''

									lowercase							=		self.image_processing_class(**self.image_processor_dict   )
									# create random PyTorch tensors
									lowercase							=		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
									lowercase							=		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
									lowercase							=		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      __lowercase					(    _A       ,     unittest.TestCase    ):
						lowercase					 =     ChineseCLIPImageProcessor if is_vision_available() else None

						def        __a		(	self				:      Tuple   )							->		int:


									'''simple docstring'''

									lowercase							=		ChineseCLIPImageProcessingTester(self							,							num_channels=4							,							do_center_crop=__lowerCamelCase   )
									lowercase							=		3

						@property
						def        __a		(	self				:      Optional[int]   )							->		Optional[int]:


									'''simple docstring'''

									return self.image_processor_tester.prepare_image_processor_dict()

						def        __a		(	self				:      Dict   )							->		Optional[int]:


									'''simple docstring'''

									lowercase							=		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				:      int   )							->		Union[str, Any]:


									'''simple docstring'''

									pass



						def        __a		(	self				:      Optional[int]   )							->		List[Any]:


									'''simple docstring'''

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

									# Test not batched input
									lowercase							=		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
									lowercase							=		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'''],
									    )							,							)






# Lint as: python3
import dataclasses
import re
from dataclasses import dataclass
from functools import total_ordering
from typing import Optional, Union


A_      =      re.compile(R"^(?P<major>\d+)" R"\.(?P<minor>\d+)" R"\.(?P<patch>\d+)$")






@total_ordering
@dataclass
class      __lowercase					:
						lowercase					 =     42
						lowercase					 =     None
						lowercase					 =     None
						lowercase					 =     None
						lowercase					 =     None

						def        __a		(	self				:      int   )							->		str:


									'''simple docstring'''

									lowercase		,lowercase		,lowercase							=		_str_to_version_tuple(self.version_str   )

						def __repr__(	self				:      Union[str, Any]   )							->		int:


									'''simple docstring'''

									return f'{self.tuple[0]}.{self.tuple[1]}.{self.tuple[2]}'

						@property
						def        __a		(	self				:      Dict   )							->		Union[str, Any]:


									'''simple docstring'''

									return self.major, self.minor, self.patch

						def        __a		(	self				:      Optional[Any]							,							__lowerCamelCase				:      Any   )							->		Dict:


									'''simple docstring'''

									if isinstance(__lowerCamelCase							,							__lowerCamelCase   ):
												return Version(__lowerCamelCase   )
									elif isinstance(__lowerCamelCase							,							__lowerCamelCase   ):
												return other
									raise TypeError(f'{other} (type {type(__lowerCamelCase   )}) cannot be compared to version.'   )

						def __eq__(	self				:      Tuple							,							__lowerCamelCase				:      Tuple   )							->		List[Any]:


									'''simple docstring'''

									try:
												lowercase							=		self._validate_operand(__lowerCamelCase   )
									except (TypeError, ValueError):
												return False
									else:
												return self.tuple == other.tuple

						def __lt__(	self				:      Any							,							__lowerCamelCase				:      Union[str, Any]   )							->		int:


									'''simple docstring'''

									lowercase							=		self._validate_operand(__lowerCamelCase   )
									return self.tuple < other.tuple

						def __hash__(	self				:      int   )							->		str:


									'''simple docstring'''

									return hash(_version_tuple_to_str(self.tuple   )   )

						@classmethod
						def        __a		(	cls				:      List[str]							,							__lowerCamelCase				:      Any   )							->		int:


									'''simple docstring'''

									lowercase							=		{f.name for f in dataclasses.fields(cls   )}
									return cls(**{k: v for k, v in dic.items() if k in field_names}   )



						def        __a		(	self				:      Union[str, Any]   )							->		str:


									'''simple docstring'''

									return self.version_str






def        __UpperCAmelCase    (       UpperCAmelCase       )->       List[str]:



			"""simple docstring"""







			lowercase							=		_VERSION_REG.match(UpperCAmelCase       )
			if not res:
						raise ValueError(f'Invalid version \'{version_str}\'. Format should be x.y.z with {{x,y,z}} being digits.'       )
			return tuple(int(UpperCAmelCase       ) for v in [res.group('''major'''       ), res.group('''minor'''       ), res.group('''patch'''       )]       )






def        __UpperCAmelCase    (       UpperCAmelCase       )->       int:



			"""simple docstring"""







			return ".".join(str(UpperCAmelCase       ) for v in version_tuple       )





