


'''simple docstring'''




from __future__ import annotations





def      _a		(lowercase__ :      list[int]	) -> list[int]:






     """simple docstring"""
     if not list_of_ints:
          return []

     if min(lowercase__	) < 0:
          raise ValueError('All numbers must be positive'	)

     __snake_case    			=	max(len(bin(lowercase__	)[2:]	) for x in list_of_ints	)
     return _msd_radix_sort(lowercase__       ,      lowercase__	)





def      _a		(lowercase__ :      list[int]       ,      lowercase__ :      int	) -> list[int]:






     """simple docstring"""
     if bit_position == 0 or len(lowercase__	) in [0, 1]:
          return list_of_ints

     __snake_case    			=	[]
     __snake_case    			=	[]
     # Split numbers based on bit at bit_position from the right
     for number in list_of_ints:
          if (number >> (bit_position - 1)) & 1:
               # number has a one at bit bit_position
               ones.append(lowercase__	)
          else:
               # number has a zero at bit bit_position
               zeros.append(lowercase__	)

    # recursively split both lists further
     __snake_case    			=	_msd_radix_sort(lowercase__       ,      bit_position - 1	)
     __snake_case    			=	_msd_radix_sort(lowercase__       ,      bit_position - 1	)

     # recombine lists
     __snake_case    			=	zeros
     res.extend(lowercase__	)

     return res





def      _a		(lowercase__ :      list[int]	) -> str:






     """simple docstring"""
     __snake_case    			=	len(lowercase__	)
     if not list_of_ints or length == 1:
          return

     if min(lowercase__	) < 0:
          raise ValueError('All numbers must be positive'	)

     __snake_case    			=	max(len(bin(lowercase__	)[2:]	) for x in list_of_ints	)
     _msd_radix_sort_inplace(lowercase__       ,      lowercase__       ,      0       ,      lowercase__	)





def      _a		(lowercase__ :      list[int]       ,      lowercase__ :      int       ,      lowercase__ :      int       ,      lowercase__ :      int	) -> Any:






     """simple docstring"""
     if bit_position == 0 or end_index - begin_index <= 1:
          return

     bit_position -= 1

     __snake_case    			=	begin_index
     __snake_case    			=	end_index - 1
     while i <= j:
          __snake_case    			=	False
          if not (list_of_ints[i] >> bit_position) & 1:
               # found zero at the beginning
               i += 1
               __snake_case    			=	True
          if (list_of_ints[j] >> bit_position) & 1:
               # found one at the end
               j -= 1
               __snake_case    			=	True

          if changed:
               continue

          __snake_case			,					__snake_case    			=	list_of_ints[j], list_of_ints[i]
          j -= 1
          if j != i:
               i += 1

     _msd_radix_sort_inplace(lowercase__       ,      lowercase__       ,      lowercase__       ,      lowercase__	)
     _msd_radix_sort_inplace(lowercase__       ,      lowercase__       ,      lowercase__       ,      lowercase__	)


if __name__ == "__main__":
       import doctest

       doctest.testmod()








'''simple docstring'''




import copy

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


_a      :      List[str]       				=      logging.get_logger(__name__)

