


'''simple docstring'''






import inspect
import unittest
from math import floor

from transformers import CvtConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import CvtForImageClassification, CvtModel
							from transformers.models.cvt.modeling_cvt import CVT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor
class 						__UpperCamelCase	(						lowercase__							):





							def 		a__   (  self		:Optional[int]			):
									snake_case_		:							Union[str, Any]			       =						self.config_class(**self.inputs_dict			)
									self.parent.assertTrue(hasattr(_UpperCamelCase  ,"""embed_dim"""			)			)
									self.parent.assertTrue(hasattr(_UpperCamelCase  ,"""num_heads"""			)			)





class 						__UpperCamelCase	:





							def __init__(  self		:str  ,_UpperCamelCase		:int  ,_UpperCamelCase		:Tuple=1_3  ,_UpperCamelCase		:Optional[Any]=6_4  ,_UpperCamelCase		:int=3  ,_UpperCamelCase		:Optional[Any]=[1_6, 4_8, 9_6]  ,_UpperCamelCase		:int=[1, 3, 6]  ,_UpperCamelCase		:Dict=[1, 2, 1_0]  ,_UpperCamelCase		:int=[7, 3, 3]  ,_UpperCamelCase		:Tuple=[4, 2, 2]  ,_UpperCamelCase		:Dict=[2, 1, 1]  ,_UpperCamelCase		:Optional[Any]=[2, 2, 2]  ,_UpperCamelCase		:Optional[Any]=[False, False, True]  ,_UpperCamelCase		:Optional[int]=[0.0, 0.0, 0.0]  ,_UpperCamelCase		:List[str]=0.02  ,_UpperCamelCase		:str=1E-1_2  ,_UpperCamelCase		:Dict=True  ,_UpperCamelCase		:Tuple=True  ,_UpperCamelCase		:Any=2  ,):
									snake_case_		:							Dict			       =						parent
									snake_case_		:							str			       =						batch_size
									snake_case_		:							List[str]			       =						image_size
									snake_case_		:							int			       =						patch_sizes
									snake_case_		:							Union[str, Any]			       =						patch_stride
									snake_case_		:							Tuple			       =						patch_padding
									snake_case_		:							int			       =						is_training
									snake_case_		:							Union[str, Any]			       =						use_labels
									snake_case_		:							Any			       =						num_labels
									snake_case_		:							Optional[int]			       =						num_channels
									snake_case_		:							Tuple			       =						embed_dim
									snake_case_		:							str			       =						num_heads
									snake_case_		:							str			       =						stride_kv
									snake_case_		:							List[Any]			       =						depth
									snake_case_		:							List[Any]			       =						cls_token
									snake_case_		:							str			       =						attention_drop_rate
									snake_case_		:							List[str]			       =						initializer_range
									snake_case_		:							Any			       =						layer_norm_eps





							def 		a__   (  self		:Any			):
									snake_case_		:							Optional[int]			       =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

									snake_case_		:							Union[str, Any]			       =						None
									if self.use_labels:
											snake_case_		:							str			       =						ids_tensor([self.batch_size]  ,self.num_labels			)

									snake_case_		:							Dict			       =						self.get_config()
									return config, pixel_values, labels





							def 		a__   (  self		:str			):
									return CvtConfig(
									    image_size=self.image_size  ,num_labels=self.num_labels  ,num_channels=self.num_channels  ,embed_dim=self.embed_dim  ,num_heads=self.num_heads  ,patch_sizes=self.patch_sizes  ,patch_padding=self.patch_padding  ,patch_stride=self.patch_stride  ,stride_kv=self.stride_kv  ,depth=self.depth  ,cls_token=self.cls_token  ,attention_drop_rate=self.attention_drop_rate  ,initializer_range=self.initializer_range  ,)





							def 		a__   (  self		:Any  ,_UpperCamelCase		:int  ,_UpperCamelCase		:Tuple  ,_UpperCamelCase		:Tuple			):
									snake_case_		:							Optional[int]			       =						CvtModel(config=_UpperCamelCase			)
									model.to(_UpperCamelCase			)
									model.eval()
									snake_case_		:							List[str]			       =						model(_UpperCamelCase			)
									snake_case_		:							Any			       =						(self.image_size, self.image_size)
									snake_case_       ,      snake_case_		:							Optional[int]			       =						image_size[0], image_size[1]
									for i in range(len(self.depth			)			):
											snake_case_		:							Any			       =						floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1			)
											snake_case_		:							List[str]			       =						floor(((width + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1			)
									self.parent.assertEqual(result.last_hidden_state.shape  ,(self.batch_size, self.embed_dim[-1], height, width)			)





							def 		a__   (  self		:str  ,_UpperCamelCase		:List[str]  ,_UpperCamelCase		:Any  ,_UpperCamelCase		:List[str]			):
									snake_case_		:							Union[str, Any]			       =						self.num_labels
									snake_case_		:							str			       =						CvtForImageClassification(_UpperCamelCase			)
									model.to(_UpperCamelCase			)
									model.eval()
									snake_case_		:							Dict			       =						model(_UpperCamelCase  ,labels=_UpperCamelCase			)
									self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.num_labels)			)





							def 		a__   (  self		:Union[str, Any]			):
									snake_case_		:							str			       =						self.prepare_config_and_inputs()
									snake_case_       ,      snake_case_       ,      snake_case_		:							Optional[int]			       =						config_and_inputs
									snake_case_		:							int			       =						{"""pixel_values""": pixel_values}
									return config, inputs_dict





