


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 CLIPImageProcessor







class      __lowercase  (unittest.TestCase   ):





							"""simple docstring"""







							def __init__(	self       ,		lowerCAmelCase__       ,		lowerCAmelCase__=7       ,		lowerCAmelCase__=3       ,		lowerCAmelCase__=1_8       ,		lowerCAmelCase__=3_0       ,		lowerCAmelCase__=4_0_0       ,		lowerCAmelCase__=True       ,		lowerCAmelCase__=None       ,		lowerCAmelCase__=True       ,		lowerCAmelCase__=None       ,		lowerCAmelCase__=True       ,		lowerCAmelCase__=[0.48_145_466, 0.4_578_275, 0.40_821_073]       ,		lowerCAmelCase__=[0.26_862_954, 0.26_130_258, 0.27_577_711]       ,		lowerCAmelCase__=True       ,		):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			List[str]       						= size if size is not None else {'''shortest_edge''': 2_0}
										SCREAMING_SNAKE_CASE_						:			int       						= crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}
										SCREAMING_SNAKE_CASE_						:			Optional[int]       						= parent
										SCREAMING_SNAKE_CASE_						:			Optional[Any]       						= batch_size
										SCREAMING_SNAKE_CASE_						:			str       						= num_channels
										SCREAMING_SNAKE_CASE_						:			Tuple       						= image_size
										SCREAMING_SNAKE_CASE_						:			Optional[int]       						= min_resolution
										SCREAMING_SNAKE_CASE_						:			List[str]       						= max_resolution
										SCREAMING_SNAKE_CASE_						:			Optional[Any]       						= do_resize
										SCREAMING_SNAKE_CASE_						:			List[Any]       						= size
										SCREAMING_SNAKE_CASE_						:			int       						= do_center_crop
										SCREAMING_SNAKE_CASE_						:			str       						= crop_size
										SCREAMING_SNAKE_CASE_						:			Optional[int]       						= do_normalize
										SCREAMING_SNAKE_CASE_						:			Union[str, Any]       						= image_mean
										SCREAMING_SNAKE_CASE_						:			Tuple       						= image_std
										SCREAMING_SNAKE_CASE_						:			Any       						= do_convert_rgb






							def  UpperCamelCase__			(	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  UpperCamelCase__			(	self       ,		lowerCAmelCase__=False       ,		lowerCAmelCase__=False       ,		lowerCAmelCase__=False    ):





										"""simple docstring"""




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

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

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

										return image_inputs







@require_torch
@require_vision
class      __lowercase  (__SCREAMING_SNAKE_CASE     ,    unittest.TestCase   ):





							"""simple docstring"""







							_UpperCAmelCase     =		CLIPImageProcessor if is_vision_available() else None






							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			Any       						= CLIPImageProcessingTester(self    )






							@property
							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										return self.image_processor_tester.prepare_image_processor_dict()






							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			str       						= self.image_processing_class(**self.image_processor_dict    )
										self.assertTrue(hasattr(UpperCamelCase__       ,		'do_resize'    )    )
										self.assertTrue(hasattr(UpperCamelCase__       ,		'size'    )    )
										self.assertTrue(hasattr(UpperCamelCase__       ,		'do_center_crop'    )    )
										self.assertTrue(hasattr(UpperCamelCase__       ,		'center_crop'    )    )
										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  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			Dict       						= self.image_processing_class.from_dict(self.image_processor_dict    )
										self.assertEqual(image_processor.size       ,		{'shortest_edge': 2_0}    )
										self.assertEqual(image_processor.crop_size       ,		{'height': 1_8, 'width': 1_8}    )

										SCREAMING_SNAKE_CASE_						:			Any       						= 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  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										pass






							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




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

										# Test not batched input
										SCREAMING_SNAKE_CASE_						:			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
										SCREAMING_SNAKE_CASE_						:			Optional[Any]       						= image_processing(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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )       ,		)






							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			str       						= self.image_processing_class(**self.image_processor_dict    )
										# create random numpy tensors
										SCREAMING_SNAKE_CASE_						:			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
										SCREAMING_SNAKE_CASE_						:			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
										SCREAMING_SNAKE_CASE_						:			List[str]       						= image_processing(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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )       ,		)






							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			List[Any]       						= self.image_processing_class(**self.image_processor_dict    )
										# create random PyTorch tensors
										SCREAMING_SNAKE_CASE_						:			int       						= 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
										SCREAMING_SNAKE_CASE_						:			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
										SCREAMING_SNAKE_CASE_						:			Dict       						= image_processing(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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )       ,		)







