



'''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_		:


							def __init__(				self   :						Any      ,						a_   :						int      ,						a_   :						Dict=1_3      ,						a_   :						Tuple=3_0      ,						a_   :						List[str]=2      ,						a_   :						Optional[Any]=3      ,						a_   :						Optional[int]=True      ,						a_   :						Union[str, Any]=True      ,						a_   :						Tuple=3_2      ,						a_   :						List[str]=2      ,						a_   :						Optional[Any]=4      ,						a_   :						Optional[Any]=3_7      ,						a_   :						Union[str, Any]="gelu"      ,						a_   :						Union[str, Any]=0.1      ,						a_   :						Any=0.1      ,						a_   :						Dict=1_0      ,						a_   :						Tuple=0.0_2      ,						a_   :						Dict=3      ,						a_   :						Union[str, Any]=None      ,						)			->					int:
										snake_case:    Union[str, Any]      							=parent
										snake_case:    List[str]      							=batch_size
										snake_case:    Optional[int]      							=image_size
										snake_case:    Optional[Any]      							=patch_size
										snake_case:    Dict      							=num_channels
										snake_case:    int      							=is_training
										snake_case:    Optional[int]      							=use_labels
										snake_case:    Optional[Any]      							=hidden_size
										snake_case:    int      							=num_hidden_layers
										snake_case:    Dict      							=num_attention_heads
										snake_case:    Optional[int]      							=intermediate_size
										snake_case:    Optional[Any]      							=hidden_act
										snake_case:    Tuple      							=hidden_dropout_prob
										snake_case:    List[str]      							=attention_probs_dropout_prob
										snake_case:    List[Any]      							=type_sequence_label_size
										snake_case:    Any      							=initializer_range
										snake_case:    List[str]      							=scope

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


							def    UpperCamelCase     (				self   :						List[str]			)			->					List[Any]:
										snake_case:    Any      							=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

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

										snake_case:    Optional[int]      							=self.get_config()

										return config, pixel_values, labels


							def    UpperCamelCase     (				self   :						Any			)			->					Union[str, Any]:
										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    UpperCamelCase     (				self   :						Tuple      ,						a_   :						int      ,						a_   :						int      ,						a_   :						Any			)			->					Any:
										snake_case:    Dict      							=TFViTModel(config=a_			)
										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.
										snake_case:    Any      							=self.image_size // 2
										snake_case:    Dict      							=pixel_values[:, :, :image_size, :image_size]
										snake_case:    Union[str, Any]      							=model(a_      ,						interpolate_pos_encoding=a_      ,						training=a_			)
										snake_case:    int      							=(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   :						Optional[int]      ,						a_   :						Tuple      ,						a_   :						Union[str, Any]      ,						a_   :						Union[str, Any]			)			->					Any:
										snake_case:    Optional[int]      							=self.type_sequence_label_size
										snake_case:    Optional[int]      							=TFViTForImageClassification(a_			)
										snake_case:    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.
										snake_case:    Optional[Any]      							=self.image_size // 2
										snake_case:    List[str]      							=pixel_values[:, :, :image_size, :image_size]
										snake_case:    str      							=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
										snake_case:    List[Any]      							=1
										snake_case:    Dict      							=TFViTForImageClassification(a_			)
										snake_case:    Optional[int]      							=floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
										snake_case:    Union[str, Any]      							=model(a_			)
										self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.type_sequence_label_size)			)




							def    UpperCamelCase     (				self   :						Dict			)			->					Union[str, Any]:
										snake_case:    Dict      							=self.prepare_config_and_inputs()
										snake_case							,  snake_case							,  snake_case:    int      							=config_and_inputs
										snake_case:    str      							={'pixel_values': pixel_values}
										return config, inputs_dict






@require_tf
class 						a_		(     snake_case    ,   snake_case    ,   unittest.TestCase    ):
							UpperCAmelCase			:		int        =				(TFViTModel, TFViTForImageClassification) if is_tf_available() else ()
							UpperCAmelCase			:		Optional[int]        =				(
							    {"""feature-extraction""": TFViTModel, """image-classification""": TFViTForImageClassification}
							    if is_tf_available()
							    else {}
							)

							UpperCAmelCase			:		Optional[Any]        =				False
							UpperCAmelCase			:		List[Any]        =				False
							UpperCAmelCase			:		Optional[Any]        =				False


							def    UpperCamelCase     (				self   :						List[str]			)			->					List[str]:
										snake_case:    List[str]      							=TFViTModelTester(self			)
										snake_case:    Any      							=ConfigTester(self      ,						config_class=a_      ,						has_text_modality=a_      ,						hidden_size=3_7			)


							def    UpperCamelCase     (				self   :						int			)			->					str:
										self.config_tester.run_common_tests()


							@unittest.skip(reason='ViT does not use inputs_embeds'			)
							def    UpperCamelCase     (				self   :						str			)			->					List[Any]:
										pass


							@unittest.skip(reason='ViT does not use inputs_embeds'			)
							def    UpperCamelCase     (				self   :						Dict			)			->					Dict:
										pass


							def    UpperCamelCase     (				self   :						Any			)			->					Tuple:
										snake_case							,  snake_case:    Union[str, Any]      							=self.model_tester.prepare_config_and_inputs_for_common()

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


							def    UpperCamelCase     (				self   :						Union[str, Any]			)			->					List[Any]:
										snake_case							,  snake_case:    Optional[int]      							=self.model_tester.prepare_config_and_inputs_for_common()

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

													snake_case:    Tuple      							=['pixel_values']
													self.assertListEqual(arg_names[:1]      ,						a_			)


							def    UpperCamelCase     (				self   :						Optional[int]			)			->					Optional[int]:
										snake_case:    List[Any]      							=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*a_			)


							def    UpperCamelCase     (				self   :						int			)			->					Dict:
										snake_case:    List[str]      							=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*a_			)




							@slow
							def    UpperCamelCase     (				self   :						List[Any]			)			->					Optional[Any]:
										snake_case:    Dict      							=TFViTModel.from_pretrained('google/vit-base-patch16-224'			)
										self.assertIsNotNone(a_			)







def a_     (    )				->					List[Any]:





			"""simple docstring"""







			snake_case:    int      							=Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'					)
			return image







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


							@cached_property
							def    UpperCamelCase     (				self   :						Dict			)			->					List[str]:
										return ViTImageProcessor.from_pretrained('google/vit-base-patch16-224'			) if is_vision_available() else None




							@slow
							def    UpperCamelCase     (				self   :						List[str]			)			->					List[Any]:
										snake_case:    Dict      							=TFViTForImageClassification.from_pretrained('google/vit-base-patch16-224'			)

										snake_case:    str      							=self.default_image_processor
										snake_case:    int      							=prepare_img()
										snake_case:    Tuple      							=image_processor(images=a_      ,						return_tensors='tf'			)

										# forward pass
										snake_case:    Tuple      							=model(**a_			)

										# verify the logits
										snake_case:    List[Any]      							=tf.TensorShape((1, 1_0_0_0)			)
										self.assertEqual(outputs.logits.shape      ,						a_			)

										snake_case:    Tuple      							=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]      ,						a_      ,						atol=1E-4			)









'''simple docstring'''

from __future__ import annotations







def a_     (    __UpperCAmelCase					)				->					list[int]:





			"""simple docstring"""







			snake_case:    Tuple      							=[True] * limit
			snake_case:    Optional[int]      							=False
			snake_case:    Union[str, Any]      							=False
			snake_case:    List[Any]      							=True

			for i in range(3				,							int(limit**0.5 + 1					)				,							2					):
						snake_case:    str      							=i * 2
						while index < limit:
									snake_case:    List[Any]      							=False
									snake_case:    List[str]      							=index + i

			snake_case:    Union[str, Any]      							=[2]

			for i in range(3				,							__UpperCAmelCase				,							2					):
						if is_prime[i]:
									primes.append(__UpperCAmelCase					)

			return primes







def a_     (    __UpperCAmelCase = 1_00_00_00					)				->					int:





			"""simple docstring"""







			snake_case:    str      							=prime_sieve(__UpperCAmelCase					)
			snake_case:    str      							=0
			snake_case:    str      							=0

			for i in range(len(__UpperCAmelCase					)					):
						for j in range(i + length				,							len(__UpperCAmelCase					)					):
									snake_case:    Tuple      							=sum(primes[i:j]					)
									if sol >= ceiling:
												break

									if sol in primes:
												snake_case:    List[str]      							=j - i
												snake_case:    Optional[int]      							=sol

			return largest


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




