
'''simple docstring'''





import copy
from typing import Dict, List, Optional

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


lowerCamelCase      ={
    "facebook/mask2former-swin-small-coco-instance": (
        "https://huggingface.co/facebook/mask2former-swin-small-coco-instance/blob/main/config.json"
    )
    # See all Mask2Former models at https://huggingface.co/models?filter=mask2former
}

lowerCamelCase      =logging.get_logger(__name__)




class 				_lowerCamelCase (      __UpperCAmelCase ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  "mask2former"
     SCREAMING_SNAKE_CASE_		   =  ["swin"]
     SCREAMING_SNAKE_CASE_		   =  {"hidden_size": "hidden_dim"}






     def __init__(							self						,						__SCREAMING_SNAKE_CASE = None						,						__SCREAMING_SNAKE_CASE = 2_5_6						,						__SCREAMING_SNAKE_CASE = 2_5_6						,						__SCREAMING_SNAKE_CASE = 2_5_6						,						__SCREAMING_SNAKE_CASE = 1_0_2_4						,						__SCREAMING_SNAKE_CASE = "relu"						,						__SCREAMING_SNAKE_CASE = 6						,						__SCREAMING_SNAKE_CASE = 1_0						,						__SCREAMING_SNAKE_CASE = 8						,						__SCREAMING_SNAKE_CASE = 0.0						,						__SCREAMING_SNAKE_CASE = 2_0_4_8						,						__SCREAMING_SNAKE_CASE = False						,						__SCREAMING_SNAKE_CASE = False						,						__SCREAMING_SNAKE_CASE = 4						,						__SCREAMING_SNAKE_CASE = 2_5_5						,						__SCREAMING_SNAKE_CASE = 1_0_0						,						__SCREAMING_SNAKE_CASE = 0.1						,						__SCREAMING_SNAKE_CASE = 2.0						,						__SCREAMING_SNAKE_CASE = 5.0						,						__SCREAMING_SNAKE_CASE = 5.0						,						__SCREAMING_SNAKE_CASE = 1_2_5_4_4						,						__SCREAMING_SNAKE_CASE = 3.0						,						__SCREAMING_SNAKE_CASE = 0.75						,						__SCREAMING_SNAKE_CASE = 0.02						,						__SCREAMING_SNAKE_CASE = 1.0						,						__SCREAMING_SNAKE_CASE = True						,						__SCREAMING_SNAKE_CASE = [4, 8, 1_6, 3_2]						,						__SCREAMING_SNAKE_CASE = None						,						**__SCREAMING_SNAKE_CASE						,						)  ->   Dict:




           """simple docstring"""







           if backbone_config is None:
                 logger.info('''`backbone_config` is `None`. Initializing the config with the default `Swin` backbone.'''  )
                 UpperCamelCase__    :   Any					=				CONFIG_MAPPING['''swin'''](
                     image_size=2_2_4						,						in_channels=3						,						patch_size=4						,						embed_dim=9_6						,						depths=[2, 2, 1_8, 2]						,						num_heads=[3, 6, 1_2, 2_4]						,						window_size=7						,						drop_path_rate=0.3						,						use_absolute_embeddings=_lowerCamelCase						,						out_features=['''stage1''', '''stage2''', '''stage3''', '''stage4''']						,						)

           if isinstance(_lowerCamelCase						,						_lowerCamelCase  ):
                 UpperCamelCase__    :   int					=				backbone_config.pop('''model_type'''  )
                 UpperCamelCase__    :   str					=				CONFIG_MAPPING[backbone_model_type]
                 UpperCamelCase__    :   Optional[Any]					=				config_class.from_dict(_lowerCamelCase  )

           # verify that the backbone is supported
           if backbone_config.model_type not in self.backbones_supported:
                 logger.warning_once(
                     F'''Backbone {backbone_config.model_type} is not a supported model and may not be compatible with Mask2Former. '''
                     F'''Supported model types: {",".join(self.backbones_supported  )}'''  )

           UpperCamelCase__    :   Tuple					=				backbone_config
           UpperCamelCase__    :   List[Any]					=				feature_size
           UpperCamelCase__    :   Union[str, Any]					=				mask_feature_size
           UpperCamelCase__    :   Any					=				hidden_dim
           UpperCamelCase__    :   Optional[int]					=				encoder_feedforward_dim
           UpperCamelCase__    :   Union[str, Any]					=				activation_function
           UpperCamelCase__    :   Dict					=				encoder_layers
           UpperCamelCase__    :   List[Any]					=				decoder_layers
           UpperCamelCase__    :   Dict					=				num_attention_heads
           UpperCamelCase__    :   Tuple					=				dropout
           UpperCamelCase__    :   str					=				dim_feedforward
           UpperCamelCase__    :   List[str]					=				pre_norm
           UpperCamelCase__    :   Optional[int]					=				enforce_input_projection
           UpperCamelCase__    :   Optional[int]					=				common_stride
           UpperCamelCase__    :   Dict					=				ignore_value
           UpperCamelCase__    :   Any					=				num_queries
           UpperCamelCase__    :   List[str]					=				no_object_weight
           UpperCamelCase__    :   Any					=				class_weight
           UpperCamelCase__    :   Dict					=				mask_weight
           UpperCamelCase__    :   Any					=				dice_weight
           UpperCamelCase__    :   Optional[int]					=				train_num_points
           UpperCamelCase__    :   Optional[int]					=				oversample_ratio
           UpperCamelCase__    :   int					=				importance_sample_ratio
           UpperCamelCase__    :   Optional[Any]					=				init_std
           UpperCamelCase__    :   Any					=				init_xavier_std
           UpperCamelCase__    :   List[str]					=				use_auxiliary_loss
           UpperCamelCase__    :   List[str]					=				feature_strides
           UpperCamelCase__    :   Tuple					=				output_auxiliary_logits
           UpperCamelCase__    :   Optional[int]					=				decoder_layers

           super().__init__(**_lowerCamelCase  )






     @classmethod
     def    __SCREAMING_SNAKE_CASE			(							cls						,						__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   str:




           """simple docstring"""







           return cls(
               backbone_config=_lowerCamelCase						,						**_lowerCamelCase						,						)






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




           """simple docstring"""







           UpperCamelCase__    :   Union[str, Any]					=				copy.deepcopy(self.__dict__  )
           UpperCamelCase__    :   Any					=				self.backbone_config.to_dict()
           UpperCamelCase__    :   Tuple					=				self.__class__.model_type
           return output




class 				_lowerCamelCase :





     """simple docstring"""







     def __init__(							self  )  ->   Tuple:




           """simple docstring"""







           UpperCamelCase__    :   Union[str, Any]					=				''''''
           UpperCamelCase__    :   int					=				''''''
           UpperCamelCase__    :   Optional[int]					=				[]






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   int:




           """simple docstring"""







           if m == -1:
                 return n + 1
           elif n == -1:
                 return m + 1
           elif self.dp[m][n] > -1:
                 return self.dp[m][n]
           else:
                 if self.worda[m] == self.worda[n]:
                       UpperCamelCase__    :   Union[str, Any]					=				self.__min_dist_top_down_dp(m - 1						,						n - 1  )
                 else:
                       UpperCamelCase__    :   int					=				self.__min_dist_top_down_dp(__SCREAMING_SNAKE_CASE						,						n - 1  )
                       UpperCamelCase__    :   Tuple					=				self.__min_dist_top_down_dp(m - 1						,						__SCREAMING_SNAKE_CASE  )
                       UpperCamelCase__    :   Optional[Any]					=				self.__min_dist_top_down_dp(m - 1						,						n - 1  )
                       UpperCamelCase__    :   Optional[int]					=				1 + min(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )

                 return self.dp[m][n]






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   int:




           """simple docstring"""







           UpperCamelCase__    :   Union[str, Any]					=				worda
           UpperCamelCase__    :   Any					=				worda
           UpperCamelCase__    :   List[str]					=				[[-1 for _ in range(len(__SCREAMING_SNAKE_CASE  )  )] for _ in range(len(__SCREAMING_SNAKE_CASE  )  )]

           return self.__min_dist_top_down_dp(len(__SCREAMING_SNAKE_CASE  ) - 1						,						len(__SCREAMING_SNAKE_CASE  ) - 1  )






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   int:




           """simple docstring"""







           UpperCamelCase__    :   int					=				worda
           UpperCamelCase__    :   List[str]					=				worda
           UpperCamelCase__    :   int					=				len(__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Optional[Any]					=				len(__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   int					=				[[0 for _ in range(n + 1  )] for _ in range(m + 1  )]

           for i in range(m + 1  ):
                 for j in range(n + 1  ):
                       if i == 0:  # first string is empty
                             UpperCamelCase__    :   List[Any]					=				j
                       elif j == 0:  # second string is empty
                             UpperCamelCase__    :   Union[str, Any]					=				i
                       elif worda[i - 1] == worda[j - 1]:  # last characters are equal
                             UpperCamelCase__    :   List[Any]					=				self.dp[i - 1][j - 1]
                       else:
                             UpperCamelCase__    :   Union[str, Any]					=				self.dp[i][j - 1]
                             UpperCamelCase__    :   str					=				self.dp[i - 1][j]
                             UpperCamelCase__    :   Union[str, Any]					=				self.dp[i - 1][j - 1]
                             UpperCamelCase__    :   List[Any]					=				1 + min(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )
           return self.dp[m][n]


if __name__ == "__main__":
    lowerCamelCase      =EditDistance()

    print("****************** Testing Edit Distance DP Algorithm ******************")
    print()

    lowerCamelCase      =input("Enter the first string: ").strip()
    lowerCamelCase      =input("Enter the second string: ").strip()

    print()
    print(F'''The minimum edit distance is: {solver.min_dist_top_down(Sa, Sa)}''')
    print(F'''The minimum edit distance is: {solver.min_dist_bottom_up(Sa, Sa)}''')
    print()
    print("*************** End of Testing Edit Distance DP Algorithm ***************")