@require_torch
class 						__UpperCamelCase	(						lowercase__						,  lowercase__						,  unittest.TestCase							):
							lowercase			:		Tuple   		=  (CvtModel, CvtForImageClassification) if is_torch_available() else ()
							lowercase			:		Tuple   		=  (
							    {'feature-extraction': CvtModel, 'image-classification': CvtForImageClassification}
							    if is_torch_available()
							    else {}
							)

							lowercase			:		List[Any]   		=  False
							lowercase			:		str   		=  False
							lowercase			:		List[str]   		=  False
							lowercase			:		int   		=  False
							lowercase			:		Any   		=  False





							def 		a__   (  self		:Optional[int]			):
									snake_case_		:							List[Any]			       =						CvtModelTester(self			)
									snake_case_		:							List[str]			       =						ConfigTester(self  ,config_class=_UpperCamelCase  ,has_text_modality=_UpperCamelCase  ,hidden_size=3_7			)





							def 		a__   (  self		:str			):
									self.create_and_test_config_common_properties()
									self.config_tester.create_and_test_config_to_json_string()
									self.config_tester.create_and_test_config_to_json_file()
									self.config_tester.create_and_test_config_from_and_save_pretrained()
									self.config_tester.create_and_test_config_with_num_labels()
									self.config_tester.check_config_can_be_init_without_params()
									self.config_tester.check_config_arguments_init()





							def 		a__   (  self		:Union[str, Any]			):
									return





							@unittest.skip(reason="""Cvt does not output attentions"""			)
							def 		a__   (  self		:List[str]			):
									pass





							@unittest.skip(reason="""Cvt does not use inputs_embeds"""			)
							def 		a__   (  self		:Dict			):
									pass





							@unittest.skip(reason="""Cvt does not support input and output embeddings"""			)
							def 		a__   (  self		:Dict			):
									pass





							def 		a__   (  self		:Optional[int]			):
									snake_case_       ,      snake_case_		:							List[str]			       =						self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
											snake_case_		:							List[str]			       =						model_class(_UpperCamelCase			)
											snake_case_		:							List[str]			       =						inspect.signature(model.forward			)
											# signature.parameters is an OrderedDict => so arg_names order is deterministic
											snake_case_		:							Optional[int]			       =						[*signature.parameters.keys()]

											snake_case_		:							Dict			       =						["""pixel_values"""]
											self.assertListEqual(arg_names[:1]  ,_UpperCamelCase			)





							def 		a__   (  self		:List[Any]			):
									snake_case_		:							int			       =						self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_UpperCamelCase			)





							def 		a__   (  self		:Union[str, Any]			):
									def check_hidden_states_output(_UpperCamelCase		:Any  ,_UpperCamelCase		:str  ,_UpperCamelCase		:Union[str, Any]			):
											snake_case_		:							str			       =						model_class(_UpperCamelCase			)
											model.to(_UpperCamelCase			)
											model.eval()

											with torch.no_grad():
													snake_case_		:							List[Any]			       =						model(**self._prepare_for_class(_UpperCamelCase  ,_UpperCamelCase			)			)

											snake_case_		:							Dict			       =						outputs.hidden_states

											snake_case_		:							Optional[int]			       =						len(self.model_tester.depth			)
											self.assertEqual(len(_UpperCamelCase			)  ,_UpperCamelCase			)

											# verify the first hidden states (first block)
											self.assertListEqual(
											    list(hidden_states[0].shape[-3:]			)  ,[
											        self.model_tester.embed_dim[0],
											        self.model_tester.image_size // 4,
											        self.model_tester.image_size // 4,
											    ]  ,)

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

									for model_class in self.all_model_classes:
											snake_case_		:							str			       =						True
											check_hidden_states_output(_UpperCamelCase  ,_UpperCamelCase  ,_UpperCamelCase			)

											# check that output_hidden_states also work using config
											del inputs_dict["output_hidden_states"]
											snake_case_		:							Union[str, Any]			       =						True

											check_hidden_states_output(_UpperCamelCase  ,_UpperCamelCase  ,_UpperCamelCase			)





							def 		a__   (  self		:List[str]			):
									snake_case_		:							List[str]			       =						self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*_UpperCamelCase			)





							@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""			)
							def 		a__   (  self		:Any			):
									pass





							@slow
							def 		a__   (  self		:Optional[Any]			):
									for model_name in CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											snake_case_		:							Tuple			       =						CvtModel.from_pretrained(_UpperCamelCase			)
											self.assertIsNotNone(_UpperCamelCase			)





