





"""simple docstring"""



from __future__ import annotations

import inspect
import unittest

from transformers import ViTConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
       import tensorflow as tf

       from transformers import TFViTForImageClassification, TFViTModel


if is_vision_available():
       from PIL import Image

       from transformers import ViTImageProcessor






class 						__snake_case   :





 """simple docstring"""


 def __init__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase=13   ,		__lowerCamelCase=30   ,		__lowerCamelCase=2   ,		__lowerCamelCase=3   ,		__lowerCamelCase=True   ,		__lowerCamelCase=True   ,		__lowerCamelCase=32   ,		__lowerCamelCase=2   ,		__lowerCamelCase=4   ,		__lowerCamelCase=37   ,		__lowerCamelCase="gelu"   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=10   ,		__lowerCamelCase=0.0_2   ,		__lowerCamelCase=3   ,		__lowerCamelCase=None   ,		):



     '''simple docstring'''




     __A       :		Optional[int]							=	parent
     __A       :		str							=	batch_size
     __A       :		Dict							=	image_size
     __A       :		Optional[Any]							=	patch_size
     __A       :		Optional[int]							=	num_channels
     __A       :		List[Any]							=	is_training
     __A       :		List[str]							=	use_labels
     __A       :		Optional[Any]							=	hidden_size
     __A       :		Any							=	num_hidden_layers
     __A       :		Tuple							=	num_attention_heads
     __A       :		Tuple							=	intermediate_size
     __A       :		Dict							=	hidden_act
     __A       :		Dict							=	hidden_dropout_prob
     __A       :		Any							=	attention_probs_dropout_prob
     __A       :		Any							=	type_sequence_label_size
     __A       :		str							=	initializer_range
     __A       :		int							=	scope

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

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		Tuple							=	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

     __A       :		List[Any]							=	None
     if self.use_labels:
         __A       :		Tuple							=	ids_tensor([self.batch_size]   ,		self.type_sequence_label_size    )

     __A       :		Tuple							=	self.get_config()

     return config, pixel_values, labels

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return 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=__lowerCamelCase   ,		initializer_range=self.initializer_range   ,		)

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    ):



     '''simple docstring'''




     __A       :		Dict							=	TFViTModel(config=__lowerCamelCase    )
     __A       :		int							=	model(__lowerCamelCase   ,		training=__lowerCamelCase    )
     self.parent.assertEqual(result.last_hidden_state.shape   ,		(self.batch_size, self.seq_length, self.hidden_size)    )

     # Test with an image with different size than the one specified in config.
     __A       :		int							=	self.image_size // 2
     __A       :		Any							=	pixel_values[:, :, :image_size, :image_size]
     __A       :		Optional[int]							=	model(__lowerCamelCase   ,		interpolate_pos_encoding=__lowerCamelCase   ,		training=__lowerCamelCase    )
     __A       :		Optional[Any]							=	(image_size // self.patch_size) ** 2 + 1
     self.parent.assertEqual(result.last_hidden_state.shape   ,		(self.batch_size, seq_length, self.hidden_size)    )

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    ):



     '''simple docstring'''




     __A       :		Dict							=	self.type_sequence_label_size
     __A       :		List[Any]							=	TFViTForImageClassification(__lowerCamelCase    )
     __A       :		Optional[Any]							=	model(__lowerCamelCase   ,		labels=__lowerCamelCase   ,		training=__lowerCamelCase    )
     self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.type_sequence_label_size)    )

     # Test with an image with different size than the one specified in config.
     __A       :		Any							=	self.image_size // 2
     __A       :		Union[str, Any]							=	pixel_values[:, :, :image_size, :image_size]
     __A       :		Optional[int]							=	model(__lowerCamelCase   ,		interpolate_pos_encoding=__lowerCamelCase   ,		training=__lowerCamelCase    )
     self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.type_sequence_label_size)    )

     # test greyscale images
     __A       :		str							=	1
     __A       :		List[str]							=	TFViTForImageClassification(__lowerCamelCase    )
     __A       :		Any							=	floats_tensor([self.batch_size, 1, self.image_size, self.image_size]    )
     __A       :		Dict							=	model(__lowerCamelCase    )
     self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.type_sequence_label_size)    )







 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		str							=	self.prepare_config_and_inputs()
     __A					,			__A					,			__A       :		Union[str, Any]							=	config_and_inputs
     __A       :		Optional[Any]							=	{'''pixel_values''': pixel_values}
     return config, inputs_dict






