





from __future__ import annotations

from collections.abc import Iterable

class 						UpperCamelCase__					:



     '''simple docstring'''

     def __init__(				self		:       Optional[Any]		,lowerCamelCase__		:       Optional[int]		,lowerCamelCase__		:       List[Any]			)	->						int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE,   SCREAMING_SNAKE_CASE						=		float(lowerCamelCase__			), float(lowerCamelCase__			)






     def __eq__(				self		:       int		,lowerCamelCase__		:       Union[str, Any]			)	->						List[str]:




           '''simple docstring'''


           return self.x == other.x and self.y == other.y






     def __ne__(				self		:       Optional[int]		,lowerCamelCase__		:       int			)	->						Dict:




           '''simple docstring'''


           return not self == other






     def __gt__(				self		:       Optional[Any]		,lowerCamelCase__		:       Optional[Any]			)	->						List[Any]:




           '''simple docstring'''


           if self.x > other.x:
                 return True
           elif self.x == other.x:
                 return self.y > other.y
           return False






     def __lt__(				self		:       Union[str, Any]		,lowerCamelCase__		:       Optional[Any]			)	->						Optional[Any]:




           '''simple docstring'''


           return not self > other






     def __ge__(				self		:       Optional[Any]		,lowerCamelCase__		:       Tuple			)	->						Optional[Any]:




           '''simple docstring'''


           if self.x > other.x:
                 return True
           elif self.x == other.x:
                 return self.y >= other.y
           return False






     def __le__(				self		:       Tuple		,lowerCamelCase__		:       int			)	->						Dict:




           '''simple docstring'''


           if self.x < other.x:
                 return True
           elif self.x == other.x:
                 return self.y <= other.y
           return False






     def __repr__(				self		:       Dict			)	->						Any:




           '''simple docstring'''


           return F"""({self.x}, {self.y})"""






     def __hash__(				self		:       List[Any]			)	->						List[Any]:




           '''simple docstring'''


           return hash(self.x			)



def   __lowercase  ( _SCREAMING_SNAKE_CASE					,		)					->  list[Point]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		[]
      if list_of_tuples:
            for p in list_of_tuples:
                  if isinstance(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      ):
                        points.append(_SCREAMING_SNAKE_CASE      )
                  else:
                        try:
                              points.append(Point(p[0]					,		p[1]      )      )
                        except (IndexError, TypeError):
                              print(
                                  F"""Ignoring deformed point {p}. All points"""
                                  """ must have at least 2 coordinates."""      )
      return points



def   __lowercase  ( _SCREAMING_SNAKE_CASE      )					->  list[Point]:


      '''simple docstring'''


      if not hasattr(_SCREAMING_SNAKE_CASE					,		"""__iter__"""      ):
            SCREAMING_SNAKE_CASE						=		F"""Expecting an iterable object but got an non-iterable type {points}"""
            raise ValueError(_SCREAMING_SNAKE_CASE      )

      if not points:
            SCREAMING_SNAKE_CASE						=		F"""Expecting a list of points but got {points}"""
            raise ValueError(_SCREAMING_SNAKE_CASE      )

      return _construct_points(_SCREAMING_SNAKE_CASE      )



def   __lowercase  ( _SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      )					->  float:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		(a.x * b.y + b.x * c.y + c.x * a.y) - (a.y * b.x + b.y * c.x + c.y * a.x)
      return det