def      UpperCAmelCase      (		):







		'''simple docstring'''
		snake_case_		:							List[str]			       =						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
		return image






@require_torch
@require_vision
class 						__UpperCamelCase	(						unittest.TestCase							):





							@cached_property
							def 		a__   (  self		:List[str]			):
									return AutoImageProcessor.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]			)





							@slow
							def 		a__   (  self		:str			):
									snake_case_		:							Tuple			       =						CvtForImageClassification.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]			).to(_UpperCamelCase			)

									snake_case_		:							Dict			       =						self.default_image_processor
									snake_case_		:							Union[str, Any]			       =						prepare_img()
									snake_case_		:							Dict			       =						image_processor(images=_UpperCamelCase  ,return_tensors="""pt"""			).to(_UpperCamelCase			)

									# forward pass
									with torch.no_grad():
											snake_case_		:							Optional[Any]			       =						model(**_UpperCamelCase			)

									# verify the logits
									snake_case_		:							Any			       =						torch.Size((1, 1_0_0_0)			)
									self.assertEqual(outputs.logits.shape  ,_UpperCamelCase			)

									snake_case_		:							Optional[Any]			       =						torch.tensor([0.92_85, 0.90_15, -0.31_50]			).to(_UpperCamelCase			)

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



'''simple docstring'''






from __future__ import annotations





def      UpperCAmelCase      (		lowerCamelCase_  :int ):







		'''simple docstring'''
		snake_case_		:							List[str]			       =						[True] * limit
		snake_case_		:							Union[str, Any]			       =						False
		snake_case_		:							List[str]			       =						False
		snake_case_		:							Any			       =						True

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

		snake_case_		:							List[str]			       =						[2]

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

		return primes





def      UpperCAmelCase      (		lowerCamelCase_  :int = 1_00_00_00 ):







		'''simple docstring'''
		snake_case_		:							Optional[int]			       =						prime_sieve(lowerCamelCase_ )
		snake_case_		:							Optional[Any]			       =						0
		snake_case_		:							Optional[int]			       =						0

		for i in range(len(lowerCamelCase_ ) ):
				for j in range(i + length				,      len(lowerCamelCase_ ) ):
						snake_case_		:							Optional[int]			       =						sum(primes[i:j] )
						if sol >= ceiling:
								break

						if sol in primes:
								snake_case_		:							Optional[Any]			       =						j - i
								snake_case_		:							Tuple			       =						sol

		return largest


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