_a      :      Any       				=      {
    "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  _lowercase   (  __lowercase       ):
   def __init__(	self					:			int					,      SCREAMING_SNAKE_CASE_					:			List[Any]=256					,      SCREAMING_SNAKE_CASE_					:			Optional[Any]=1024					,      SCREAMING_SNAKE_CASE_					:			Any=16					,      SCREAMING_SNAKE_CASE_					:			int=16					,      SCREAMING_SNAKE_CASE_					:			List[Any]=4					,      SCREAMING_SNAKE_CASE_					:			Optional[Any]="gelu"					,      SCREAMING_SNAKE_CASE_					:			Tuple=1e-6					,      **SCREAMING_SNAKE_CASE_					:			Optional[Any]					,      )   ->       Tuple:
        super().__init__(**SCREAMING_SNAKE_CASE_			)
        __snake_case    			=	hidden_size
        __snake_case    			=	image_size
        __snake_case    			=	patch_size
        __snake_case    			=	image_size // patch_size
        __snake_case    			=	mask_input_channels
        __snake_case    			=	num_point_embeddings
        __snake_case    			=	hidden_act
        __snake_case    			=	layer_norm_eps




class  _lowercase   (  __lowercase       ):
   def __init__(	self					:			List[Any]					,      SCREAMING_SNAKE_CASE_					:			List[Any]=256					,      SCREAMING_SNAKE_CASE_					:			Dict="relu"					,      SCREAMING_SNAKE_CASE_					:			Any=2048					,      SCREAMING_SNAKE_CASE_					:			int=2					,      SCREAMING_SNAKE_CASE_					:			Optional[Any]=8					,      SCREAMING_SNAKE_CASE_					:			int=2					,      SCREAMING_SNAKE_CASE_					:			Optional[int]=3					,      SCREAMING_SNAKE_CASE_					:			str=3					,      SCREAMING_SNAKE_CASE_					:			Optional[Any]=256					,      SCREAMING_SNAKE_CASE_					:			Optional[int]=1e-6					,      **SCREAMING_SNAKE_CASE_					:			int					,      )   ->       str:
        super().__init__(**SCREAMING_SNAKE_CASE_			)
        __snake_case    			=	hidden_size
        __snake_case    			=	hidden_act
        __snake_case    			=	mlp_dim
        __snake_case    			=	num_hidden_layers
        __snake_case    			=	num_attention_heads
        __snake_case    			=	attention_downsample_rate
        __snake_case    			=	num_multimask_outputs
        __snake_case    			=	iou_head_depth
        __snake_case    			=	iou_head_hidden_dim
        __snake_case    			=	layer_norm_eps




class  _lowercase   (  __lowercase       ):
   def __init__(	self					:			Union[str, Any]					,      SCREAMING_SNAKE_CASE_					:			int=768					,      SCREAMING_SNAKE_CASE_					:			int=256					,      SCREAMING_SNAKE_CASE_					:			str=12					,      SCREAMING_SNAKE_CASE_					:			Tuple=12					,      SCREAMING_SNAKE_CASE_					:			Optional[Any]=3					,      SCREAMING_SNAKE_CASE_					:			Optional[int]=1024					,      SCREAMING_SNAKE_CASE_					:			List[str]=16					,      SCREAMING_SNAKE_CASE_					:			Optional[Any]="gelu"					,      SCREAMING_SNAKE_CASE_					:			Any=1e-06					,      SCREAMING_SNAKE_CASE_					:			Optional[int]=0.0					,      SCREAMING_SNAKE_CASE_					:			Optional[int]=1e-10					,      SCREAMING_SNAKE_CASE_					:			List[Any]=True					,      SCREAMING_SNAKE_CASE_					:			Optional[int]=4.0					,      SCREAMING_SNAKE_CASE_					:			List[Any]=True					,      SCREAMING_SNAKE_CASE_					:			Optional[int]=True					,      SCREAMING_SNAKE_CASE_					:			Union[str, Any]=14					,      SCREAMING_SNAKE_CASE_					:			str=[2, 5, 8, 11]					,      SCREAMING_SNAKE_CASE_					:			Optional[int]=128					,      SCREAMING_SNAKE_CASE_					:			Tuple=None					,      **SCREAMING_SNAKE_CASE_					:			List[Any]					,      )   ->       Optional[Any]:
        super().__init__(**SCREAMING_SNAKE_CASE_			)

        __snake_case    			=	hidden_size
        __snake_case    			=	output_channels
        __snake_case    			=	num_hidden_layers
        __snake_case    			=	num_attention_heads
        __snake_case    			=	num_channels
        __snake_case    			=	image_size
        __snake_case    			=	patch_size
        __snake_case    			=	hidden_act
        __snake_case    			=	layer_norm_eps
        __snake_case    			=	attention_dropout
        __snake_case    			=	initializer_range
        __snake_case    			=	qkv_bias
        __snake_case    			=	mlp_ratio
        __snake_case    			=	use_abs_pos
        __snake_case    			=	use_rel_pos
        __snake_case    			=	window_size
        __snake_case    			=	global_attn_indexes
        __snake_case    			=	num_pos_feats
        __snake_case    			=	int(hidden_size * mlp_ratio			) if mlp_dim is None else mlp_dim




class  _lowercase   (  __lowercase       ):
   _SCREAMING_SNAKE_CASE     :     Union[str, Any]									=  "sam"
   _SCREAMING_SNAKE_CASE     :     Any									=  True
   def __init__(	self					:			Optional[Any]					,      SCREAMING_SNAKE_CASE_					:			Dict=None					,      SCREAMING_SNAKE_CASE_					:			List[Any]=None					,      SCREAMING_SNAKE_CASE_					:			List[str]=None					,      SCREAMING_SNAKE_CASE_					:			str=0.0_2					,      **SCREAMING_SNAKE_CASE_					:			str					,      )   ->       str:
        super().__init__(**SCREAMING_SNAKE_CASE_			)
        __snake_case    			=	vision_config if vision_config is not None else {}
        __snake_case    			=	prompt_encoder_config if prompt_encoder_config is not None else {}
        __snake_case    			=	mask_decoder_config if mask_decoder_config is not None else {}

        if isinstance(SCREAMING_SNAKE_CASE_					,      SCREAMING_SNAKE_CASE_			):
             __snake_case    			=	vision_config.to_dict()
        if isinstance(SCREAMING_SNAKE_CASE_					,      SCREAMING_SNAKE_CASE_			):
             __snake_case    			=	prompt_encoder_config.to_dict()
        if isinstance(SCREAMING_SNAKE_CASE_					,      SCREAMING_SNAKE_CASE_			):
             __snake_case    			=	mask_decoder_config.to_dict()

        __snake_case    			=	SamVisionConfig(**SCREAMING_SNAKE_CASE_			)
        __snake_case    			=	SamPromptEncoderConfig(**SCREAMING_SNAKE_CASE_			)
        __snake_case    			=	SamMaskDecoderConfig(**SCREAMING_SNAKE_CASE_			)
        __snake_case    			=	initializer_range





   def a     (	self					:			int			)   ->       str:
        __snake_case    			=	copy.deepcopy(self.__dict__			)
        __snake_case    			=	self.vision_config.to_dict()
        __snake_case    			=	self.prompt_encoder_config.to_dict()
        __snake_case    			=	self.mask_decoder_config.to_dict()
        __snake_case    			=	self.__class__.model_type
        return output