@require_torch
@require_vision
class      __lowercase  (__SCREAMING_SNAKE_CASE     ,    unittest.TestCase   ):





							"""simple docstring"""







							_UpperCAmelCase     =		CLIPImageProcessor if is_vision_available() else None






							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			Optional[Any]       						= CLIPImageProcessingTester(self       ,		num_channels=4    )
										SCREAMING_SNAKE_CASE_						:			Optional[Any]       						= 3






							@property
							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										return self.image_processor_tester.prepare_image_processor_dict()






							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			List[str]       						= self.image_processing_class(**self.image_processor_dict    )
										self.assertTrue(hasattr(UpperCamelCase__       ,		'do_resize'    )    )
										self.assertTrue(hasattr(UpperCamelCase__       ,		'size'    )    )
										self.assertTrue(hasattr(UpperCamelCase__       ,		'do_center_crop'    )    )
										self.assertTrue(hasattr(UpperCamelCase__       ,		'center_crop'    )    )
										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  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										pass






							def  UpperCamelCase__			(	self    ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_						:			Optional[Any]       						= self.image_processing_class(**self.image_processor_dict    )
										# create random PIL images
										SCREAMING_SNAKE_CASE_						:			Any       						= self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__    )
										for image in image_inputs:
													self.assertIsInstance(UpperCamelCase__       ,		Image.Image    )

										# Test not batched input
										SCREAMING_SNAKE_CASE_						:			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
										SCREAMING_SNAKE_CASE_						:			Dict       						= image_processing(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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )       ,		)







'''simple docstring'''
from __future__ import annotations

import sys




def 					_UpperCamelCase		(    SCREAMING_SNAKE_CASE__      ,    SCREAMING_SNAKE_CASE__       )   ->				tuple[int, int]:


		'''simple docstring'''


		if abs(SCREAMING_SNAKE_CASE__       ) == 1:
				return a, 0
		elif abs(SCREAMING_SNAKE_CASE__       ) == 1:
				return 0, b

		snake_case       ,snake_case   :    Tuple			       =		a, b
		snake_case       ,snake_case   :    List[str]			       =		1, 0
		snake_case       ,snake_case   :    Optional[Any]			       =		0, 1

		while remainder != 0:
				snake_case   :    int			       =		old_remainder // remainder
				snake_case       ,snake_case   :    Tuple			       =		remainder, old_remainder - quotient * remainder
				snake_case       ,snake_case   :    Optional[Any]			       =		coeff_a, old_coeff_a - quotient * coeff_a
				snake_case       ,snake_case   :    Dict			       =		coeff_b, old_coeff_b - quotient * coeff_b

		# sign correction for negative numbers
		if a < 0:
				snake_case   :    Optional[Any]			       =		-old_coeff_a
		if b < 0:
				snake_case   :    int			       =		-old_coeff_b

		return old_coeff_a, old_coeff_b




def 					_UpperCamelCase		(    )   ->				str:


		'''simple docstring'''


		if len(sys.argv       ) < 3:
				print('''2 integer arguments required'''       )
				return 1
		snake_case   :    str			       =		int(sys.argv[1]       )
		snake_case   :    List[str]			       =		int(sys.argv[2]       )
		print(extended_euclidean_algorithm(SCREAMING_SNAKE_CASE__      ,    SCREAMING_SNAKE_CASE__       )       )
		return 0


if __name__ == "__main__":
						raise SystemExit(main())


