

"""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, prepare_image_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import OwlViTImageProcessor

class      __a (   unittest.TestCase     ):

			"""simple docstring"""

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






			def  _lowerCAmelCase      (				self  :       Dict    ):
								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,
								}



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

			"""simple docstring"""

			SCREAMING_SNAKE_CASE_      =    OwlViTImageProcessor if is_vision_available() else None






			def  _lowerCAmelCase      (				self  :       List[Any]    ):
								UpperCamelCase__		:     Any								=OwlViTImageProcessingTester(self    )






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






			def  _lowerCAmelCase      (				self  :       Optional[int]    ):
								UpperCamelCase__		:     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  :       Tuple    ):
								UpperCamelCase__		:     Any								=self.image_processing_class.from_dict(self.image_processor_dict    )
								self.assertEqual(image_processor.size    ,	{'''height''': 18, '''width''': 18}    )
								self.assertEqual(image_processor.crop_size    ,	{'''height''': 18, '''width''': 18}    )

								UpperCamelCase__		:     int								=self.image_processing_class.from_dict(self.image_processor_dict    ,	size=42    ,	crop_size=84    )
								self.assertEqual(image_processor.size    ,	{'''height''': 42, '''width''': 42}    )
								self.assertEqual(image_processor.crop_size    ,	{'''height''': 84, '''width''': 84}    )






			def  _lowerCAmelCase      (				self  :       Any    ):
								# Initialize image_processing
								UpperCamelCase__		:     int								=self.image_processing_class(**self.image_processor_dict    )
								# create random PIL images
								UpperCamelCase__		:     Tuple								=prepare_image_inputs(self.image_processor_tester    ,	equal_resolution=lowercase_    )

								for image in image_inputs:
													self.assertIsInstance(lowercase_    ,	Image.Image    )

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

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

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





"""simple docstring"""





def 							_lowerCAmelCase   (    UpperCAmelCase  :				int   ,				UpperCAmelCase  :				int   ,				UpperCAmelCase  :				int					):


					'''simple docstring'''






					if power < 0:
										return -1
					base %= mod
					UpperCamelCase__		:     Any								=1

					while power > 0:
										if power & 1:
															UpperCamelCase__		:     Optional[Any]								=(result * base) % mod
										UpperCamelCase__		:     Union[str, Any]								=power >> 1
										UpperCamelCase__		:     Union[str, Any]								=(base * base) % mod

					return result



def 							_lowerCAmelCase   (    ):


					'''simple docstring'''






					print(modular_exponential(3   ,				200   ,				13					)					)


if __name__ == "__main__":
				import doctest

				doctest.testmod()

				main()


