



'''simple docstring'''





import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


A			:   Tuple			=      logging.get_logger(__name__)

A			:   List[str]			=      {
    """facebook/sam-vit-huge""": """https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json""",
    """facebook/sam-vit-large""": """https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json""",
    """facebook/sam-vit-base""": """https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json""",
}





class 							lowerCAmelCase_		(	a_						):





    def __init__(    self    :    str,    _snake_case    :    List[Any]=256,    _snake_case    :    Tuple=1_024,    _snake_case    :    int=16,    _snake_case    :    int=16,    _snake_case    :    Union[str, Any]=4,    _snake_case    :    Optional[Any]="gelu",    _snake_case    :    int=1E-6,    **_snake_case    :    List[str],    ):



       '''simple docstring'''







       super().__init__(**_snake_case     )
       snake_case   :							str						  =hidden_size
       snake_case   :							List[str]						  =image_size
       snake_case   :							Optional[Any]						  =patch_size
       snake_case   :							List[Any]						  =image_size // patch_size
       snake_case   :							str						  =mask_input_channels
       snake_case   :							Any						  =num_point_embeddings
       snake_case   :							Union[str, Any]						  =hidden_act
       snake_case   :							Any						  =layer_norm_eps





class 							lowerCAmelCase_		(	a_						):





    def __init__(    self    :    List[Any],    _snake_case    :    Optional[Any]=256,    _snake_case    :    Optional[Any]="relu",    _snake_case    :    Optional[int]=2_048,    _snake_case    :    Union[str, Any]=2,    _snake_case    :    str=8,    _snake_case    :    int=2,    _snake_case    :    Dict=3,    _snake_case    :    Optional[int]=3,    _snake_case    :    List[Any]=256,    _snake_case    :    List[Any]=1E-6,    **_snake_case    :    List[Any],    ):



       '''simple docstring'''







       super().__init__(**_snake_case     )
       snake_case   :							Any						  =hidden_size
       snake_case   :							List[Any]						  =hidden_act
       snake_case   :							Tuple						  =mlp_dim
       snake_case   :							List[Any]						  =num_hidden_layers
       snake_case   :							Any						  =num_attention_heads
       snake_case   :							Optional[int]						  =attention_downsample_rate
       snake_case   :							List[Any]						  =num_multimask_outputs
       snake_case   :							Union[str, Any]						  =iou_head_depth
       snake_case   :							List[str]						  =iou_head_hidden_dim
       snake_case   :							Dict						  =layer_norm_eps





class 							lowerCAmelCase_		(	a_						):





    def __init__(    self    :    int,    _snake_case    :    Any=768,    _snake_case    :    Dict=256,    _snake_case    :    List[Any]=12,    _snake_case    :    Optional[int]=12,    _snake_case    :    int=3,    _snake_case    :    Tuple=1_024,    _snake_case    :    List[Any]=16,    _snake_case    :    List[str]="gelu",    _snake_case    :    Optional[int]=1E-06,    _snake_case    :    Dict=0.0,    _snake_case    :    List[Any]=1E-10,    _snake_case    :    Union[str, Any]=True,    _snake_case    :    int=4.0,    _snake_case    :    List[Any]=True,    _snake_case    :    Tuple=True,    _snake_case    :    Optional[int]=14,    _snake_case    :    List[Any]=[2, 5, 8, 11],    _snake_case    :    Tuple=128,    _snake_case    :    int=None,    **_snake_case    :    str,    ):



       '''simple docstring'''







       super().__init__(**_snake_case     )

       snake_case   :							Union[str, Any]						  =hidden_size
       snake_case   :							int						  =output_channels
       snake_case   :							Optional[int]						  =num_hidden_layers
       snake_case   :							Dict						  =num_attention_heads
       snake_case   :							Any						  =num_channels
       snake_case   :							str						  =image_size
       snake_case   :							Optional[Any]						  =patch_size
       snake_case   :							Union[str, Any]						  =hidden_act
       snake_case   :							Union[str, Any]						  =layer_norm_eps
       snake_case   :							Union[str, Any]						  =attention_dropout
       snake_case   :							Optional[int]						  =initializer_range
       snake_case   :							Tuple						  =qkv_bias
       snake_case   :							Optional[int]						  =mlp_ratio
       snake_case   :							Dict						  =use_abs_pos
       snake_case   :							Dict						  =use_rel_pos
       snake_case   :							List[str]						  =window_size
       snake_case   :							List[Any]						  =global_attn_indexes
       snake_case   :							Optional[int]						  =num_pos_feats
       snake_case   :							Dict						  =int(hidden_size * mlp_ratio     ) if mlp_dim is None else mlp_dim





