


'''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 		a__    (							__lowercase  ):





							'''simple docstring'''






							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Dict:
														lowerCAmelCase__	       =     self.config_class(**self.inputs_dict       )
														self.parent.assertTrue(hasattr(_a ,   '''embed_dim'''       )       )
														self.parent.assertTrue(hasattr(_a ,   '''num_heads'''       )       )




class 		a__    :





							'''simple docstring'''






							def __init__(		self ,   lowerCamelCase_ ,   lowerCamelCase_=13 ,   lowerCamelCase_=64 ,   lowerCamelCase_=3 ,   lowerCamelCase_=[16, 48, 96] ,   lowerCamelCase_=[1, 3, 6] ,   lowerCamelCase_=[1, 2, 10] ,   lowerCamelCase_=[7, 3, 3] ,   lowerCamelCase_=[4, 2, 2] ,   lowerCamelCase_=[2, 1, 1] ,   lowerCamelCase_=[2, 2, 2] ,   lowerCamelCase_=[False, False, True] ,   lowerCamelCase_=[0.0, 0.0, 0.0] ,   lowerCamelCase_=0.02 ,   lowerCamelCase_=1e-12 ,   lowerCamelCase_=True ,   lowerCamelCase_=True ,   lowerCamelCase_=2 ,   )	->							List[str]:
														lowerCAmelCase__	       =     parent
														lowerCAmelCase__	       =     batch_size
														lowerCAmelCase__	       =     image_size
														lowerCAmelCase__	       =     patch_sizes
														lowerCAmelCase__	       =     patch_stride
														lowerCAmelCase__	       =     patch_padding
														lowerCAmelCase__	       =     is_training
														lowerCAmelCase__	       =     use_labels
														lowerCAmelCase__	       =     num_labels
														lowerCAmelCase__	       =     num_channels
														lowerCAmelCase__	       =     embed_dim
														lowerCAmelCase__	       =     num_heads
														lowerCAmelCase__	       =     stride_kv
														lowerCAmelCase__	       =     depth
														lowerCAmelCase__	       =     cls_token
														lowerCAmelCase__	       =     attention_drop_rate
														lowerCAmelCase__	       =     initializer_range
														lowerCAmelCase__	       =     layer_norm_eps







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Union[str, Any]:
														lowerCAmelCase__	       =     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

														lowerCAmelCase__	       =     None
														if self.use_labels:
																					lowerCAmelCase__	       =     ids_tensor([self.batch_size] ,   self.num_labels       )

														lowerCAmelCase__	       =     self.get_config()
														return config, pixel_values, labels







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Dict:
														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   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_       )	->							Optional[Any]:
														lowerCAmelCase__	       =     CvtModel(config=_a       )
														model.to(_a       )
														model.eval()
														lowerCAmelCase__	       =     model(_a       )
														lowerCAmelCase__	       =     (self.image_size, self.image_size)
														lowerCAmelCase__       , lowerCAmelCase__	       =     image_size[0], image_size[1]
														for i in range(len(self.depth       )       ):
																					lowerCAmelCase__	       =     floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1       )
																					lowerCAmelCase__	       =     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   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_       )	->							str:
														lowerCAmelCase__	       =     self.num_labels
														lowerCAmelCase__	       =     CvtForImageClassification(_a       )
														model.to(_a       )
														model.eval()
														lowerCAmelCase__	       =     model(_a ,   labels=_a       )
														self.parent.assertEqual(result.logits.shape ,   (self.batch_size, self.num_labels)       )







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




@require_torch
class 		a__    (							__lowercase    ,    __lowercase    ,    unittest.TestCase  ):





							'''simple docstring'''






							lowercase__      :       Any     						=				(CvtModel, CvtForImageClassification) if is_torch_available() else ()
							lowercase__      :       Any     						=				(
							    {"feature-extraction": CvtModel, "image-classification": CvtForImageClassification}
							    if is_torch_available()
							    else {}
							)

							lowercase__      :       List[Any]     						=				False
							lowercase__      :       Optional[Any]     						=				False
							lowercase__      :       Any     						=				False
							lowercase__      :       Any     						=				False
							lowercase__      :       List[str]     						=				False







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							str:
														lowerCAmelCase__	       =     CvtModelTester(self       )
														lowerCAmelCase__	       =     ConfigTester(self ,   config_class=_a ,   has_text_modality=_a ,   hidden_size=37       )







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							List[Any]:
														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   __SCREAMING_SNAKE_CASE							(		self       )	->							Tuple:
														return







							@unittest.skip(reason='''Cvt does not output attentions'''       )
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Tuple:
														pass







							@unittest.skip(reason='''Cvt does not use inputs_embeds'''       )
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Tuple:
														pass







							@unittest.skip(reason='''Cvt does not support input and output embeddings'''       )
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							str:
														pass







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Dict:
														lowerCAmelCase__       , lowerCAmelCase__	       =     self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					lowerCAmelCase__	       =     model_class(_a       )
																					lowerCAmelCase__	       =     inspect.signature(model.forward       )
																					# signature.parameters is an OrderedDict => so arg_names order is deterministic
																					lowerCAmelCase__	       =     [*signature.parameters.keys()]

																					lowerCAmelCase__	       =     ['''pixel_values''']
																					self.assertListEqual(arg_names[:1] ,   _a       )







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							str:
														lowerCAmelCase__	       =     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*_a       )







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Union[str, Any]:
														def check_hidden_states_output(lowerCamelCase_ ,   lowerCamelCase_ ,   lowerCamelCase_       ):
																					lowerCAmelCase__	       =     model_class(_a       )
																					model.to(_a       )
																					model.eval()

																					with torch.no_grad():
																												lowerCAmelCase__	       =     model(**self._prepare_for_class(_a ,   _a       )       )

																					lowerCAmelCase__	       =     outputs.hidden_states

																					lowerCAmelCase__	       =     len(self.model_tester.depth       )
																					self.assertEqual(len(_a       ) ,   _a       )

																					# 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,
																					    ] ,   )

														lowerCAmelCase__       , lowerCAmelCase__	       =     self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					lowerCAmelCase__	       =     True
																					check_hidden_states_output(_a ,   _a ,   _a       )

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					lowerCAmelCase__	       =     True

																					check_hidden_states_output(_a ,   _a ,   _a       )







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							List[Any]:
														lowerCAmelCase__	       =     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_image_classification(*_a       )







							@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''       )
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							List[Any]:
														pass







							@slow
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							int:
														for model_name in CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					lowerCAmelCase__	       =     CvtModel.from_pretrained(_a       )
																					self.assertIsNotNone(_a       )


def  _snake_case       (					)						->   Union[str, Any]:
							lowerCAmelCase__	       =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''	)
							return image






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





							'''simple docstring'''






							@cached_property
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							int:
														return AutoImageProcessor.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]       )







							@slow
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							List[str]:
														lowerCAmelCase__	       =     CvtForImageClassification.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]       ).to(_a       )

														lowerCAmelCase__	       =     self.default_image_processor
														lowerCAmelCase__	       =     prepare_img()
														lowerCAmelCase__	       =     image_processor(images=_a ,   return_tensors='''pt'''       ).to(_a       )

														# forward pass
														with torch.no_grad():
																					lowerCAmelCase__	       =     model(**_a       )

														# verify the logits
														lowerCAmelCase__	       =     torch.Size((1, 10_00)       )
														self.assertEqual(outputs.logits.shape ,   _a       )

														lowerCAmelCase__	       =     torch.tensor([0.9_285, 0.9_015, -0.3_150]       ).to(_a       )

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



'''simple docstring'''






from __future__ import annotations


def  _snake_case       (					A			,   A	)						->   float:
							lowerCAmelCase__	       =     sorted(numsa + numsa	)
							lowerCAmelCase__       , lowerCAmelCase__	       =     divmod(len(A	)			,   2	)
							if mod == 1:
														return all_numbers[div]
							else:
														return (all_numbers[div] + all_numbers[div - 1]) / 2


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		__UpperCAmelCase       =							[float(x) for x in input('''Enter the elements of first array: ''').split()]
		__UpperCAmelCase       =							[float(x) for x in input('''Enter the elements of second array: ''').split()]
		print(f"""The median of two arrays is: {median_of_two_arrays(array_a, array_a)}""")