@require_tf
class 						__snake_case   (						SCREAMING_SNAKE_CASE__				,				SCREAMING_SNAKE_CASE__				,				unittest.TestCase	):





 """simple docstring"""


 _lowerCamelCase								=	(TFViTModel, TFViTForImageClassification) if is_tf_available() else ()
 _lowerCamelCase								=	(
     {"""feature-extraction""": TFViTModel, """image-classification""": TFViTForImageClassification}
     if is_tf_available()
     else {}
 )

 _lowerCamelCase								=	False
 _lowerCamelCase								=	False
 _lowerCamelCase								=	False

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		str							=	TFViTModelTester(self    )
     __A       :		int							=	ConfigTester(self   ,		config_class=__lowerCamelCase   ,		has_text_modality=__lowerCamelCase   ,		hidden_size=37    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     self.config_tester.run_common_tests()

 @unittest.skip(reason='''ViT does not use inputs_embeds'''    )
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     pass

 @unittest.skip(reason='''ViT does not use inputs_embeds'''    )
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     pass

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A					,			__A       :		str							=	self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
         __A       :		int							=	model_class(__lowerCamelCase    )
         self.assertIsInstance(model.get_input_embeddings()   ,		(tf.keras.layers.Layer)    )
         __A       :		Tuple							=	model.get_output_embeddings()
         self.assertTrue(x is None or isinstance(__lowerCamelCase   ,		tf.keras.layers.Layer    )    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A					,			__A       :		Optional[int]							=	self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
         __A       :		List[str]							=	model_class(__lowerCamelCase    )
         __A       :		Union[str, Any]							=	inspect.signature(model.call    )
         # signature.parameters is an OrderedDict => so arg_names order is deterministic
         __A       :		int							=	[*signature.parameters.keys()]

         __A       :		int							=	['''pixel_values''']
         self.assertListEqual(arg_names[:1]   ,		__lowerCamelCase    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		List[str]							=	self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*__lowerCamelCase    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		List[str]							=	self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_image_classification(*__lowerCamelCase    )







 @slow
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		str							=	TFViTModel.from_pretrained('''google/vit-base-patch16-224'''    )
     self.assertIsNotNone(__lowerCamelCase    )







def 						__lowercase	(  )  ->List[Any]:



    '''simple docstring'''







    __A       :		Optional[int]							=	Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
    return image






@require_tf
@require_vision
class 						__snake_case   (						unittest.TestCase	):





 """simple docstring"""


 @cached_property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return ViTImageProcessor.from_pretrained('''google/vit-base-patch16-224'''    ) if is_vision_available() else None







 @slow
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		str							=	TFViTForImageClassification.from_pretrained('''google/vit-base-patch16-224'''    )

     __A       :		List[Any]							=	self.default_image_processor
     __A       :		str							=	prepare_img()
     __A       :		Dict							=	image_processor(images=__lowerCamelCase   ,		return_tensors='''tf'''    )

     # forward pass
     __A       :		List[str]							=	model(**__lowerCamelCase    )

     # verify the logits
     __A       :		Any							=	tf.TensorShape((1, 1000)    )
     self.assertEqual(outputs.logits.shape   ,		__lowerCamelCase    )

     __A       :		Optional[Any]							=	tf.constant([-0.2_7_4_4, 0.8_2_1_5, -0.0_8_3_6]    )

     tf.debugging.assert_near(outputs.logits[0, :3]   ,		__lowerCamelCase   ,		atol=1e-4    )











"""simple docstring"""



def 						__lowercase	(  snake_case_    :    int		)  ->int:



    '''simple docstring'''







    __A       :		str							=	1
    for i in range(1							,num + 1		):
        fact *= i
    return fact







def 						__lowercase	(  snake_case_    :    int		)  ->int:



    '''simple docstring'''







    __A       :		str							=	0
    while number > 0:
        __A       :		Optional[int]							=	number % 10
        sum_of_digits += last_digit
        __A       :		Dict							=	number // 10  # Removing the last_digit from the given number
    return sum_of_digits







def 						__lowercase	(  snake_case_    :    int = 100		)  ->int:



    '''simple docstring'''







    __A       :		Optional[int]							=	factorial(snake_case_		)
    __A       :		Optional[Any]							=	split_and_add(snake_case_		)
    return result


if __name__ == "__main__":
       print(solution(int(input("""Enter the Number: """).strip())))




