



"""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       A_			(     unittest.TestCase				):



						"""simple docstring"""






						def __init__(					self :Optional[Any]   ,  lowercase_ :Optional[Any]   ,  lowercase_ :List[str]=13   ,  lowercase_ :Tuple=30   ,  lowercase_ :str=2   ,  lowercase_ :Optional[int]=3   ,  lowercase_ :Dict=True   ,  lowercase_ :List[str]=True   ,  lowercase_ :str=32   ,  lowercase_ :Dict=5   ,  lowercase_ :Optional[int]=4   ,  lowercase_ :Optional[Any]=37   ,  lowercase_ :Dict="gelu"   ,  lowercase_ :int=0.1   ,  lowercase_ :int=0.1   ,  lowercase_ :Union[str, Any]=10   ,  lowercase_ :str=0.02   ,  )				->			Optional[int]:
												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 :str					)				->			List[str]:
												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=lowercase_   ,  initializer_range=self.initializer_range   ,  )

												return config, pixel_values






						def 	UpperCAmelCase__     (					self :str   ,  lowercase_ :Union[str, Any]   ,  lowercase_ :List[Any]					)				->			List[Any]:
												UpperCAmelCase             = FlaxViTModel(config=lowercase_					)
												UpperCAmelCase             = model(lowercase_					)
												# 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 :List[Any]   ,  lowercase_ :Optional[int]   ,  lowercase_ :Dict					)				->			List[Any]:
												UpperCAmelCase             = self.type_sequence_label_size
												UpperCAmelCase             = FlaxViTForImageClassification(config=lowercase_					)
												UpperCAmelCase             = model(lowercase_					)
												self.parent.assertEqual(result.logits.shape   ,  (self.batch_size, self.type_sequence_label_size)					)

												# test greyscale images
												UpperCAmelCase             = 1
												UpperCAmelCase             = FlaxViTForImageClassification(lowercase_					)

												UpperCAmelCase             = floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
												UpperCAmelCase             = model(lowercase_					)






						def 	UpperCAmelCase__     (					self :str					)				->			Optional[int]:
												UpperCAmelCase             = self.prepare_config_and_inputs()
												(
												    (
												    UpperCAmelCase
												)      ,    (
												    UpperCAmelCase
												)      ,    
												)             = config_and_inputs
												UpperCAmelCase             = {'pixel_values': pixel_values}
												return config, inputs_dict







@require_flax
class       A_			(     SCREAMING_SNAKE_CASE_	,   unittest.TestCase				):



						"""simple docstring"""
						__UpperCamelCase						=							(FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()






						def 	UpperCAmelCase__     (					self :int					)				->			None:
												UpperCAmelCase             = FlaxViTModelTester(self					)
												UpperCAmelCase             = ConfigTester(self   ,  config_class=lowercase_   ,  has_text_modality=lowercase_   ,  hidden_size=37					)






						def 	UpperCAmelCase__     (					self :Optional[Any]					)				->			Tuple:
												self.config_tester.run_common_tests()






						def 	UpperCAmelCase__     (					self :Dict					)				->			Tuple:
												UpperCAmelCase             = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*lowercase_					)






						def 	UpperCAmelCase__     (					self :str					)				->			Dict:
												UpperCAmelCase             = self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_image_classification(*lowercase_					)






						def 	UpperCAmelCase__     (					self :Any					)				->			Optional[int]:
												UpperCAmelCase      ,    UpperCAmelCase             = self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																		UpperCAmelCase             = model_class(lowercase_					)
																		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]   ,  lowercase_					)






						def 	UpperCAmelCase__     (					self :str					)				->			Optional[int]:
												UpperCAmelCase      ,    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(lowercase_   ,  lowercase_					)
																								UpperCAmelCase             = model_class(lowercase_					)

																								@jax.jit
																								def model_jitted(lowercase_ :Tuple   ,  **lowercase_ :Dict					):
																														return model(pixel_values=lowercase_   ,  **lowercase_					)

																								with self.subTest('JIT Enabled'					):
																														UpperCAmelCase             = model_jitted(**lowercase_					).to_tuple()

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

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






						@slow
						def 	UpperCAmelCase__     (					self :List[Any]					)				->			str:
												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(lowercase_					)







def    __UpperCamelCase     (				lowerCAmelCase__							:				int = 5_0_0_0_0_0_0_0  ):
 __a :  int						=  set()
 __a :  str						=  int((limit - 2_4) ** (1 / 2)  )

 __a :  int						=  set(range(3  ,   prime_square_limit + 1  ,   2  )  )
 primes.add(2  )
 for p in range(3  ,   prime_square_limit + 1  ,   2  ):
  if p not in primes:
   continue
  primes.difference_update(set(range(p * p  ,   prime_square_limit + 1  ,   lowerCAmelCase__  )  )  )

 for primea in primes:
  __a :  Union[str, Any]						=  primea * primea
  for primea in primes:
   __a :  Union[str, Any]						=  primea * primea * primea
   if square + cube >= limit - 1_6:
    break
   for primea in primes:
    __a :  int						=  primea * primea * primea * primea
    __a :  Union[str, Any]						=  square + cube + tetr
    if total >= limit:
     break
    ret.add(lowerCAmelCase__  )

 return len(lowerCAmelCase__  )


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