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


				'''simple docstring'''






				def __init__(						self		,     lowercase		,     lowercase=7		,     lowercase=3		,     lowercase=1_8		,     lowercase=3_0		,     lowercase=4_0_0		,     lowercase=True		,     lowercase=None		,     lowercase=True		,     lowercase=None		,     lowercase=True		,     lowercase=[0.4814_5466, 0.457_8275, 0.4082_1073]		,     lowercase=[0.2686_2954, 0.2613_0258, 0.2757_7711]		,     lowercase=True		,     ):



							"""simple docstring"""





							A_		:    Union[str, Any]         =				size if size is not None else {'height': 2_2_4, 'width': 2_2_4}
							A_		:    Dict         =				crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}
							A_		:    Optional[Any]         =				parent
							A_		:    Optional[Any]         =				batch_size
							A_		:    Any         =				num_channels
							A_		:    List[Any]         =				image_size
							A_		:    Optional[int]         =				min_resolution
							A_		:    Dict         =				max_resolution
							A_		:    int         =				do_resize
							A_		:    int         =				size
							A_		:    Dict         =				do_center_crop
							A_		:    int         =				crop_size
							A_		:    Union[str, Any]         =				do_normalize
							A_		:    Optional[Any]         =				image_mean
							A_		:    str         =				image_std
							A_		:    str         =				do_convert_rgb
				def   lowerCAmelCase_       (						self ):



							"""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		,     lowercase=False		,     lowercase=False		,     lowercase=False ):



							"""simple docstring"""





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

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

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

							return image_inputs





@require_torch
@require_vision
class UpperCAmelCase						( __A ,	unittest.TestCase  ):


				'''simple docstring'''






				lowerCamelCase_    = ChineseCLIPImageProcessor if is_vision_available() else None
				def   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							A_		:    Any         =				ChineseCLIPImageProcessingTester(self		,     do_center_crop=lowercase )
				@property
				def   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							return self.image_processor_tester.prepare_image_processor_dict()
				def   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							A_		:    Tuple         =				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   lowerCAmelCase_       (						self ):



							"""simple docstring"""





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

							A_		:    List[str]         =				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 ):



							"""simple docstring"""





							pass
				def   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							A_		:    Tuple         =				self.image_processing_class(**self.image_processor_dict )
							# create random PIL images
							A_		:    List[Any]         =				self.image_processor_tester.prepare_inputs(equal_resolution=lowercase )
							for image in image_inputs:
										self.assertIsInstance(lowercase		,     Image.Image )

							# 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_		:    Optional[Any]         =				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   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							A_		:    Optional[Any]         =				self.image_processing_class(**self.image_processor_dict )
							# create random numpy tensors
							A_		:    List[str]         =				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
							A_		:    Dict         =				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_		:    Dict         =				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   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							A_		:    List[Any]         =				self.image_processing_class(**self.image_processor_dict )
							# create random PyTorch tensors
							A_		:    Dict         =				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
							A_		:    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_		:    Dict         =				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						( __A ,	unittest.TestCase  ):


				'''simple docstring'''






				lowerCamelCase_    = ChineseCLIPImageProcessor if is_vision_available() else None
				def   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							A_		:    Optional[Any]         =				ChineseCLIPImageProcessingTester(self		,     num_channels=4		,     do_center_crop=lowercase )
							A_		:    Optional[Any]         =				3
				@property
				def   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							return self.image_processor_tester.prepare_image_processor_dict()
				def   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							A_		:    int         =				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   lowerCAmelCase_       (						self ):



							"""simple docstring"""





							pass







				def   lowerCAmelCase_       (						self ):



							"""simple docstring"""





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

							# Test not batched input
							A_		:    List[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_		:    str         =				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'],
							    )		,     )







from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_UpperCAmelCase            =		{
    """configuration_autoformer""": [
        """AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """AutoformerConfig""",
    ],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_UpperCAmelCase            =		[
	    """AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """AutoformerForPrediction""",
	    """AutoformerModel""",
	    """AutoformerPreTrainedModel""",
	]


if TYPE_CHECKING:
	from .configuration_autoformer import (
	    AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    AutoformerConfig,
	)

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_autoformer import (
		    AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    AutoformerForPrediction,
		    AutoformerModel,
		    AutoformerPreTrainedModel,
		)

else:
	import sys

	_UpperCAmelCase            =		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






