

"""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 BlipImageProcessor

class      __a (   unittest.TestCase     ):

			"""simple docstring"""

			def __init__(				self  :       Any    ,	lowercase_  :       Optional[Any]    ,	lowercase_  :       Dict=7    ,	lowercase_  :       Dict=3    ,	lowercase_  :       Any=18    ,	lowercase_  :       Optional[Any]=30    ,	lowercase_  :       Optional[int]=400    ,	lowercase_  :       Optional[int]=True    ,	lowercase_  :       Optional[int]=None    ,	lowercase_  :       Tuple=True    ,	lowercase_  :       Optional[int]=False    ,	lowercase_  :       int=[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]    ,	lowercase_  :       Tuple=[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]    ,	lowercase_  :       Tuple=True    ,	):
								UpperCamelCase__		:     Tuple								=size if size is not None else {'''height''': 20, '''width''': 20}
								UpperCamelCase__		:     Any								=parent
								UpperCamelCase__		:     List[str]								=batch_size
								UpperCamelCase__		:     List[str]								=num_channels
								UpperCamelCase__		:     int								=image_size
								UpperCamelCase__		:     List[str]								=min_resolution
								UpperCamelCase__		:     int								=max_resolution
								UpperCamelCase__		:     Dict								=do_resize
								UpperCamelCase__		:     str								=size
								UpperCamelCase__		:     List[str]								=do_normalize
								UpperCamelCase__		:     List[Any]								=image_mean
								UpperCamelCase__		:     List[str]								=image_std
								UpperCamelCase__		:     str								=do_pad
								UpperCamelCase__		:     Optional[Any]								=do_convert_rgb






			def  _lowerCAmelCase      (				self  :       Dict    ):
								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_normalize": self.do_normalize,
								    "image_mean": self.image_mean,
								    "image_std": self.image_std,
								    "do_convert_rgb": self.do_convert_rgb,
								    "do_pad": self.do_pad,
								}






			def  _lowerCAmelCase      (				self  :       Tuple    ,	lowercase_  :       Union[str, Any]=False    ,	lowercase_  :       List[str]=False    ,	lowercase_  :       str=False    ):
								assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

								if torchify:
													UpperCamelCase__		:     str								=[torch.from_numpy(lowercase_    ) for x in image_inputs]

								return image_inputs



@require_torch
@require_vision
class      __a (   snake_case__,     unittest.TestCase     ):

			"""simple docstring"""

			SCREAMING_SNAKE_CASE_      =    BlipImageProcessor if is_vision_available() else None






			def  _lowerCAmelCase      (				self  :       Tuple    ):
								UpperCamelCase__		:     Any								=BlipImageProcessingTester(self    )






			@property
			def  _lowerCAmelCase      (				self  :       Any    ):
								return self.image_processor_tester.prepare_image_processor_dict()






			def  _lowerCAmelCase      (				self  :       Union[str, Any]    ):
								UpperCamelCase__		:     Dict								=self.image_processing_class(**self.image_processor_dict    )
								self.assertTrue(hasattr(lowercase_    ,	'''do_resize'''    )    )
								self.assertTrue(hasattr(lowercase_    ,	'''size'''    )    )
								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  :       Optional[int]    ):
								pass






			def  _lowerCAmelCase      (				self  :       Dict    ):
								# Initialize image_processor
								UpperCamelCase__		:     Union[str, Any]								=self.image_processing_class(**self.image_processor_dict    )
								# create random PIL images
								UpperCamelCase__		:     Optional[Any]								=self.image_processor_tester.prepare_inputs(equal_resolution=lowercase_    )
								for image in image_inputs:
													self.assertIsInstance(lowercase_    ,	Image.Image    )

								# Test not batched input
								UpperCamelCase__		:     str								=image_processor(image_inputs[0]    ,	return_tensors='''pt'''    ).pixel_values
								self.assertEqual(
								    encoded_images.shape    ,	(
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )    ,	)

								# Test batched
								UpperCamelCase__		:     List[str]								=image_processor(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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )    ,	)






			def  _lowerCAmelCase      (				self  :       Dict    ):
								# Initialize image_processor
								UpperCamelCase__		:     Tuple								=self.image_processing_class(**self.image_processor_dict    )
								# create random numpy tensors
								UpperCamelCase__		:     Tuple								=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
								UpperCamelCase__		:     Union[str, Any]								=image_processor(image_inputs[0]    ,	return_tensors='''pt'''    ).pixel_values
								self.assertEqual(
								    encoded_images.shape    ,	(
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )    ,	)

								# Test batched
								UpperCamelCase__		:     Optional[Any]								=image_processor(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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )    ,	)






			def  _lowerCAmelCase      (				self  :       Any    ):
								# Initialize image_processor
								UpperCamelCase__		:     Tuple								=self.image_processing_class(**self.image_processor_dict    )
								# create random PyTorch tensors
								UpperCamelCase__		:     Tuple								=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
								UpperCamelCase__		:     Union[str, Any]								=image_processor(image_inputs[0]    ,	return_tensors='''pt'''    ).pixel_values
								self.assertEqual(
								    encoded_images.shape    ,	(
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )    ,	)

								# Test batched
								UpperCamelCase__		:     Dict								=image_processor(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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )    ,	)



@require_torch
@require_vision
class      __a (   snake_case__,     unittest.TestCase     ):

			"""simple docstring"""

			SCREAMING_SNAKE_CASE_      =    BlipImageProcessor if is_vision_available() else None






			def  _lowerCAmelCase      (				self  :       Tuple    ):
								UpperCamelCase__		:     Tuple								=BlipImageProcessingTester(self    ,	num_channels=4    )
								UpperCamelCase__		:     Dict								=3






			@property
			def  _lowerCAmelCase      (				self  :       str    ):
								return self.image_processor_tester.prepare_image_processor_dict()






			def  _lowerCAmelCase      (				self  :       List[str]    ):
								UpperCamelCase__		:     List[str]								=self.image_processing_class(**self.image_processor_dict    )
								self.assertTrue(hasattr(lowercase_    ,	'''do_resize'''    )    )
								self.assertTrue(hasattr(lowercase_    ,	'''size'''    )    )
								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  :       Any    ):
								pass






			def  _lowerCAmelCase      (				self  :       Tuple    ):
								# Initialize image_processor
								UpperCamelCase__		:     Dict								=self.image_processing_class(**self.image_processor_dict    )
								# create random PIL images
								UpperCamelCase__		:     Tuple								=self.image_processor_tester.prepare_inputs(equal_resolution=lowercase_    )
								for image in image_inputs:
													self.assertIsInstance(lowercase_    ,	Image.Image    )

								# Test not batched input
								UpperCamelCase__		:     List[str]								=image_processor(image_inputs[0]    ,	return_tensors='''pt'''    ).pixel_values
								self.assertEqual(
								    encoded_images.shape    ,	(
								        1,
								        self.expected_encoded_image_num_channels,
								        self.image_processor_tester.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )    ,	)

								# Test batched
								UpperCamelCase__		:     List[str]								=image_processor(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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )    ,	)





"""simple docstring"""





def 							_lowerCAmelCase   (    UpperCAmelCase  :				int					):


					'''simple docstring'''






					if not isinstance(UpperCAmelCase   ,				UpperCAmelCase					):
										raise ValueError('''double_factorial() only accepts integral values'''					)
					if n < 0:
										raise ValueError('''double_factorial() not defined for negative values'''					)
					return 1 if n <= 1 else n * double_factorial(n - 2					)


if __name__ == "__main__":
				import doctest

				doctest.testmod()


