
'''simple docstring'''
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers.testing_utils import require_vision
from transformers.utils import is_vision_available


if is_vision_available():
						from PIL import Image

						from transformers import AutoProcessor, BertTokenizer, CLIPImageProcessor, GitProcessor, PreTrainedTokenizerFast






@require_vision
class      snake_case__    (	unittest.TestCase ):







		"""simple docstring"""

		def 	lowerCAmelCase							(	self							:       Union[str, Any]	)		->       Dict:






				"""simple docstring"""







				snake_case   :    Optional[Any]			       =		tempfile.mkdtemp()

				snake_case   :    Optional[Any]			       =		CLIPImageProcessor()
				snake_case   :    Optional[int]			       =		BertTokenizer.from_pretrained(
				    '''hf-internal-testing/tiny-random-BertModel'''   ,     model_input_names=['''input_ids''', '''attention_mask''']	)

				snake_case   :    Any			       =		GitProcessor(UpperCamelCase__   ,     UpperCamelCase__	)

				processor.save_pretrained(self.tmpdirname	)



		def 	lowerCAmelCase							(	self							:       List[str]   ,     **UpperCamelCase__							:       List[Any]	)		->       Any:






				"""simple docstring"""







				return AutoProcessor.from_pretrained(self.tmpdirname   ,     **UpperCamelCase__	).tokenizer



		def 	lowerCAmelCase							(	self							:       Optional[int]   ,     **UpperCamelCase__							:       Tuple	)		->       List[Any]:






				"""simple docstring"""







				return AutoProcessor.from_pretrained(self.tmpdirname   ,     **UpperCamelCase__	).image_processor



		def 	lowerCAmelCase							(	self							:       int	)		->       Any:






				"""simple docstring"""







				shutil.rmtree(self.tmpdirname	)



		def 	lowerCAmelCase							(	self							:       str	)		->       str:






				"""simple docstring"""







				snake_case   :    Optional[Any]			       =		[np.random.randint(255   ,     size=(3, 30, 400)   ,     dtype=np.uinta	)]

				snake_case   :    Union[str, Any]			       =		[Image.fromarray(np.moveaxis(UpperCamelCase__   ,     0   ,     -1	)	) for x in image_inputs]

				return image_inputs



		def 	lowerCAmelCase							(	self							:       List[Any]	)		->       Optional[int]:






				"""simple docstring"""







				snake_case   :    List[str]			       =		GitProcessor(tokenizer=self.get_tokenizer()   ,     image_processor=self.get_image_processor()	)
				processor.save_pretrained(self.tmpdirname	)

				snake_case   :    Union[str, Any]			       =		self.get_tokenizer(bos_token='''(BOS)'''   ,     eos_token='''(EOS)'''	)
				snake_case   :    Optional[int]			       =		self.get_image_processor(do_normalize=UpperCamelCase__   ,     padding_value=1.0	)

				snake_case   :    Union[str, Any]			       =		GitProcessor.from_pretrained(
				    self.tmpdirname   ,     bos_token='''(BOS)'''   ,     eos_token='''(EOS)'''   ,     do_normalize=UpperCamelCase__   ,     padding_value=1.0	)

				self.assertEqual(processor.tokenizer.get_vocab()   ,     tokenizer_add_kwargs.get_vocab()	)
				self.assertIsInstance(processor.tokenizer   ,     UpperCamelCase__	)

				self.assertEqual(processor.image_processor.to_json_string()   ,     image_processor_add_kwargs.to_json_string()	)
				self.assertIsInstance(processor.image_processor   ,     UpperCamelCase__	)



		def 	lowerCAmelCase							(	self							:       Optional[Any]	)		->       Optional[int]:






				"""simple docstring"""







				snake_case   :    str			       =		self.get_image_processor()
				snake_case   :    Optional[int]			       =		self.get_tokenizer()

				snake_case   :    Optional[Any]			       =		GitProcessor(tokenizer=UpperCamelCase__   ,     image_processor=UpperCamelCase__	)

				snake_case   :    Any			       =		self.prepare_image_inputs()

				snake_case   :    Optional[Any]			       =		image_processor(UpperCamelCase__   ,     return_tensors='''np'''	)
				snake_case   :    Dict			       =		processor(images=UpperCamelCase__   ,     return_tensors='''np'''	)

				for key in input_feat_extract.keys():
						self.assertAlmostEqual(input_feat_extract[key].sum()   ,     input_processor[key].sum()   ,     delta=1e-2	)



		def 	lowerCAmelCase							(	self							:       List[str]	)		->       List[str]:






				"""simple docstring"""







				snake_case   :    str			       =		self.get_image_processor()
				snake_case   :    Tuple			       =		self.get_tokenizer()

				snake_case   :    Optional[int]			       =		GitProcessor(tokenizer=UpperCamelCase__   ,     image_processor=UpperCamelCase__	)

				snake_case   :    List[str]			       =		'''lower newer'''

				snake_case   :    str			       =		processor(text=UpperCamelCase__	)

				snake_case   :    Optional[Any]			       =		tokenizer(UpperCamelCase__   ,     return_token_type_ids=UpperCamelCase__	)

				for key in encoded_tok.keys():
						self.assertListEqual(encoded_tok[key]   ,     encoded_processor[key]	)



		def 	lowerCAmelCase							(	self							:       int	)		->       str:






				"""simple docstring"""







				snake_case   :    List[Any]			       =		self.get_image_processor()
				snake_case   :    Tuple			       =		self.get_tokenizer()

				snake_case   :    Optional[Any]			       =		GitProcessor(tokenizer=UpperCamelCase__   ,     image_processor=UpperCamelCase__	)

				snake_case   :    Dict			       =		'''lower newer'''
				snake_case   :    Any			       =		self.prepare_image_inputs()

				snake_case   :    str			       =		processor(text=UpperCamelCase__   ,     images=UpperCamelCase__	)

				self.assertListEqual(list(inputs.keys()	)   ,     ['''input_ids''', '''attention_mask''', '''pixel_values''']	)

				# test if it raises when no input is passed
				with pytest.raises(UpperCamelCase__	):
						processor()



		def 	lowerCAmelCase							(	self							:       Optional[Any]	)		->       Optional[Any]:






				"""simple docstring"""







				snake_case   :    Tuple			       =		self.get_image_processor()
				snake_case   :    Any			       =		self.get_tokenizer()

				snake_case   :    str			       =		GitProcessor(tokenizer=UpperCamelCase__   ,     image_processor=UpperCamelCase__	)

				snake_case   :    int			       =		[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

				snake_case   :    int			       =		processor.batch_decode(UpperCamelCase__	)
				snake_case   :    int			       =		tokenizer.batch_decode(UpperCamelCase__	)

				self.assertListEqual(UpperCamelCase__   ,     UpperCamelCase__	)



		def 	lowerCAmelCase							(	self							:       List[Any]	)		->       List[Any]:






				"""simple docstring"""







				snake_case   :    str			       =		self.get_image_processor()
				snake_case   :    Dict			       =		self.get_tokenizer()

				snake_case   :    Optional[Any]			       =		GitProcessor(tokenizer=UpperCamelCase__   ,     image_processor=UpperCamelCase__	)

				snake_case   :    List[str]			       =		'''lower newer'''
				snake_case   :    Any			       =		self.prepare_image_inputs()

				snake_case   :    Tuple			       =		processor(text=UpperCamelCase__   ,     images=UpperCamelCase__	)

				# For now the processor supports only ['input_ids', 'attention_mask', 'pixel_values']
				self.assertListEqual(list(inputs.keys()	)   ,     ['''input_ids''', '''attention_mask''', '''pixel_values''']	)




'''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())


