





'''simple docstring'''







from __future__ import annotations

from math import pi, pow

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	int | float)			->						float:

     '''simple docstring'''




     if side_length < 0:
          raise ValueError('vol_cube() only accepts non-negative values')
     return pow(lowerCAmelCase__       ,  3)

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if height < 0 or radius < 0:
          raise ValueError('vol_spherical_cap() only accepts non-negative values')
     # Volume is 1/3 pi * height squared * (3 * radius - height)
     return 1 / 3 * pi * pow(lowerCAmelCase__       ,  2) * (3 * radius - height)

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if radius_a < 0 or radius_a < 0 or centers_distance < 0:
          raise ValueError('vol_spheres_intersect() only accepts non-negative values')
     if centers_distance == 0:
          return vol_sphere(min(lowerCAmelCase__       ,  lowerCAmelCase__))

     _lowercase							:      Tuple  						=							(
         (radius_a - radius_a + centers_distance)
         * (radius_a + radius_a - centers_distance)
         / (2 * centers_distance)
     )
     _lowercase							:      Union[str, Any]  						=							(
         (radius_a - radius_a + centers_distance)
         * (radius_a + radius_a - centers_distance)
         / (2 * centers_distance)
     )

     return vol_spherical_cap(lowerCAmelCase__       ,  lowerCAmelCase__) + vol_spherical_cap(lowerCAmelCase__       ,  lowerCAmelCase__)

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if radius_a <= 0 or radius_a <= 0 or centers_distance < 0:
          raise ValueError(
              'vol_spheres_union() only accepts non-negative values, non-zero radius')

     if centers_distance == 0:
          return vol_sphere(max(lowerCAmelCase__       ,  lowerCAmelCase__))

     return (
         vol_sphere(lowerCAmelCase__)
         + vol_sphere(lowerCAmelCase__)
         - vol_spheres_intersect(lowerCAmelCase__       ,  lowerCAmelCase__       ,  lowerCAmelCase__)
     )

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if width < 0 or height < 0 or length < 0:
          raise ValueError('vol_cuboid() only accepts non-negative values')
     return float(width * height * length)

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if height < 0 or area_of_base < 0:
          raise ValueError('vol_cone() only accepts non-negative values')
     return area_of_base * height / 3.0

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if height < 0 or radius < 0:
          raise ValueError('vol_right_circ_cone() only accepts non-negative values')
     return pi * pow(lowerCAmelCase__       ,  2) * height / 3.0

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if height < 0 or area_of_base < 0:
          raise ValueError('vol_prism() only accepts non-negative values')
     return float(area_of_base * height)

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if height < 0 or area_of_base < 0:
          raise ValueError('vol_pyramid() only accepts non-negative values')
     return area_of_base * height / 3.0

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if radius < 0:
          raise ValueError('vol_sphere() only accepts non-negative values')
     # Volume is 4/3 * pi * radius cubed
     return 4 / 3 * pi * pow(lowerCAmelCase__       ,  3)

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if radius < 0:
          raise ValueError('vol_hemisphere() only accepts non-negative values')
     # Volume is radius cubed * pi * 2/3
     return pow(lowerCAmelCase__       ,  3) * pi * 2 / 3

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if height < 0 or radius < 0:
          raise ValueError('vol_circular_cylinder() only accepts non-negative values')
     # Volume is radius squared * height * pi
     return pow(lowerCAmelCase__       ,  2) * height * pi

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if inner_radius < 0 or outer_radius < 0 or height < 0:
          raise ValueError(
              'vol_hollow_circular_cylinder() only accepts non-negative values')
     if outer_radius <= inner_radius:
          raise ValueError('outer_radius must be greater than inner_radius')
     return pi * (pow(lowerCAmelCase__       ,  2) - pow(lowerCAmelCase__       ,  2)) * height

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if radius_a < 0 or radius_a < 0 or height < 0:
          raise ValueError('vol_conical_frustum() only accepts non-negative values')
     return (
         1
         / 3
         * pi
         * height
         * (pow(lowerCAmelCase__       ,  2) + pow(lowerCAmelCase__       ,  2) + radius_a * radius_a)
     )

def 		SCREAMING_SNAKE_CASE      (					lowerCAmelCase__     :	float       ,  lowerCAmelCase__     :	float)			->						float:

     '''simple docstring'''




     if torus_radius < 0 or tube_radius < 0:
          raise ValueError('vol_torus() only accepts non-negative values')
     return 2 * pow(lowerCAmelCase__       ,  2) * torus_radius * pow(lowerCAmelCase__       ,  2)

