


'''simple docstring'''







import inspect
import unittest

from transformers import DPTConfig
from transformers.file_utils import is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

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


if is_torch_available():
   import torch
   from torch import nn

   from transformers import MODEL_MAPPING, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTModel
   from transformers.models.dpt.modeling_dpt import DPT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
   from PIL import Image

   from transformers import DPTImageProcessor







class A__	:






      def __init__(			self      :Optional[int]					,						SCREAMING_SNAKE_CASE      :List[str]					,						SCREAMING_SNAKE_CASE      :int=2					,						SCREAMING_SNAKE_CASE      :Tuple=3_2					,						SCREAMING_SNAKE_CASE      :Dict=1_6					,						SCREAMING_SNAKE_CASE      :List[str]=3					,						SCREAMING_SNAKE_CASE      :List[Any]=True					,						SCREAMING_SNAKE_CASE      :Tuple=True					,						SCREAMING_SNAKE_CASE      :int=3_2					,						SCREAMING_SNAKE_CASE      :List[str]=4					,						SCREAMING_SNAKE_CASE      :Optional[Any]=[0, 1, 2, 3]					,						SCREAMING_SNAKE_CASE      :Any=4					,						SCREAMING_SNAKE_CASE      :List[Any]=3_7					,						SCREAMING_SNAKE_CASE      :List[str]="gelu"					,						SCREAMING_SNAKE_CASE      :Optional[Any]=0.1					,						SCREAMING_SNAKE_CASE      :Optional[Any]=0.1					,						SCREAMING_SNAKE_CASE      :Optional[Any]=0.02					,						SCREAMING_SNAKE_CASE      :Union[str, Any]=3					,						SCREAMING_SNAKE_CASE      :List[Any]=False					,						SCREAMING_SNAKE_CASE      :Tuple=None					,						)	-> Optional[int]:




             '''simple docstring'''
             _a   :			Any					 =parent
             _a   :			Dict					 =batch_size
             _a   :			Optional[int]					 =image_size
             _a   :			Dict					 =patch_size
             _a   :			Union[str, Any]					 =num_channels
             _a   :			str					 =is_training
             _a   :			Union[str, Any]					 =use_labels
             _a   :			List[str]					 =hidden_size
             _a   :			Dict					 =num_hidden_layers
             _a   :			Tuple					 =backbone_out_indices
             _a   :			List[str]					 =num_attention_heads
             _a   :			List[str]					 =intermediate_size
             _a   :			int					 =hidden_act
             _a   :			Optional[int]					 =hidden_dropout_prob
             _a   :			Tuple					 =attention_probs_dropout_prob
             _a   :			Optional[int]					 =initializer_range
             _a   :			List[Any]					 =num_labels
             _a   :			str					 =scope
             _a   :			int					 =is_hybrid
             # sequence length of DPT = num_patches + 1 (we add 1 for the [CLS] token)
             _a   :			Union[str, Any]					 =(image_size // patch_size) ** 2
             _a   :			Any					 =num_patches + 1






      def __UpperCAmelCase	(			self      :str     )	-> List[Any]:




             '''simple docstring'''
             _a   :			List[Any]					 =floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

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

             _a   :			int					 =self.get_config()

             return config, pixel_values, labels






      def __UpperCAmelCase	(			self      :List[str]     )	-> List[str]:




             '''simple docstring'''
             return DPTConfig(
                 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					,						backbone_out_indices=self.backbone_out_indices					,						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=SCREAMING_SNAKE_CASE					,						initializer_range=self.initializer_range					,						is_hybrid=self.is_hybrid					,						)






      def __UpperCAmelCase	(			self      :Any					,						SCREAMING_SNAKE_CASE      :Optional[Any]					,						SCREAMING_SNAKE_CASE      :Any					,						SCREAMING_SNAKE_CASE      :Optional[Any]     )	-> str:




             '''simple docstring'''
             _a   :			Any					 =DPTModel(config=SCREAMING_SNAKE_CASE     )
             model.to(SCREAMING_SNAKE_CASE     )
             model.eval()
             _a   :			Union[str, Any]					 =model(SCREAMING_SNAKE_CASE     )
             self.parent.assertEqual(result.last_hidden_state.shape					,						(self.batch_size, self.seq_length, self.hidden_size)     )






      def __UpperCAmelCase	(			self      :Optional[Any]					,						SCREAMING_SNAKE_CASE      :List[Any]					,						SCREAMING_SNAKE_CASE      :Any					,						SCREAMING_SNAKE_CASE      :Any     )	-> Dict:




             '''simple docstring'''
             _a   :			Union[str, Any]					 =self.num_labels
             _a   :			Dict					 =DPTForDepthEstimation(SCREAMING_SNAKE_CASE     )
             model.to(SCREAMING_SNAKE_CASE     )
             model.eval()
             _a   :			Tuple					 =model(SCREAMING_SNAKE_CASE     )
             self.parent.assertEqual(result.predicted_depth.shape					,						(self.batch_size, self.image_size, self.image_size)     )






      def __UpperCAmelCase	(			self      :Optional[int]					,						SCREAMING_SNAKE_CASE      :str					,						SCREAMING_SNAKE_CASE      :Optional[int]					,						SCREAMING_SNAKE_CASE      :Union[str, Any]     )	-> Optional[int]:




             '''simple docstring'''
             _a   :			Dict					 =self.num_labels
             _a   :			Optional[Any]					 =DPTForSemanticSegmentation(SCREAMING_SNAKE_CASE     )
             model.to(SCREAMING_SNAKE_CASE     )
             model.eval()
             _a   :			List[Any]					 =model(SCREAMING_SNAKE_CASE					,						labels=SCREAMING_SNAKE_CASE     )
             self.parent.assertEqual(
                 result.logits.shape					,						(self.batch_size, self.num_labels, self.image_size, self.image_size)     )






      def __UpperCAmelCase	(			self      :Union[str, Any]     )	-> List[str]:




             '''simple docstring'''
             _a   :			List[Any]					 =self.prepare_config_and_inputs()
             _a ,   _a ,   _a   :			List[str]					 =config_and_inputs
             _a   :			Tuple					 ={"""pixel_values""": pixel_values}
             return config, inputs_dict







@require_torch
class A__	(						UpperCAmelCase__			,					UpperCAmelCase__			,					unittest.TestCase				):
      __UpperCamelCase	:  Union[str, Any]     	=							(DPTModel, DPTForDepthEstimation, DPTForSemanticSegmentation) if is_torch_available() else ()
      __UpperCamelCase	:  Dict     	=							(
          {
              "depth-estimation": DPTForDepthEstimation,
              "feature-extraction": DPTModel,
              "image-segmentation": DPTForSemanticSegmentation,
          }
          if is_torch_available()
          else {}
      )

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






      def __UpperCAmelCase	(			self      :int     )	-> int:




             '''simple docstring'''
             _a   :			Dict					 =DPTModelTester(self     )
             _a   :			int					 =ConfigTester(self					,						config_class=SCREAMING_SNAKE_CASE					,						has_text_modality=SCREAMING_SNAKE_CASE					,						hidden_size=3_7     )






      def __UpperCAmelCase	(			self      :int     )	-> List[str]:




             '''simple docstring'''
             self.config_tester.run_common_tests()






      @unittest.skip(reason="""DPT does not use inputs_embeds"""     )
      def __UpperCAmelCase	(			self      :int     )	-> int:




             '''simple docstring'''
             pass






      def __UpperCAmelCase	(			self      :str     )	-> int:




             '''simple docstring'''
             _a ,   _a   :			Optional[Any]					 =self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    _a   :			List[Any]					 =model_class(SCREAMING_SNAKE_CASE     )
                    self.assertIsInstance(model.get_input_embeddings()					,						(nn.Module)     )
                    _a   :			Optional[Any]					 =model.get_output_embeddings()
                    self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE					,						nn.Linear     )     )






      def __UpperCAmelCase	(			self      :Any     )	-> List[str]:




             '''simple docstring'''
             _a ,   _a   :			Union[str, Any]					 =self.model_tester.prepare_config_and_inputs_for_common()

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

                    _a   :			Any					 =["""pixel_values"""]
                    self.assertListEqual(arg_names[:1]					,						SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :Dict     )	-> int:




             '''simple docstring'''
             _a   :			Optional[Any]					 =self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :int     )	-> int:




             '''simple docstring'''
             _a   :			int					 =self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_depth_estimation(*SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :Any     )	-> int:




             '''simple docstring'''
             _a   :			int					 =self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_semantic_segmentation(*SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :int     )	-> Optional[int]:




             '''simple docstring'''
             for model_class in self.all_model_classes:
                    if model_class.__name__ == "DPTForDepthEstimation":
                           continue

                    _a ,   _a   :			List[str]					 =self.model_tester.prepare_config_and_inputs_for_common()
                    _a   :			int					 =True

                    if model_class in get_values(SCREAMING_SNAKE_CASE     ):
                           continue

                    _a   :			List[str]					 =model_class(SCREAMING_SNAKE_CASE     )
                    model.to(SCREAMING_SNAKE_CASE     )
                    model.train()
                    _a   :			int					 =self._prepare_for_class(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE					,						return_labels=SCREAMING_SNAKE_CASE     )
                    _a   :			str					 =model(**SCREAMING_SNAKE_CASE     ).loss
                    loss.backward()






      def __UpperCAmelCase	(			self      :List[str]     )	-> int:




             '''simple docstring'''
             for model_class in self.all_model_classes:
                    if model_class.__name__ == "DPTForDepthEstimation":
                           continue

                    _a ,   _a   :			Tuple					 =self.model_tester.prepare_config_and_inputs_for_common()
                    _a   :			List[str]					 =False
                    _a   :			Tuple					 =True

                    if model_class in get_values(SCREAMING_SNAKE_CASE     ) or not model_class.supports_gradient_checkpointing:
                           continue
                    _a   :			Union[str, Any]					 =model_class(SCREAMING_SNAKE_CASE     )
                    model.to(SCREAMING_SNAKE_CASE     )
                    model.gradient_checkpointing_enable()
                    model.train()
                    _a   :			Optional[Any]					 =self._prepare_for_class(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE					,						return_labels=SCREAMING_SNAKE_CASE     )
                    _a   :			List[str]					 =model(**SCREAMING_SNAKE_CASE     ).loss
                    loss.backward()






      def __UpperCAmelCase	(			self      :str     )	-> Any:




             '''simple docstring'''
             _a ,   _a   :			List[Any]					 =self.model_tester.prepare_config_and_inputs_for_common()

             _a   :			Union[str, Any]					 =_config_zero_init(SCREAMING_SNAKE_CASE     )
             for model_class in self.all_model_classes:
                    _a   :			Union[str, Any]					 =model_class(config=SCREAMING_SNAKE_CASE     )
                    # Skip the check for the backbone
                    _a   :			Tuple					 =[]
                    for name, module in model.named_modules():
                           if module.__class__.__name__ == "DPTViTHybridEmbeddings":
                                  _a   :			Union[str, Any]					 =[f"{name}.{key}" for key in module.state_dict().keys()]
                                  break

                    for name, param in model.named_parameters():
                           if param.requires_grad:
                                  if name in backbone_params:
                                         continue
                                  self.assertIn(
                                      ((param.data.mean() * 1e9).round() / 1e9).item()					,						[0.0, 1.0]					,						msg=f"Parameter {name} of model {model_class} seems not properly initialized"					,						)






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




             '''simple docstring'''
             pass






      @slow
      def __UpperCAmelCase	(			self      :Optional[Any]     )	-> List[Any]:




             '''simple docstring'''
             for model_name in DPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    _a   :			List[Any]					 =DPTModel.from_pretrained(SCREAMING_SNAKE_CASE     )
                    self.assertIsNotNone(SCREAMING_SNAKE_CASE     )