def   __lowercase  ( _SCREAMING_SNAKE_CASE      )					->  list[Point]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		sorted(_validate_input(_SCREAMING_SNAKE_CASE      )      )
      SCREAMING_SNAKE_CASE						=		len(_SCREAMING_SNAKE_CASE      )
      SCREAMING_SNAKE_CASE						=		set()

      for i in range(n - 1      ):
            for j in range(i + 1					,		_SCREAMING_SNAKE_CASE      ):
                  SCREAMING_SNAKE_CASE						=		SCREAMING_SNAKE_CASE						=		False
                  SCREAMING_SNAKE_CASE						=		True
                  for k in range(_SCREAMING_SNAKE_CASE      ):
                        if k != i and k != j:
                              SCREAMING_SNAKE_CASE						=		_det(points[i]					,		points[j]					,		points[k]      )

                              if det_k > 0:
                                    SCREAMING_SNAKE_CASE						=		True
                              elif det_k < 0:
                                    SCREAMING_SNAKE_CASE						=		True
                              else:
                                    # point[i], point[j], point[k] all lie on a straight line
                                    # if point[k] is to the left of point[i] or it's to the
                                    # right of point[j], then point[i], point[j] cannot be
                                    # part of the convex hull of A
                                    if points[k] < points[i] or points[k] > points[j]:
                                          SCREAMING_SNAKE_CASE						=		False
                                          break

                        if points_left_of_ij and points_right_of_ij:
                              SCREAMING_SNAKE_CASE						=		False
                              break

                  if ij_part_of_convex_hull:
                        convex_set.update([points[i], points[j]]      )

      return sorted(_SCREAMING_SNAKE_CASE      )



def   __lowercase  ( _SCREAMING_SNAKE_CASE      )					->  list[Point]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		sorted(_validate_input(_SCREAMING_SNAKE_CASE      )      )
      SCREAMING_SNAKE_CASE						=		len(_SCREAMING_SNAKE_CASE      )

      # divide all the points into an upper hull and a lower hull
      # the left most point and the right most point are definitely
      # members of the convex hull by definition.
      # use these two anchors to divide all the points into two hulls,
      # an upper hull and a lower hull.

      # all points to the left (above) the line joining the extreme points belong to the
      # upper hull
      # all points to the right (below) the line joining the extreme points below to the
      # lower hull
      # ignore all points on the line joining the extreme points since they cannot be
      # part of the convex hull

      SCREAMING_SNAKE_CASE						=		points[0]
      SCREAMING_SNAKE_CASE						=		points[n - 1]

      SCREAMING_SNAKE_CASE						=		{left_most_point, right_most_point}
      SCREAMING_SNAKE_CASE						=		[]
      SCREAMING_SNAKE_CASE						=		[]

      for i in range(1					,		n - 1      ):
            SCREAMING_SNAKE_CASE						=		_det(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		points[i]      )

            if det > 0:
                  upper_hull.append(points[i]      )
            elif det < 0:
                  lower_hull.append(points[i]      )

      _construct_hull(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      )
      _construct_hull(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      )

      return sorted(_SCREAMING_SNAKE_CASE      )



def   __lowercase  ( _SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      )					->  None:


      '''simple docstring'''


      if points:
            SCREAMING_SNAKE_CASE						=		None
            SCREAMING_SNAKE_CASE						=		float("""-inf"""      )
            SCREAMING_SNAKE_CASE						=		[]

            for p in points:
                  SCREAMING_SNAKE_CASE						=		_det(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      )

                  if det > 0:
                        candidate_points.append(_SCREAMING_SNAKE_CASE      )

                        if det > extreme_point_distance:
                              SCREAMING_SNAKE_CASE						=		det
                              SCREAMING_SNAKE_CASE						=		p

            if extreme_point:
                  _construct_hull(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      )
                  convex_set.add(_SCREAMING_SNAKE_CASE      )
                  _construct_hull(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      )