class 							lowerCAmelCase_		(	a_						):
    __UpperCAmelCase							=	'sam'
    __UpperCAmelCase							=	True





    def __init__(    self    :    Optional[int],    _snake_case    :    Any=None,    _snake_case    :    Optional[int]=None,    _snake_case    :    Union[str, Any]=None,    _snake_case    :    List[Any]=0.02,    **_snake_case    :    Union[str, Any],    ):



       '''simple docstring'''







       super().__init__(**_snake_case     )
       snake_case   :							List[str]						  =vision_config if vision_config is not None else {}
       snake_case   :							List[Any]						  =prompt_encoder_config if prompt_encoder_config is not None else {}
       snake_case   :							Dict						  =mask_decoder_config if mask_decoder_config is not None else {}

       if isinstance(_snake_case,    _snake_case     ):
          snake_case   :							Any						  =vision_config.to_dict()
       if isinstance(_snake_case,    _snake_case     ):
          snake_case   :							Dict						  =prompt_encoder_config.to_dict()
       if isinstance(_snake_case,    _snake_case     ):
          snake_case   :							Any						  =mask_decoder_config.to_dict()

       snake_case   :							List[str]						  =SamVisionConfig(**_snake_case     )
       snake_case   :							List[str]						  =SamPromptEncoderConfig(**_snake_case     )
       snake_case   :							Any						  =SamMaskDecoderConfig(**_snake_case     )
       snake_case   :							Union[str, Any]						  =initializer_range






    def 					__snake_case       (    self    :    Optional[int]     ):



       '''simple docstring'''







       snake_case   :							Optional[int]						  =copy.deepcopy(self.__dict__     )
       snake_case   :							Optional[Any]						  =self.vision_config.to_dict()
       snake_case   :							List[str]						  =self.prompt_encoder_config.to_dict()
       snake_case   :							Tuple						  =self.mask_decoder_config.to_dict()
       snake_case   :							Dict						  =self.__class__.model_type
       return output




'''simple docstring'''





class 							lowerCAmelCase_		:





    def __init__(    self    :    List[Any],    _snake_case    :    Any     ):



       '''simple docstring'''







       snake_case   :							Tuple						  =data
       snake_case   :							int						  =None
       snake_case   :							List[Any]						  =None






    def __str__(    self    :    List[str]     ):



       '''simple docstring'''







       return f'''{self.data}'''