def      SCREAMING_SNAKE_CASE_ (  )  ->      Tuple:
       _a   :			List[Any]					 =Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
       return image







@require_torch
@require_vision
@slow
class A__	(						unittest.TestCase				):






      def __UpperCAmelCase	(			self      :Tuple     )	-> str:




             '''simple docstring'''
             _a   :			List[Any]					 =DPTImageProcessor.from_pretrained("""Intel/dpt-large"""     )
             _a   :			Union[str, Any]					 =DPTForDepthEstimation.from_pretrained("""Intel/dpt-large"""     ).to(SCREAMING_SNAKE_CASE     )

             _a   :			Union[str, Any]					 =prepare_img()
             _a   :			Union[str, Any]					 =image_processor(images=SCREAMING_SNAKE_CASE					,						return_tensors="""pt"""     ).to(SCREAMING_SNAKE_CASE     )

             # forward pass
             with torch.no_grad():
                    _a   :			List[str]					 =model(**SCREAMING_SNAKE_CASE     )
                    _a   :			Optional[Any]					 =outputs.predicted_depth

             # verify the predicted depth
             _a   :			int					 =torch.Size((1, 3_8_4, 3_8_4)     )
             self.assertEqual(predicted_depth.shape					,						SCREAMING_SNAKE_CASE     )

             _a   :			Union[str, Any]					 =torch.tensor(
                 [[6.3_199, 6.3_629, 6.4_148], [6.3_850, 6.3_615, 6.4_166], [6.3_519, 6.3_176, 6.3_575]]     ).to(SCREAMING_SNAKE_CASE     )

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






      def __UpperCAmelCase	(			self      :Dict     )	-> Tuple:




             '''simple docstring'''
             _a   :			Any					 =DPTImageProcessor.from_pretrained("""Intel/dpt-large-ade"""     )
             _a   :			Tuple					 =DPTForSemanticSegmentation.from_pretrained("""Intel/dpt-large-ade"""     ).to(SCREAMING_SNAKE_CASE     )

             _a   :			Any					 =prepare_img()
             _a   :			Dict					 =image_processor(images=SCREAMING_SNAKE_CASE					,						return_tensors="""pt"""     ).to(SCREAMING_SNAKE_CASE     )

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

             # verify the logits
             _a   :			Tuple					 =torch.Size((1, 1_5_0, 4_8_0, 4_8_0)     )
             self.assertEqual(outputs.logits.shape					,						SCREAMING_SNAKE_CASE     )

             _a   :			Any					 =torch.tensor(
                 [[4.0_480, 4.2_420, 4.4_360], [4.3_124, 4.5_693, 4.8_261], [4.5_768, 4.8_965, 5.2_163]]     ).to(SCREAMING_SNAKE_CASE     )

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






      def __UpperCAmelCase	(			self      :Tuple     )	-> List[Any]:




             '''simple docstring'''
             _a   :			Any					 =DPTImageProcessor.from_pretrained("""Intel/dpt-large-ade"""     )
             _a   :			Optional[int]					 =DPTForSemanticSegmentation.from_pretrained("""Intel/dpt-large-ade"""     ).to(SCREAMING_SNAKE_CASE     )

             _a   :			Dict					 =prepare_img()
             _a   :			Optional[int]					 =image_processor(images=SCREAMING_SNAKE_CASE					,						return_tensors="""pt"""     ).to(SCREAMING_SNAKE_CASE     )

             # forward pass
             with torch.no_grad():
                    _a   :			List[str]					 =model(**SCREAMING_SNAKE_CASE     )

             _a   :			int					 =outputs.logits.detach().cpu()

             _a   :			int					 =image_processor.post_process_semantic_segmentation(outputs=SCREAMING_SNAKE_CASE					,						target_sizes=[(5_0_0, 3_0_0)]     )
             _a   :			Tuple					 =torch.Size((5_0_0, 3_0_0)     )
             self.assertEqual(segmentation[0].shape					,						SCREAMING_SNAKE_CASE     )

             _a   :			List[str]					 =image_processor.post_process_semantic_segmentation(outputs=SCREAMING_SNAKE_CASE     )
             _a   :			int					 =torch.Size((4_8_0, 4_8_0)     )
             self.assertEqual(segmentation[0].shape					,						SCREAMING_SNAKE_CASE     )






'''simple docstring'''







def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     Union[str, Any]  )  ->      int:
       _a   :			List[str]					 =[701, 301, 132, 57, 23, 10, 4, 1]
       for gap in gaps:
              for i in range(_UpperCAmelCase   ,len(_UpperCAmelCase  )  ):
                     _a   :			Tuple					 =collection[i]
                     _a   :			Optional[Any]					 =i
                     while j >= gap and collection[j - gap] > insert_value:
                            _a   :			Union[str, Any]					 =collection[j - gap]
                            j -= gap
                     if j != i:
                            _a   :			Union[str, Any]					 =insert_value
       return collection


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

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


