

"""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      __a							:






     '''simple docstring'''

     def __init__(						self	,    _a	,    _a=13	,    _a=30	,    _a=2	,    _a=3	,    _a=True	,    _a=True	,    _a=32	,    _a=2	,    _a=4	,    _a=37	,    _a="gelu"	,    _a=0.1	,    _a=0.1	,    _a=10	,    _a=0.02	,    _a=3	,    _a=None	,    )  ->      Union[str, Any]:


           """simple docstring"""


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

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

     def 					_a			(						self  )  ->      int:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )

           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	None
           if self.use_labels:
                 SCREAMING_SNAKE_CASE__   :      Tuple      		=	ids_tensor([self.batch_size]	,    self.type_sequence_label_size  )

           SCREAMING_SNAKE_CASE__   :      str      		=	self.get_config()

           return config, pixel_values, labels

     def 					_a			(						self  )  ->      Dict:


           """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=_a	,    initializer_range=self.initializer_range	,    )

     def 					_a			(						self	,    _a	,    _a	,    _a  )  ->      Optional[Any]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      str      		=	TFViTModel(config=_a  )
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	model(_a	,    training=_a  )
           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.
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	self.image_size // 2
           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	pixel_values[:, :, :image_size, :image_size]
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	model(_a	,    interpolate_pos_encoding=_a	,    training=_a  )
           SCREAMING_SNAKE_CASE__   :      List[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 					_a			(						self	,    _a	,    _a	,    _a  )  ->      Tuple:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	self.type_sequence_label_size
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	TFViTForImageClassification(_a  )
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	model(_a	,    labels=_a	,    training=_a  )
           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.
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	self.image_size // 2
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	pixel_values[:, :, :image_size, :image_size]
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	model(_a	,    interpolate_pos_encoding=_a	,    training=_a  )
           self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.type_sequence_label_size)  )

           # test greyscale images
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	1
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	TFViTForImageClassification(_a  )
           SCREAMING_SNAKE_CASE__   :      int      		=	floats_tensor([self.batch_size, 1, self.image_size, self.image_size]  )
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	model(_a  )
           self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.type_sequence_label_size)  )





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


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Dict      		=	self.prepare_config_and_inputs()
           SCREAMING_SNAKE_CASE__		,		SCREAMING_SNAKE_CASE__		,		SCREAMING_SNAKE_CASE__   :      Any      		=	config_and_inputs
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	{"""pixel_values""": pixel_values}
           return config, inputs_dict





@require_tf
class      __a							(UpperCamelCase_   ,	UpperCamelCase_   ,	unittest.TestCase):






     '''simple docstring'''
     _SCREAMING_SNAKE_CASE						:List[str]       = (TFViTModel, TFViTForImageClassification) if is_tf_available() else ()
     _SCREAMING_SNAKE_CASE						:Dict       = (
         {"""feature-extraction""": TFViTModel, """image-classification""": TFViTForImageClassification}
         if is_tf_available()
         else {}
     )

     _SCREAMING_SNAKE_CASE						:int       = False
     _SCREAMING_SNAKE_CASE						:List[str]       = False
     _SCREAMING_SNAKE_CASE						:Optional[Any]       = False

     def 					_a			(						self  )  ->      Tuple:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      int      		=	TFViTModelTester(self  )
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	ConfigTester(self	,    config_class=_a	,    has_text_modality=_a	,    hidden_size=37  )

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


           """simple docstring"""


           self.config_tester.run_common_tests()

     @unittest.skip(reason="""ViT does not use inputs_embeds"""  )
     def 					_a			(						self  )  ->      Dict:


           """simple docstring"""


           pass

     @unittest.skip(reason="""ViT does not use inputs_embeds"""  )
     def 					_a			(						self  )  ->      List[str]:


           """simple docstring"""


           pass

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


           """simple docstring"""


           SCREAMING_SNAKE_CASE__		,		SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                 SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	model_class(_a  )
                 self.assertIsInstance(model.get_input_embeddings()	,    (tf.keras.layers.Layer)  )
                 SCREAMING_SNAKE_CASE__   :      Tuple      		=	model.get_output_embeddings()
                 self.assertTrue(x is None or isinstance(_a	,    tf.keras.layers.Layer  )  )

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


           """simple docstring"""


           SCREAMING_SNAKE_CASE__		,		SCREAMING_SNAKE_CASE__   :      Tuple      		=	self.model_tester.prepare_config_and_inputs_for_common()

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

                 SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	["""pixel_values"""]
                 self.assertListEqual(arg_names[:1]	,    _a  )

     def 					_a			(						self  )  ->      Dict:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*_a  )

     def 					_a			(						self  )  ->      Tuple:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Tuple      		=	self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_image_classification(*_a  )





     @slow
     def 					_a			(						self  )  ->      Tuple:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	TFViTModel.from_pretrained("""google/vit-base-patch16-224"""  )
           self.assertIsNotNone(_a  )





def  _lowercase					(    )       ->				Dict:
      SCREAMING_SNAKE_CASE__   :      Any      		=	Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
      return image



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






     '''simple docstring'''

     @cached_property
     def 					_a			(						self  )  ->      str:


           """simple docstring"""


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





     @slow
     def 					_a			(						self  )  ->      Dict:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      int      		=	TFViTForImageClassification.from_pretrained("""google/vit-base-patch16-224"""  )

           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	self.default_image_processor
           SCREAMING_SNAKE_CASE__   :      int      		=	prepare_img()
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	image_processor(images=_a	,    return_tensors="""tf"""  )

           # forward pass
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	model(**_a  )

           # verify the logits
           SCREAMING_SNAKE_CASE__   :      Dict      		=	tf.TensorShape((1, 1_000)  )
           self.assertEqual(outputs.logits.shape	,    _a  )

           SCREAMING_SNAKE_CASE__   :      Dict      		=	tf.constant([-0.2_744, 0.8_215, -0.0_836]  )

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







"""simple docstring"""


from math import sqrt




def  _lowercase					(    __lowerCAmelCase							)       ->				bool:

      if 1 < number < 4:
            # 2 and 3 are primes
            return True
      elif number < 2 or number % 2 == 0 or number % 3 == 0:
            # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
            return False

      # All primes number are in format of 6k +/- 1
      for i in range(5  ,					int(sqrt(__lowerCAmelCase							) + 1							)  ,					6							):
            if number % i == 0 or number % (i + 2) == 0:
                  return False
      return True




def  _lowercase					(    __lowerCAmelCase = 1_0001							)       ->				int:
      SCREAMING_SNAKE_CASE__   :      Dict      		=	0
      SCREAMING_SNAKE_CASE__   :      Tuple      		=	1
      while count != nth and number < 3:
            number += 1
            if is_prime(__lowerCAmelCase							):
                  count += 1
      while count != nth:
            number += 2
            if is_prime(__lowerCAmelCase							):
                  count += 1
      return number


if __name__ == "__main__":
  print(f'{solution() = }')