def   __lowercase  ( _SCREAMING_SNAKE_CASE      )					->  list[Point]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		sorted(_validate_input(_SCREAMING_SNAKE_CASE      )      )
      SCREAMING_SNAKE_CASE						=		len(_SCREAMING_SNAKE_CASE      )

      SCREAMING_SNAKE_CASE						=		points[:2]
      for i in range(2					,		_SCREAMING_SNAKE_CASE      ):
            SCREAMING_SNAKE_CASE						=		_det(convex_hull[1]					,		convex_hull[0]					,		points[i]      )
            if det > 0:
                  convex_hull.insert(0					,		points[i]      )
                  break
            elif det < 0:
                  convex_hull.append(points[i]      )
                  break
            else:
                  SCREAMING_SNAKE_CASE						=		points[i]
      i += 1

      for j in range(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      ):
            if (
                _det(convex_hull[0]					,		convex_hull[-1]					,		points[j]      ) > 0
                and _det(convex_hull[-1]					,		convex_hull[0]					,		points[1]      ) < 0
            ):
                  # The point lies within the convex hull
                  continue

            convex_hull.insert(0					,		points[j]      )
            convex_hull.append(points[j]      )
            while _det(convex_hull[0]					,		convex_hull[1]					,		convex_hull[2]      ) >= 0:
                  del convex_hull[1]
            while _det(convex_hull[-1]					,		convex_hull[-2]					,		convex_hull[-3]      ) <= 0:
                  del convex_hull[-2]

    # `convex_hull` is contains the convex hull in circular order
      return sorted(convex_hull[1:] if len(_SCREAMING_SNAKE_CASE      ) > 3 else convex_hull      )



def   __lowercase  ( )					->  Any:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		[
          (0, 3),
          (2, 2),
          (1, 1),
          (2, 1),
          (3, 0),
          (0, 0),
          (3, 3),
          (2, -1),
          (2, -4),
          (1, -3),
      ]
      # the convex set of points is
      # [(0, 0), (0, 3), (1, -3), (2, -4), (3, 0), (3, 3)]
      SCREAMING_SNAKE_CASE						=		convex_hull_bf(_SCREAMING_SNAKE_CASE      )

      SCREAMING_SNAKE_CASE						=		convex_hull_recursive(_SCREAMING_SNAKE_CASE      )
      assert results_bf == results_recursive

      SCREAMING_SNAKE_CASE						=		convex_hull_melkman(_SCREAMING_SNAKE_CASE      )
      assert results_bf == results_melkman

      print(_SCREAMING_SNAKE_CASE      )


if __name__ == "__main__":
      main()









import copy

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


