
"""simple docstring"""





import inspect
import unittest

import numpy as np

from transformers import ViTConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
				import jax

				from transformers.models.vit.modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel






class        _UpperCAmelCase(       unittest.TestCase      ):



		def __init__(   self							,						__a							,						__a=13							,						__a=30							,						__a=2							,						__a=3							,						__a=True							,						__a=True							,						__a=32							,						__a=5							,						__a=4							,						__a=37							,						__a="gelu"							,						__a=0.1							,						__a=0.1							,						__a=10							,						__a=0.02							,						)			->			List[Any]:






							'''simple docstring'''
							_UpperCamelCase									=    parent
							_UpperCamelCase									=    batch_size
							_UpperCamelCase									=    image_size
							_UpperCamelCase									=    patch_size
							_UpperCamelCase									=    num_channels
							_UpperCamelCase									=    is_training
							_UpperCamelCase									=    use_labels
							_UpperCamelCase									=    hidden_size
							_UpperCamelCase									=    num_hidden_layers
							_UpperCamelCase									=    num_attention_heads
							_UpperCamelCase									=    intermediate_size
							_UpperCamelCase									=    hidden_act
							_UpperCamelCase									=    hidden_dropout_prob
							_UpperCamelCase									=    attention_probs_dropout_prob
							_UpperCamelCase									=    type_sequence_label_size
							_UpperCamelCase									=    initializer_range

							# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
							_UpperCamelCase									=    (image_size // patch_size) ** 2
							_UpperCamelCase									=    num_patches + 1



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






							'''simple docstring'''
							_UpperCamelCase									=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

							_UpperCamelCase									=    ViTConfig(
							    image_size=self.image_size							,						patch_size=self.patch_size							,						num_channels=self.num_channels							,						hidden_size=self.hidden_size							,						num_hidden_layers=self.num_hidden_layers							,						num_attention_heads=self.num_attention_heads							,						intermediate_size=self.intermediate_size							,						hidden_act=self.hidden_act							,						hidden_dropout_prob=self.hidden_dropout_prob							,						attention_probs_dropout_prob=self.attention_probs_dropout_prob							,						is_decoder=A__							,						initializer_range=self.initializer_range							,						)

							return config, pixel_values



		def 		UpperCAmelCase				(   self							,						__a							,						__a)			->			Dict:






							'''simple docstring'''
							_UpperCamelCase									=    FlaxViTModel(config=A__)
							_UpperCamelCase									=    model(A__)
							# expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
							_UpperCamelCase									=    (self.image_size, self.image_size)
							_UpperCamelCase									=    (self.patch_size, self.patch_size)
							_UpperCamelCase									=    (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
							self.parent.assertEqual(result.last_hidden_state.shape							,						(self.batch_size, num_patches + 1, self.hidden_size))



		def 		UpperCAmelCase				(   self							,						__a							,						__a)			->			Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase									=    self.type_sequence_label_size
							_UpperCamelCase									=    FlaxViTForImageClassification(config=A__)
							_UpperCamelCase									=    model(A__)
							self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.type_sequence_label_size))

							# test greyscale images
							_UpperCamelCase									=    1
							_UpperCamelCase									=    FlaxViTForImageClassification(A__)

							_UpperCamelCase									=    floats_tensor([self.batch_size, 1, self.image_size, self.image_size])
							_UpperCamelCase									=    model(A__)




		def 		UpperCAmelCase				(   self)			->			str:






							'''simple docstring'''
							_UpperCamelCase									=    self.prepare_config_and_inputs()
							(
							    _UpperCamelCase				
							)									=    config_and_inputs
							_UpperCamelCase									=    {'''pixel_values''': pixel_values}
							return config, inputs_dict






@require_flax
class        _UpperCAmelCase(       __snake_case ,	unittest.TestCase      ):
		lowercase__         = (FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()



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






							'''simple docstring'''
							_UpperCamelCase									=    FlaxViTModelTester(self)
							_UpperCamelCase									=    ConfigTester(self							,						config_class=A__							,						has_text_modality=A__							,						hidden_size=37)



		def 		UpperCAmelCase				(   self)			->			Dict:






							'''simple docstring'''
							self.config_tester.run_common_tests()



		def 		UpperCAmelCase				(   self)			->			Any:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*A__)



		def 		UpperCAmelCase				(   self)			->			Optional[int]:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*A__)



		def 		UpperCAmelCase				(   self)			->			Tuple:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												_UpperCamelCase									=    model_class(A__)
												_UpperCamelCase									=    inspect.signature(model.__call__)
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												_UpperCamelCase									=    [*signature.parameters.keys()]

												_UpperCamelCase									=    ['''pixel_values''']
												self.assertListEqual(arg_names[:1]							,						A__)



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






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												with self.subTest(model_class.__name__):
																	_UpperCamelCase									=    self._prepare_for_class(A__							,						A__)
																	_UpperCamelCase									=    model_class(A__)

																	@jax.jit
																	def model_jitted(__a							,						**__a):
																						return model(pixel_values=A__							,						**A__)

																	with self.subTest('''JIT Enabled'''):
																						_UpperCamelCase									=    model_jitted(**A__).to_tuple()

																	with self.subTest('''JIT Disabled'''):
																						with jax.disable_jit():
																											_UpperCamelCase									=    model_jitted(**A__).to_tuple()

																	self.assertEqual(len(A__)							,						len(A__))
																	for jitted_output, output in zip(A__							,						A__):
																						self.assertEqual(jitted_output.shape							,						output.shape)




		@slow
		def 		UpperCAmelCase				(   self)			->			Union[str, Any]:






							'''simple docstring'''
							for model_class_name in self.all_model_classes:
												_UpperCamelCase									=    model_class_name.from_pretrained('''google/vit-base-patch16-224''')
												_UpperCamelCase									=    model(np.ones((1, 3, 2_24, 2_24)))
												self.assertIsNotNone(A__)














def  a__ (__lowercase							:int					,  __lowercase							:int   )		-> int:
				return abs(__lowercase   ) if a == 0 else greatest_common_divisor(b % a					,  __lowercase   )



def  a__ (__lowercase							:int					,  __lowercase							:int   )		-> int:
				while y:  # --> when y=0 then loop will terminate and return x as final GCD.
								_A  ,				_A	:				Union[str, Any]   =      y, x % y
				return abs(__lowercase   )



def  a__ ()		-> Optional[Any]:
				try:
								_A	:				Optional[Any]   =      input('''Enter two integers separated by comma (,): '''   ).split(''','''   )
								_A	:				List[Any]   =      int(nums[0]   )
								_A	:				Optional[int]   =      int(nums[1]   )
								print(
								    f"""greatest_common_divisor({num_a}, {num_a}) = """
								    f"""{greatest_common_divisor(__lowercase					,  __lowercase   )}"""   )
								print(f"""By iterative gcd({num_a}, {num_a}) = {gcd_by_iterative(__lowercase					,  __lowercase   )}"""   )
				except (IndexError, UnboundLocalError, ValueError):
								print('''Wrong input'''   )


if __name__ == "__main__":
	main()



