




import inspect
import unittest

from transformers import ResNetConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
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 torch import nn

      from transformers import ResNetBackbone, ResNetForImageClassification, ResNetModel
      from transformers.models.resnet.modeling_resnet import RESNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor






class      A     :
     """simple docstring"""

     def __init__(      self					:				List[str]		,					A__					:				Any		,					A__					:				Union[str, Any]=3		,					A__					:				int=3_2		,					A__					:				Union[str, Any]=3		,					A__					:				int=1_0		,					A__					:				int=[1_0, 2_0, 3_0, 4_0]		,					A__					:				List[Any]=[1, 1, 2, 1]		,					A__					:				List[Any]=True		,					A__					:				Any=True		,					A__					:				int="relu"		,					A__					:				Optional[int]=3		,					A__					:				Any=None		,					A__					:				Union[str, Any]=["stage2", "stage3", "stage4"]		,					A__					:				Optional[Any]=[2, 3, 4]		,					)			->    Optional[Any]:
           lowerCamelCase__ 					=			parent
           lowerCamelCase__ 					=			batch_size
           lowerCamelCase__ 					=			image_size
           lowerCamelCase__ 					=			num_channels
           lowerCamelCase__ 					=			embeddings_size
           lowerCamelCase__ 					=			hidden_sizes
           lowerCamelCase__ 					=			depths
           lowerCamelCase__ 					=			is_training
           lowerCamelCase__ 					=			use_labels
           lowerCamelCase__ 					=			hidden_act
           lowerCamelCase__ 					=			num_labels
           lowerCamelCase__ 					=			scope
           lowerCamelCase__ 					=			len(A__     )
           lowerCamelCase__ 					=			out_features
           lowerCamelCase__ 					=			out_indices




     def 	__snake_case				(      self					:				List[str]     )			->    Tuple:
           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 	__snake_case				(      self					:				Optional[int]     )			->    Optional[Any]:
           return ResNetConfig(
               num_channels=self.num_channels		,					embeddings_size=self.embeddings_size		,					hidden_sizes=self.hidden_sizes		,					depths=self.depths		,					hidden_act=self.hidden_act		,					num_labels=self.num_labels		,					out_features=self.out_features		,					out_indices=self.out_indices		,					)




     def 	__snake_case				(      self					:				Optional[int]		,					A__					:				str		,					A__					:				List[Any]		,					A__					:				str     )			->    str:
           lowerCamelCase__ 					=			ResNetModel(config=A__     )
           model.to(A__     )
           model.eval()
           lowerCamelCase__ 					=			model(A__     )
           # expected last hidden states: B, C, H // 32, W // 32
           self.parent.assertEqual(
               result.last_hidden_state.shape		,					(self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)		,					)




     def 	__snake_case				(      self					:				Optional[int]		,					A__					:				str		,					A__					:				Tuple		,					A__					:				Tuple     )			->    str:
           lowerCamelCase__ 					=			self.num_labels
           lowerCamelCase__ 					=			ResNetForImageClassification(A__     )
           model.to(A__     )
           model.eval()
           lowerCamelCase__ 					=			model(A__		,					labels=A__     )
           self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.num_labels)     )




     def 	__snake_case				(      self					:				str		,					A__					:				Union[str, Any]		,					A__					:				Optional[int]		,					A__					:				int     )			->    Optional[Any]:
           lowerCamelCase__ 					=			ResNetBackbone(config=A__     )
           model.to(A__     )
           model.eval()
           lowerCamelCase__ 					=			model(A__     )

           # verify feature maps
           self.parent.assertEqual(len(result.feature_maps     )		,					len(config.out_features     )     )
           self.parent.assertListEqual(list(result.feature_maps[0].shape     )		,					[self.batch_size, self.hidden_sizes[1], 4, 4]     )

           # verify channels
           self.parent.assertEqual(len(model.channels     )		,					len(config.out_features     )     )
           self.parent.assertListEqual(model.channels		,					config.hidden_sizes[1:]     )

           # verify backbone works with out_features=None
           lowerCamelCase__ 					=			None
           lowerCamelCase__ 					=			ResNetBackbone(config=A__     )
           model.to(A__     )
           model.eval()
           lowerCamelCase__ 					=			model(A__     )

           # verify feature maps
           self.parent.assertEqual(len(result.feature_maps     )		,					1     )
           self.parent.assertListEqual(list(result.feature_maps[0].shape     )		,					[self.batch_size, self.hidden_sizes[-1], 1, 1]     )

           # verify channels
           self.parent.assertEqual(len(model.channels     )		,					1     )
           self.parent.assertListEqual(model.channels		,					[config.hidden_sizes[-1]]     )




     def 	__snake_case				(      self					:				List[Any]     )			->    List[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     (						_lowerCAmelCase     ,  _lowerCAmelCase     ,  unittest.TestCase						):
     """simple docstring"""

     _snake_case       =(
         (
             ResNetModel,
             ResNetForImageClassification,
             ResNetBackbone,
         )
         if is_torch_available()
         else ()
     )
     _snake_case       =(
         {"feature-extraction": ResNetModel, "image-classification": ResNetForImageClassification}
         if is_torch_available()
         else {}
     )

     _snake_case       =True
     _snake_case       =False
     _snake_case       =False
     _snake_case       =False
     _snake_case       =False




     def 	__snake_case				(      self					:				Optional[int]     )			->    Any:
           lowerCamelCase__ 					=			ResNetModelTester(self     )
           lowerCamelCase__ 					=			ConfigTester(self		,					config_class=A__		,					has_text_modality=A__     )




     def 	__snake_case				(      self					:				Dict     )			->    List[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 	__snake_case				(      self					:				Optional[int]     )			->    List[str]:
           return




     @unittest.skip(reason='ResNet does not use inputs_embeds'     )
     def 	__snake_case				(      self					:				str     )			->    str:
           pass




     @unittest.skip(reason='ResNet does not support input and output embeddings'     )
     def 	__snake_case				(      self					:				Optional[int]     )			->    Dict:
           pass




     def 	__snake_case				(      self					:				Any     )			->    Optional[int]:
           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 	__snake_case				(      self					:				Dict     )			->    Union[str, Any]:
           lowerCamelCase__ 					=			self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*A__     )




     def 	__snake_case				(      self					:				List[str]     )			->    Any:
           lowerCamelCase__ 					=			self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_backbone(*A__     )




     def 	__snake_case				(      self					:				Any     )			->    Any:
           lowerCamelCase__					,						lowerCamelCase__ 					=			self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                 lowerCamelCase__ 					=			model_class(config=A__     )
                 for name, module in model.named_modules():
                       if isinstance(A__		,					(nn.BatchNormad, nn.GroupNorm)     ):
                             self.assertTrue(
                                 torch.all(module.weight == 1     )		,					msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""		,					)
                             self.assertTrue(
                                 torch.all(module.bias == 0     )		,					msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""		,					)




     def 	__snake_case				(      self					:				str     )			->    Dict:
           def check_hidden_states_output(A__					:				str		,					A__					:				Tuple		,					A__					:				List[Any]     ):
                 lowerCamelCase__ 					=			model_class(A__     )
                 model.to(A__     )
                 model.eval()

                 with torch.no_grad():
                       lowerCamelCase__ 					=			model(**self._prepare_for_class(A__		,					A__     )     )

                 lowerCamelCase__ 					=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

                 lowerCamelCase__ 					=			self.model_tester.num_stages
                 self.assertEqual(len(A__     )		,					expected_num_stages + 1     )

                 # ResNet's feature maps are of shape (batch_size, num_channels, height, width)
                 self.assertListEqual(
                     list(hidden_states[0].shape[-2:]     )		,					[self.model_tester.image_size // 4, self.model_tester.image_size // 4]		,					)

           lowerCamelCase__					,						lowerCamelCase__ 					=			self.model_tester.prepare_config_and_inputs_for_common()
           lowerCamelCase__ 					=			['basic', 'bottleneck']
           for model_class in self.all_model_classes:
                 for layer_type in layers_type:
                       lowerCamelCase__ 					=			layer_type
                       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__     )




     @unittest.skip(reason='ResNet does not use feedforward chunking'     )
     def 	__snake_case				(      self					:				str     )			->    Optional[int]:
           pass




     def 	__snake_case				(      self					:				Optional[Any]     )			->    Tuple:
           lowerCamelCase__ 					=			self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_image_classification(*A__     )




     @slow
     def 	__snake_case				(      self					:				List[str]     )			->    Tuple:
           for model_name in RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 lowerCamelCase__ 					=			ResNetModel.from_pretrained(A__     )
                 self.assertIsNotNone(A__     )

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


      '''simple docstring'''




      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 	__snake_case				(      self					:				Tuple     )			->    Any:
           return (
               AutoImageProcessor.from_pretrained(RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]     )
               if is_vision_available()
               else None
           )




     @slow
     def 	__snake_case				(      self					:				List[str]     )			->    str:
           lowerCamelCase__ 					=			ResNetForImageClassification.from_pretrained(RESNET_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, 1_0_0_0)     )
           self.assertEqual(outputs.logits.shape		,					A__     )

           lowerCamelCase__ 					=			torch.tensor([-11.1069, -9.7877, -8.3777]     ).to(A__     )

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






