

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

import inspect
import unittest

import numpy as np

from transformers import DeiTConfig
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 (
					    TFDeiTForImageClassification,
					    TFDeiTForImageClassificationWithTeacher,
					    TFDeiTForMaskedImageModeling,
					    TFDeiTModel,
					)
					from transformers.models.deit.modeling_tf_deit import TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import DeiTImageProcessor
class 					_snake_case		:






			def __init__(  self			,_snake_case			,_snake_case=13			,_snake_case=30			,_snake_case=2			,_snake_case=3			,_snake_case=True			,_snake_case=True			,_snake_case=32			,_snake_case=2			,_snake_case=4			,_snake_case=37			,_snake_case="gelu"			,_snake_case=0.1			,_snake_case=0.1			,_snake_case=10			,_snake_case=0.02			,_snake_case=3			,_snake_case=None			,_snake_case=2			,):
				UpperCAmelCase_     :      Any						=  parent
				UpperCAmelCase_     :      int						=  batch_size
				UpperCAmelCase_     :      Optional[Any]						=  image_size
				UpperCAmelCase_     :      List[Any]						=  patch_size
				UpperCAmelCase_     :      Optional[int]						=  num_channels
				UpperCAmelCase_     :      Dict						=  is_training
				UpperCAmelCase_     :      Optional[int]						=  use_labels
				UpperCAmelCase_     :      List[Any]						=  hidden_size
				UpperCAmelCase_     :      int						=  num_hidden_layers
				UpperCAmelCase_     :      Tuple						=  num_attention_heads
				UpperCAmelCase_     :      Optional[int]						=  intermediate_size
				UpperCAmelCase_     :      List[Any]						=  hidden_act
				UpperCAmelCase_     :      Union[str, Any]						=  hidden_dropout_prob
				UpperCAmelCase_     :      List[str]						=  attention_probs_dropout_prob
				UpperCAmelCase_     :      List[Any]						=  type_sequence_label_size
				UpperCAmelCase_     :      Any						=  initializer_range
				UpperCAmelCase_     :      Dict						=  scope
				UpperCAmelCase_     :      Optional[int]						=  encoder_stride

				# in DeiT, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distilation tokens)
				UpperCAmelCase_     :      Union[str, Any]						=  (image_size // patch_size) ** 2
				UpperCAmelCase_     :      Any						=  num_patches + 2






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Optional[Any]						=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

				UpperCAmelCase_     :      Optional[int]						=  None
				if self.use_labels:
					UpperCAmelCase_     :      Dict						=  ids_tensor([self.batch_size]			,self.type_sequence_label_size     )

				UpperCAmelCase_     :      Dict						=  self.get_config()

				return config, pixel_values, labels






			def 		UpperCamelCase__							(  self     ):
				return DeiTConfig(
				    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=_snake_case			,initializer_range=self.initializer_range			,encoder_stride=self.encoder_stride			,)






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      Union[str, Any]						=  TFDeiTModel(config=_snake_case     )
				UpperCAmelCase_     :      Dict						=  model(_snake_case     )
				self.parent.assertEqual(result.last_hidden_state.shape			,(self.batch_size, self.seq_length, self.hidden_size)     )






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      Any						=  TFDeiTForMaskedImageModeling(config=_snake_case     )
				UpperCAmelCase_     :      Tuple						=  model(_snake_case     )
				self.parent.assertEqual(
				    result.reconstruction.shape			,(self.batch_size, self.num_channels, self.image_size, self.image_size)     )

				# test greyscale images
				UpperCAmelCase_     :      int						=  1
				UpperCAmelCase_     :      Union[str, Any]						=  TFDeiTForMaskedImageModeling(_snake_case     )

				UpperCAmelCase_     :      Tuple						=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
				UpperCAmelCase_     :      Tuple						=  model(_snake_case     )
				self.parent.assertEqual(result.reconstruction.shape			,(self.batch_size, 1, self.image_size, self.image_size)     )






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case     ):
				UpperCAmelCase_     :      Dict						=  self.type_sequence_label_size
				UpperCAmelCase_     :      Dict						=  TFDeiTForImageClassification(_snake_case     )
				UpperCAmelCase_     :      List[Any]						=  model(_snake_case			,labels=_snake_case     )
				self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.type_sequence_label_size)     )

				# test greyscale images
				UpperCAmelCase_     :      List[Any]						=  1
				UpperCAmelCase_     :      Union[str, Any]						=  TFDeiTForImageClassification(_snake_case     )

				UpperCAmelCase_     :      Tuple						=  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
				UpperCAmelCase_     :      Any						=  model(_snake_case			,labels=_snake_case     )
				self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.type_sequence_label_size)     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      str						=  self.prepare_config_and_inputs()
				UpperCAmelCase_					,					UpperCAmelCase_					,					UpperCAmelCase_     :      int						=  config_and_inputs
				UpperCAmelCase_     :      str						=  {"pixel_values": pixel_values}
				return config, inputs_dict