SCREAMING_SNAKE_CASE_		  =			logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_		  =			{
    """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 						UpperCamelCase__					( lowerCAmelCase_  ):



     '''simple docstring'''

     def __init__(				self		:       List[str]		,lowerCamelCase__		:       int=256		,lowerCamelCase__		:       List[Any]=1024		,lowerCamelCase__		:       Any=16		,lowerCamelCase__		:       Union[str, Any]=16		,lowerCamelCase__		:       int=4		,lowerCamelCase__		:       Tuple="gelu"		,lowerCamelCase__		:       Dict=1e-6		,**lowerCamelCase__		:       int		,)	->						List[str]:




           '''simple docstring'''


           super().__init__(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		hidden_size
           SCREAMING_SNAKE_CASE						=		image_size
           SCREAMING_SNAKE_CASE						=		patch_size
           SCREAMING_SNAKE_CASE						=		image_size // patch_size
           SCREAMING_SNAKE_CASE						=		mask_input_channels
           SCREAMING_SNAKE_CASE						=		num_point_embeddings
           SCREAMING_SNAKE_CASE						=		hidden_act
           SCREAMING_SNAKE_CASE						=		layer_norm_eps

class 						UpperCamelCase__					( lowerCAmelCase_  ):



     '''simple docstring'''

     def __init__(				self		:       str		,lowerCamelCase__		:       str=256		,lowerCamelCase__		:       Optional[Any]="relu"		,lowerCamelCase__		:       str=2048		,lowerCamelCase__		:       Union[str, Any]=2		,lowerCamelCase__		:       int=8		,lowerCamelCase__		:       Union[str, Any]=2		,lowerCamelCase__		:       List[Any]=3		,lowerCamelCase__		:       int=3		,lowerCamelCase__		:       Optional[Any]=256		,lowerCamelCase__		:       Tuple=1e-6		,**lowerCamelCase__		:       List[str]		,)	->						Dict:




           '''simple docstring'''


           super().__init__(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		hidden_size
           SCREAMING_SNAKE_CASE						=		hidden_act
           SCREAMING_SNAKE_CASE						=		mlp_dim
           SCREAMING_SNAKE_CASE						=		num_hidden_layers
           SCREAMING_SNAKE_CASE						=		num_attention_heads
           SCREAMING_SNAKE_CASE						=		attention_downsample_rate
           SCREAMING_SNAKE_CASE						=		num_multimask_outputs
           SCREAMING_SNAKE_CASE						=		iou_head_depth
           SCREAMING_SNAKE_CASE						=		iou_head_hidden_dim
           SCREAMING_SNAKE_CASE						=		layer_norm_eps

class 						UpperCamelCase__					( lowerCAmelCase_  ):



     '''simple docstring'''

     def __init__(				self		:       Union[str, Any]		,lowerCamelCase__		:       Optional[Any]=768		,lowerCamelCase__		:       Union[str, Any]=256		,lowerCamelCase__		:       Optional[int]=12		,lowerCamelCase__		:       str=12		,lowerCamelCase__		:       Tuple=3		,lowerCamelCase__		:       Optional[Any]=1024		,lowerCamelCase__		:       Optional[int]=16		,lowerCamelCase__		:       Optional[Any]="gelu"		,lowerCamelCase__		:       int=1e-0_6		,lowerCamelCase__		:       Optional[Any]=0.0		,lowerCamelCase__		:       Tuple=1e-1_0		,lowerCamelCase__		:       Any=True		,lowerCamelCase__		:       List[Any]=4.0		,lowerCamelCase__		:       Optional[int]=True		,lowerCamelCase__		:       Union[str, Any]=True		,lowerCamelCase__		:       List[str]=14		,lowerCamelCase__		:       List[str]=[2, 5, 8, 11]		,lowerCamelCase__		:       Tuple=128		,lowerCamelCase__		:       Dict=None		,**lowerCamelCase__		:       Optional[Any]		,)	->						str:




           '''simple docstring'''


           super().__init__(**lowerCamelCase__			)

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

class 						UpperCamelCase__					( lowerCAmelCase_  ):



     '''simple docstring'''

     __snake_case       :      Any						      =     "sam"
     __snake_case       :      Optional[Any]						      =     True






     def __init__(				self		:       Union[str, Any]		,lowerCamelCase__		:       List[Any]=None		,lowerCamelCase__		:       int=None		,lowerCamelCase__		:       int=None		,lowerCamelCase__		:       int=0.02		,**lowerCamelCase__		:       int		,)	->						str:




           '''simple docstring'''


           super().__init__(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		vision_config if vision_config is not None else {}
           SCREAMING_SNAKE_CASE						=		prompt_encoder_config if prompt_encoder_config is not None else {}
           SCREAMING_SNAKE_CASE						=		mask_decoder_config if mask_decoder_config is not None else {}

           if isinstance(lowerCamelCase__		,lowerCamelCase__			):
                 SCREAMING_SNAKE_CASE						=		vision_config.to_dict()
           if isinstance(lowerCamelCase__		,lowerCamelCase__			):
                 SCREAMING_SNAKE_CASE						=		prompt_encoder_config.to_dict()
           if isinstance(lowerCamelCase__		,lowerCamelCase__			):
                 SCREAMING_SNAKE_CASE						=		mask_decoder_config.to_dict()

           SCREAMING_SNAKE_CASE						=		SamVisionConfig(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		SamPromptEncoderConfig(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		SamMaskDecoderConfig(**lowerCamelCase__			)
           SCREAMING_SNAKE_CASE						=		initializer_range






     def 							SCREAMING_SNAKE_CASE__    (				self		:       Union[str, Any]			)	->						Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		copy.deepcopy(self.__dict__			)
           SCREAMING_SNAKE_CASE						=		self.vision_config.to_dict()
           SCREAMING_SNAKE_CASE						=		self.prompt_encoder_config.to_dict()
           SCREAMING_SNAKE_CASE						=		self.mask_decoder_config.to_dict()
           SCREAMING_SNAKE_CASE						=		self.__class__.model_type
           return output