@require_torch
class      A     (						_lowerCAmelCase     ,  unittest.TestCase						):
     """simple docstring"""

     _snake_case       =(ResNetBackbone,) if is_torch_available() else ()
     _snake_case       =False
     _snake_case       =ResNetConfig




     def 	__snake_case				(      self					:				List[str]     )			->    Optional[Any]:
           lowerCamelCase__ 					=			ResNetModelTester(self     )





def      lowerCAmelCase_     (					lowerCamelCase:    Optional[int]  )   ->     Union[str, Any]:


      '''simple docstring'''




      lowerCamelCase__ 					=			[7_01, 3_01, 1_32, 57, 23, 10, 4, 1]
      for gap in gaps:
            for i in range(lowerCamelCase       ,			len(lowerCamelCase  )  ):
                  lowerCamelCase__ 					=			collection[i]
                  lowerCamelCase__ 					=			i
                  while j >= gap and collection[j - gap] > insert_value:
                        lowerCamelCase__ 					=			collection[j - gap]
                        j -= gap
                  if j != i:
                        lowerCamelCase__ 					=			insert_value
      return collection


if __name__ == "__main__":
      from doctest import testmod

      testmod()
      __SCREAMING_SNAKE_CASE      :				List[Any]				      =input("""Enter numbers separated by a comma:\n""").strip()
      __SCREAMING_SNAKE_CASE      :				Dict				      =[int(item) for item in user_input.split(""",""")]
      print(shell_sort(unsorted))