@require_tf
class 					_snake_case		(__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE			,			unittest.TestCase):
			__A  :	str        =(
			    (
			        TFDeiTModel,
			        TFDeiTForImageClassification,
			        TFDeiTForImageClassificationWithTeacher,
			        TFDeiTForMaskedImageModeling,
			    )
			    if is_tf_available()
			    else ()
			)
			__A  :	Union[str, Any]        =(
			    {
			        "feature-extraction": TFDeiTModel,
			        "image-classification": (TFDeiTForImageClassification, TFDeiTForImageClassificationWithTeacher),
			    }
			    if is_tf_available()
			    else {}
			)

			__A  :	Any        =False
			__A  :	Dict        =False
			__A  :	Tuple        =False
			__A  :	List[str]        =False






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      List[str]						=  TFDeiTModelTester(self     )
				UpperCAmelCase_     :      Any						=  ConfigTester(self			,config_class=_snake_case			,has_text_modality=_snake_case			,hidden_size=37     )






			def 		UpperCamelCase__							(  self     ):
				self.config_tester.run_common_tests()






			@unittest.skip(reason="DeiT does not use inputs_embeds"     )
			def 		UpperCamelCase__							(  self     ):
				pass






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_					,					UpperCAmelCase_     :      int						=  self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
					UpperCAmelCase_     :      Optional[int]						=  model_class(_snake_case     )
					self.assertIsInstance(model.get_input_embeddings()			,(tf.keras.layers.Layer)     )
					UpperCAmelCase_     :      Optional[Any]						=  model.get_output_embeddings()
					self.assertTrue(x is None or isinstance(_snake_case			,tf.keras.layers.Dense     )     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_					,					UpperCAmelCase_     :      Dict						=  self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
					UpperCAmelCase_     :      List[Any]						=  model_class(_snake_case     )
					UpperCAmelCase_     :      List[Any]						=  inspect.signature(model.call     )
					# signature.parameters is an OrderedDict => so arg_names order is deterministic
					UpperCAmelCase_     :      Tuple						=  [*signature.parameters.keys()]

					UpperCAmelCase_     :      Tuple						=  ["pixel_values"]
					self.assertListEqual(arg_names[:1]			,_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Any						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Any						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_image_modeling(*_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Dict						=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*_snake_case     )






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case=False     ):
				UpperCAmelCase_     :      Union[str, Any]						=  super()._prepare_for_class(_snake_case			,_snake_case			,return_labels=_snake_case     )

				if return_labels:
					if "labels" in inputs_dict and "labels" not in inspect.signature(model_class.call     ).parameters:
						del inputs_dict["labels"]

				return inputs_dict






			@slow
			def 		UpperCamelCase__							(  self     ):
				for model_name in TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					UpperCAmelCase_     :      str						=  TFDeiTModel.from_pretrained(_snake_case     )
					self.assertIsNotNone(_snake_case     )




def  a__       (    )     ->					Optional[int]:


	"""simple docstring"""





	UpperCAmelCase_     :      Optional[Any]						=  Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
	return image





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






			@cached_property
			def 		UpperCamelCase__							(  self     ):
				return (
				    DeiTImageProcessor.from_pretrained("facebook/deit-base-distilled-patch16-224"     )
				    if is_vision_available()
				    else None
				)






			@slow
			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Any						=  TFDeiTForImageClassificationWithTeacher.from_pretrained("facebook/deit-base-distilled-patch16-224"     )

				UpperCAmelCase_     :      Any						=  self.default_image_processor
				UpperCAmelCase_     :      List[str]						=  prepare_img()
				UpperCAmelCase_     :      Tuple						=  image_processor(images=_snake_case			,return_tensors="tf"     )

				# forward pass
				UpperCAmelCase_     :      List[str]						=  model(**_snake_case     )

				# verify the logits
				UpperCAmelCase_     :      List[Any]						=  tf.TensorShape((1, 10_00)     )
				self.assertEqual(outputs.logits.shape			,_snake_case     )

				UpperCAmelCase_     :      str						=  tf.constant([-1.0266, 0.1912, -1.2861]     )

				self.assertTrue(np.allclose(outputs.logits[0, :3]			,_snake_case			,atol=1E-4     )     )






'''simple docstring'''





def snake_case_     (					lowercase__		):
  return sum(i for i in range(1   ,       number // 2 + 1		) if number % i == 0		) == number


if __name__ == "__main__":
      print("""Program to check whether a number is a Perfect number or not...""")
      SCREAMING_SNAKE_CASE     =       int(input("""Enter number: """).strip())
      print(F'{number} is {"" if perfect(number) else "not "}a Perfect Number.')