def 		SCREAMING_SNAKE_CASE      (					)			->						int:

     '''simple docstring'''




     print('Volumes:')
     print(F'''Cube: {vol_cube(2) = }''')  # = 8
     print(F'''Cuboid: {vol_cuboid(2       ,  2       ,  2) = }''')  # = 8
     print(F'''Cone: {vol_cone(2       ,  2) = }''')  # ~= 1.33
     print(F'''Right Circular Cone: {vol_right_circ_cone(2       ,  2) = }''')  # ~= 8.38
     print(F'''Prism: {vol_prism(2       ,  2) = }''')  # = 4
     print(F'''Pyramid: {vol_pyramid(2       ,  2) = }''')  # ~= 1.33
     print(F'''Sphere: {vol_sphere(2) = }''')  # ~= 33.5
     print(F'''Hemisphere: {vol_hemisphere(2) = }''')  # ~= 16.75
     print(F'''Circular Cylinder: {vol_circular_cylinder(2       ,  2) = }''')  # ~= 25.1
     print(F'''Torus: {vol_torus(2       ,  2) = }''')  # ~= 157.9
     print(F'''Conical Frustum: {vol_conical_frustum(2       ,  2       ,  4) = }''')  # ~= 58.6
     print(F'''Spherical cap: {vol_spherical_cap(1       ,  2) = }''')  # ~= 5.24
     print(F'''Spheres intersetion: {vol_spheres_intersect(2       ,  2       ,  1) = }''')  # ~= 21.21
     print(F'''Spheres union: {vol_spheres_union(2       ,  2       ,  1) = }''')  # ~= 45.81
     print(
         F'''Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1       ,  2       ,  3) = }''')  # ~= 28.3


if __name__ == "__main__":
    main()






'''simple docstring'''







import copy

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


A						    =							logging.get_logger(__name__)

A						    =							{
    '''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 							__SCREAMING_SNAKE_CASE			(       lowerCAmelCase__      ):
      '''simple docstring'''



      def __init__(							self    : Union[str, Any]   ,UpperCamelCase    : Tuple=256   ,UpperCamelCase    : Union[str, Any]=1024   ,UpperCamelCase    : Any=16   ,UpperCamelCase    : List[str]=16   ,UpperCamelCase    : List[str]=4   ,UpperCamelCase    : Dict="gelu"   ,UpperCamelCase    : Any=1e-6   ,**UpperCamelCase    : List[Any]   ,)		->  str:
           super().__init__(**UpperCamelCase  )
           _lowercase							:      int  						=							hidden_size
           _lowercase							:      List[str]  						=							image_size
           _lowercase							:      Optional[Any]  						=							patch_size
           _lowercase							:      Any  						=							image_size // patch_size
           _lowercase							:      str  						=							mask_input_channels
           _lowercase							:      Optional[Any]  						=							num_point_embeddings
           _lowercase							:      Dict  						=							hidden_act
           _lowercase							:      int  						=							layer_norm_eps



class 							__SCREAMING_SNAKE_CASE			(       lowerCAmelCase__      ):
      '''simple docstring'''



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



class 							__SCREAMING_SNAKE_CASE			(       lowerCAmelCase__      ):
      '''simple docstring'''



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

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



class 							__SCREAMING_SNAKE_CASE			(       lowerCAmelCase__      ):
      '''simple docstring'''



      lowerCAmelCase__       :      Any 		=		"sam"
      lowerCAmelCase__       :      Optional[int] 		=		True

      def __init__(							self    : Optional[Any]   ,UpperCamelCase    : Optional[int]=None   ,UpperCamelCase    : List[str]=None   ,UpperCamelCase    : List[Any]=None   ,UpperCamelCase    : int=0.0_2   ,**UpperCamelCase    : Any   ,)		->  Tuple:
           super().__init__(**UpperCamelCase  )
           _lowercase							:      str  						=							vision_config if vision_config is not None else {}
           _lowercase							:      int  						=							prompt_encoder_config if prompt_encoder_config is not None else {}
           _lowercase							:      List[Any]  						=							mask_decoder_config if mask_decoder_config is not None else {}

           if isinstance(UpperCamelCase   ,UpperCamelCase  ):
                _lowercase							:      Optional[Any]  						=							vision_config.to_dict()
           if isinstance(UpperCamelCase   ,UpperCamelCase  ):
                _lowercase							:      Union[str, Any]  						=							prompt_encoder_config.to_dict()
           if isinstance(UpperCamelCase   ,UpperCamelCase  ):
                _lowercase							:      List[Any]  						=							mask_decoder_config.to_dict()

           _lowercase							:      Optional[int]  						=							SamVisionConfig(**UpperCamelCase  )
           _lowercase							:      Union[str, Any]  						=							SamPromptEncoderConfig(**UpperCamelCase  )
           _lowercase							:      Union[str, Any]  						=							SamMaskDecoderConfig(**UpperCamelCase  )
           _lowercase							:      Tuple  						=							initializer_range



      def   _lowerCamelCase		(							self    : List[str]  )		->  Optional[int]:
           _lowercase							:      List[Any]  						=							copy.deepcopy(self.__dict__  )
           _lowercase							:      Any  						=							self.vision_config.to_dict()
           _lowercase							:      Dict  						=							self.prompt_encoder_config.to_dict()
           _lowercase							:      Union[str, Any]  						=							self.mask_decoder_config.to_dict()
           _lowercase							:      List[Any]  						=							self.__class__.model_type
           return output