class 							lowerCAmelCase_		:





    def __init__(    self    :    Optional[int]     ):



       '''simple docstring'''







       snake_case   :							Optional[int]						  =None
       snake_case   :							int						  =None





    def __iter__(    self    :    List[str]     ):



       '''simple docstring'''







       snake_case   :							str						  =self.head
       while node:
          yield node.data
          snake_case   :							Union[str, Any]						  =node.next





    def __str__(    self    :    List[str]     ):



       '''simple docstring'''







       return "->".join([str(_snake_case     ) for item in self]     )





    def __len__(    self    :    Dict     ):



       '''simple docstring'''







       return sum(1 for _ in self     )





    def 					__snake_case       (    self    :    List[Any],    _snake_case    :    str     ):



       '''simple docstring'''







       self.insert_at_nth(0,    _snake_case     )





    def 					__snake_case       (    self    :    Optional[Any],    _snake_case    :    Dict     ):



       '''simple docstring'''







       self.insert_at_nth(len(self     ),    _snake_case     )





    def 					__snake_case       (    self    :    Union[str, Any],    _snake_case    :    int,    _snake_case    :    Dict     ):



       '''simple docstring'''







       snake_case   :							Optional[int]						  =len(self     )

       if not 0 <= index <= length:
          raise IndexError('''list index out of range'''     )
       snake_case   :							int						  =Node(_snake_case     )
       if self.head is None:
          snake_case   :							Optional[Any]						  =new_node
       elif index == 0:
          snake_case   :							int						  =new_node
          snake_case   :							Union[str, Any]						  =self.head
          snake_case   :							Optional[int]						  =new_node
       elif index == length:
          snake_case   :							Dict						  =new_node
          snake_case   :							int						  =self.tail
          snake_case   :							Union[str, Any]						  =new_node
       else:
          snake_case   :							Optional[int]						  =self.head
          for _ in range(0,    _snake_case     ):
             snake_case   :							Union[str, Any]						  =temp.next
          snake_case   :							int						  =new_node
          snake_case   :							Union[str, Any]						  =temp.previous
          snake_case   :							List[Any]						  =temp
          snake_case   :							int						  =new_node





    def 					__snake_case       (    self    :    str     ):



       '''simple docstring'''







       return self.delete_at_nth(0     )





    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       return self.delete_at_nth(len(self     ) - 1     )





    def 					__snake_case       (    self    :    Union[str, Any],    _snake_case    :    int     ):



       '''simple docstring'''







       snake_case   :							Dict						  =len(self     )

       if not 0 <= index <= length - 1:
          raise IndexError('''list index out of range'''     )
       snake_case   :							List[str]						  =self.head  # default first node
       if length == 1:
          snake_case   :							Union[str, Any]						  =None
       elif index == 0:
          snake_case   :							Tuple						  =self.head.next
          snake_case   :							Optional[int]						  =None
       elif index == length - 1:
          snake_case   :							Union[str, Any]						  =self.tail
          snake_case   :							List[str]						  =self.tail.previous
          snake_case   :							int						  =None
       else:
          snake_case   :							int						  =self.head
          for _ in range(0,    _snake_case     ):
             snake_case   :							Any						  =temp.next
          snake_case   :							List[Any]						  =temp
          snake_case   :							Optional[Any]						  =temp.previous
          snake_case   :							int						  =temp.next
       return delete_node.data





    def 					__snake_case       (    self    :    List[Any],    _snake_case    :    Tuple     ):



       '''simple docstring'''







       snake_case   :							List[Any]						  =self.head

       while current.data != data:  # Find the position to delete
          if current.next:
             snake_case   :							Any						  =current.next
          else:  # We have reached the end an no value matches
             raise ValueError('''No data matching given value'''     )

       if current == self.head:
          self.delete_head()

       elif current == self.tail:
          self.delete_tail()

       else:  # Before: 1 <--> 2(current) <--> 3
          snake_case   :							Optional[int]						  =current.next  # 1 --> 3
          snake_case   :							List[Any]						  =current.previous  # 1 <--> 3
       return data






    def 					__snake_case       (    self    :    Any     ):



       '''simple docstring'''







       return len(self     ) == 0




def 		_a   (  ):
   snake_case   :							Optional[Any]						  =DoublyLinkedList()
   assert linked_list.is_empty() is True
   assert str(lowerCamelCase_							) == ""

   try:
      linked_list.delete_head()
      raise AssertionError  # This should not happen.
   except IndexError:
      assert True  # This should happen.

   try:
      linked_list.delete_tail()
      raise AssertionError  # This should not happen.
   except IndexError:
      assert True  # This should happen.

   for i in range(10							):
      assert len(lowerCamelCase_							) == i
      linked_list.insert_at_nth(lowerCamelCase_					,						i + 1							)
   assert str(lowerCamelCase_							) == "->".join(str(lowerCamelCase_							) for i in range(1					,						11							)							)

   linked_list.insert_at_head(0							)
   linked_list.insert_at_tail(11							)
   assert str(lowerCamelCase_							) == "->".join(str(lowerCamelCase_							) for i in range(0					,						12							)							)

   assert linked_list.delete_head() == 0
   assert linked_list.delete_at_nth(9							) == 10
   assert linked_list.delete_tail() == 11
   assert len(lowerCamelCase_							) == 9
   assert str(lowerCamelCase_							) == "->".join(str(lowerCamelCase_							) for i in range(1					,						10							)							)


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

      testmod()





