


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






						'''simple docstring'''







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







						def lowerCAmelCase__ (  self:	Dict     )							->	List[str]:
										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:	List[Any]      ,							__UpperCamelCase:	Dict=False      ,							__UpperCamelCase:	Optional[Any]=False      ,							__UpperCamelCase:	Dict=False     )							->	Tuple:
										assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

										return image_inputs






@require_torch
@require_vision
class 		_snake_case    (				snake_case_  ,  unittest.TestCase		):






						'''simple docstring'''







						__snake_case   =      BlipImageProcessor if is_vision_available() else None







						def lowerCAmelCase__ (  self:	Optional[int]     )							->	str:
										__magic_name__				:					int						       =       BlipImageProcessingTester(self     )







						@property
						def lowerCAmelCase__ (  self:	Any     )							->	Tuple:
										return self.image_processor_tester.prepare_image_processor_dict()







						def lowerCAmelCase__ (  self:	Dict     )							->	List[str]:
										__magic_name__				:					Union[str, Any]						       =       self.image_processing_class(**self.image_processor_dict     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"do_resize"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"size"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"do_normalize"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"image_mean"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"image_std"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"do_convert_rgb"     )     )







						def lowerCAmelCase__ (  self:	Any     )							->	Optional[Any]:
										pass







						def lowerCAmelCase__ (  self:	Union[str, Any]     )							->	Union[str, Any]:
										# Initialize image_processor
										__magic_name__				:					Union[str, Any]						       =       self.image_processing_class(**self.image_processor_dict     )
										# create random PIL images
										__magic_name__				:					int						       =       self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase     )
										for image in image_inputs:
														self.assertIsInstance(__UpperCamelCase      ,							Image.Image     )

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

										# Test not batched input
										__magic_name__				:					Tuple						       =       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
										__magic_name__				:					str						       =       image_processor(__UpperCamelCase      ,							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:	Union[str, Any]     )							->	Tuple:
										# Initialize image_processor
										__magic_name__				:					Tuple						       =       self.image_processing_class(**self.image_processor_dict     )
										# create random PyTorch tensors
										__magic_name__				:					Optional[Any]						       =       self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase      ,							torchify=__UpperCamelCase     )
										for image in image_inputs:
														self.assertIsInstance(__UpperCamelCase      ,							torch.Tensor     )

										# Test not batched input
										__magic_name__				:					List[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
										__magic_name__				:					Union[str, Any]						       =       image_processor(__UpperCamelCase      ,							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 		_snake_case    (				snake_case_  ,  unittest.TestCase		):






						'''simple docstring'''







						__snake_case   =      BlipImageProcessor if is_vision_available() else None







						def lowerCAmelCase__ (  self:	str     )							->	Optional[int]:
										__magic_name__				:					str						       =       BlipImageProcessingTester(self      ,							num_channels=4     )
										__magic_name__				:					int						       =       3







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







						def lowerCAmelCase__ (  self:	List[Any]     )							->	Optional[int]:
										__magic_name__				:					Tuple						       =       self.image_processing_class(**self.image_processor_dict     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"do_resize"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"size"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"do_normalize"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"image_mean"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"image_std"     )     )
										self.assertTrue(hasattr(__UpperCamelCase      ,							"do_convert_rgb"     )     )







						def lowerCAmelCase__ (  self:	Any     )							->	Any:
										pass







						def lowerCAmelCase__ (  self:	List[Any]     )							->	Tuple:
										# Initialize image_processor
										__magic_name__				:					Optional[Any]						       =       self.image_processing_class(**self.image_processor_dict     )
										# create random PIL images
										__magic_name__				:					List[Any]						       =       self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase     )
										for image in image_inputs:
														self.assertIsInstance(__UpperCamelCase      ,							Image.Image     )

										# Test not batched input
										__magic_name__				:					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
										__magic_name__				:					Tuple						       =       image_processor(__UpperCamelCase      ,							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 						_UpperCamelCase							( UpperCamelCase__		):






				"""simple docstring"""



				if not isinstance(UpperCamelCase__     ,   UpperCamelCase__		) or number < 0:
								raise ValueError("Input must be a non-negative integer"		)

				__magic_name__				:					str						       =       number & ~(number - 1)
				__magic_name__				:					Optional[int]						       =       0
				while intermediate:
								intermediate >>= 1
								index += 1
				return index - 1


if __name__ == "__main__":
		import doctest

		doctest.testmod(verbose=True)