import unittest

from transformers import ElectraConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      MODEL_FOR_PRETRAINING_MAPPING,
      ElectraForCausalLM,
      ElectraForMaskedLM,
      ElectraForMultipleChoice,
      ElectraForPreTraining,
      ElectraForQuestionAnswering,
      ElectraForSequenceClassification,
      ElectraForTokenClassification,
      ElectraModel,
  )
  from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST






class 				_SCREAMING_SNAKE_CASE:
   def __init__(     self				,  lowerCAmelCase_				,  lowerCAmelCase_=13				,  lowerCAmelCase_=7				,  lowerCAmelCase_=True				,  lowerCAmelCase_=True				,  lowerCAmelCase_=True				,  lowerCAmelCase_=True				,  lowerCAmelCase_=99				,  lowerCAmelCase_=32				,  lowerCAmelCase_=5				,  lowerCAmelCase_=4				,  lowerCAmelCase_=37				,  lowerCAmelCase_="gelu"				,  lowerCAmelCase_=0.1				,  lowerCAmelCase_=0.1				,  lowerCAmelCase_=5_12				,  lowerCAmelCase_=16				,  lowerCAmelCase_=2				,  lowerCAmelCase_=0.02				,  lowerCAmelCase_=3				,  lowerCAmelCase_=4				,  lowerCAmelCase_=None				,  )						->Optional[Any]:
        a	:     Tuple						      =    parent
        a	:     Optional[Any]						      =    batch_size
        a	:     Optional[Any]						      =    seq_length
        a	:     Dict						      =    is_training
        a	:     Union[str, Any]						      =    use_input_mask
        a	:     Any						      =    use_token_type_ids
        a	:     Union[str, Any]						      =    use_labels
        a	:     Any						      =    vocab_size
        a	:     Optional[int]						      =    hidden_size
        a	:     List[Any]						      =    num_hidden_layers
        a	:     List[str]						      =    num_attention_heads
        a	:     Optional[Any]						      =    intermediate_size
        a	:     int						      =    hidden_act
        a	:     Union[str, Any]						      =    hidden_dropout_prob
        a	:     Optional[Any]						      =    attention_probs_dropout_prob
        a	:     Union[str, Any]						      =    max_position_embeddings
        a	:     List[Any]						      =    type_vocab_size
        a	:     Dict						      =    type_sequence_label_size
        a	:     Optional[int]						      =    initializer_range
        a	:     Tuple						      =    num_labels
        a	:     int						      =    num_choices
        a	:     int						      =    scope
   def _lowercase(     self     )						->Optional[Any]:
        a	:     List[Any]						      =    ids_tensor([self.batch_size, self.seq_length]				,  self.vocab_size     )

        a	:     str						      =    None
        if self.use_input_mask:
             a	:     Optional[int]						      =    random_attention_mask([self.batch_size, self.seq_length]     )

        a	:     Tuple						      =    None
        if self.use_token_type_ids:
             a	:     Optional[int]						      =    ids_tensor([self.batch_size, self.seq_length]				,  self.type_vocab_size     )

        a	:     Optional[Any]						      =    None
        a	:     int						      =    None
        a	:     Union[str, Any]						      =    None
        if self.use_labels:
             a	:     str						      =    ids_tensor([self.batch_size]				,  self.type_sequence_label_size     )
             a	:     Tuple						      =    ids_tensor([self.batch_size, self.seq_length]				,  self.num_labels     )
             a	:     List[str]						      =    ids_tensor([self.batch_size]				,  self.num_choices     )
             a	:     Tuple						      =    ids_tensor([self.batch_size, self.seq_length]				,  1     )

        a	:     Optional[Any]						      =    self.get_config()

        return (
            config,
            input_ids,
            token_type_ids,
            input_mask,
            sequence_labels,
            token_labels,
            choice_labels,
            fake_token_labels,
        )
   def _lowercase(     self     )						->List[Any]:
        return ElectraConfig(
            vocab_size=self.vocab_size				,  hidden_size=self.hidden_size				,  num_hidden_layers=self.num_hidden_layers				,  num_attention_heads=self.num_attention_heads				,  intermediate_size=self.intermediate_size				,  hidden_act=self.hidden_act				,  hidden_dropout_prob=self.hidden_dropout_prob				,  attention_probs_dropout_prob=self.attention_probs_dropout_prob				,  max_position_embeddings=self.max_position_embeddings				,  type_vocab_size=self.type_vocab_size				,  is_decoder=lowerCAmelCase_				,  initializer_range=self.initializer_range				,  )
   def _lowercase(     self     )						->Union[str, Any]:
        (
            (
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,							
        )	:     int						      =    self.prepare_config_and_inputs()

        a	:     str						      =    True
        a	:     Optional[Any]						      =    floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
        a	:     List[str]						      =    ids_tensor([self.batch_size, self.seq_length]				,  vocab_size=2     )

        return (
            config,
            input_ids,
            token_type_ids,
            input_mask,
            sequence_labels,
            token_labels,
            choice_labels,
            encoder_hidden_states,
            encoder_attention_mask,
        )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  )						->List[str]:
        a	:     Union[str, Any]						      =    ElectraModel(config=lowerCAmelCase_     )
        model.to(lowerCAmelCase_     )
        model.eval()
        a	:     List[Any]						      =    model(lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_     )
        a	:     int						      =    model(lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_     )
        a	:     Union[str, Any]						      =    model(lowerCAmelCase_     )
        self.parent.assertEqual(result.last_hidden_state.shape				,  (self.batch_size, self.seq_length, self.hidden_size)     )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  )						->Optional[int]:
        a	:     Union[str, Any]						      =    True
        a	:     int						      =    ElectraModel(lowerCAmelCase_     )
        model.to(lowerCAmelCase_     )
        model.eval()
        a	:     Any						      =    model(
            lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_				,  encoder_hidden_states=lowerCAmelCase_				,  encoder_attention_mask=lowerCAmelCase_				,  )
        a	:     str						      =    model(
            lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_				,  encoder_hidden_states=lowerCAmelCase_				,  )
        a	:     int						      =    model(lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_     )
        self.parent.assertEqual(result.last_hidden_state.shape				,  (self.batch_size, self.seq_length, self.hidden_size)     )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  )						->List[str]:
        a	:     List[Any]						      =    ElectraForMaskedLM(config=lowerCAmelCase_     )
        model.to(lowerCAmelCase_     )
        model.eval()
        a	:     Any						      =    model(lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_				,  labels=lowerCAmelCase_     )
        self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.vocab_size)     )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  )						->Union[str, Any]:
        a	:     List[str]						      =    ElectraForCausalLM(config=lowerCAmelCase_     )
        model.to(lowerCAmelCase_     )
        model.eval()
        a	:     Dict						      =    model(lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_				,  labels=lowerCAmelCase_     )
        self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.vocab_size)     )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  )						->int:
        a	:     Union[str, Any]						      =    self.num_labels
        a	:     int						      =    ElectraForTokenClassification(config=lowerCAmelCase_     )
        model.to(lowerCAmelCase_     )
        model.eval()
        a	:     Any						      =    model(lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_				,  labels=lowerCAmelCase_     )
        self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.num_labels)     )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  )						->int:
        a	:     Union[str, Any]						      =    self.num_labels
        a	:     List[str]						      =    ElectraForPreTraining(config=lowerCAmelCase_     )
        model.to(lowerCAmelCase_     )
        model.eval()
        a	:     Optional[int]						      =    model(lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_				,  labels=lowerCAmelCase_     )
        self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length)     )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  )						->Optional[Any]:
        a	:     Tuple						      =    self.num_labels
        a	:     List[str]						      =    ElectraForSequenceClassification(lowerCAmelCase_     )
        model.to(lowerCAmelCase_     )
        model.eval()
        a	:     Optional[Any]						      =    model(lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_				,  labels=lowerCAmelCase_     )
        self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.num_labels)     )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  )						->int:
        a	:     Any						      =    ElectraForQuestionAnswering(config=lowerCAmelCase_     )
        model.to(lowerCAmelCase_     )
        model.eval()
        a	:     Dict						      =    model(
            lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_				,  start_positions=lowerCAmelCase_				,  end_positions=lowerCAmelCase_				,  )
        self.parent.assertEqual(result.start_logits.shape				,  (self.batch_size, self.seq_length)     )
        self.parent.assertEqual(result.end_logits.shape				,  (self.batch_size, self.seq_length)     )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_				,  )						->Optional[int]:
        a	:     str						      =    self.num_choices
        a	:     Optional[int]						      =    ElectraForMultipleChoice(config=lowerCAmelCase_     )
        model.to(lowerCAmelCase_     )
        model.eval()
        a	:     Tuple						      =    input_ids.unsqueeze(1     ).expand(-1				,  self.num_choices				,  -1     ).contiguous()
        a	:     Any						      =    token_type_ids.unsqueeze(1     ).expand(-1				,  self.num_choices				,  -1     ).contiguous()
        a	:     Tuple						      =    input_mask.unsqueeze(1     ).expand(-1				,  self.num_choices				,  -1     ).contiguous()
        a	:     Optional[int]						      =    model(
            lowerCAmelCase_				,  attention_mask=lowerCAmelCase_				,  token_type_ids=lowerCAmelCase_				,  labels=lowerCAmelCase_				,  )
        self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.num_choices)     )


   def _lowercase(     self     )						->List[Any]:
        a	:     Tuple						      =    self.prepare_config_and_inputs()
        (
            (
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,				(
            a			
        )      ,							
        )	:     List[str]						      =    config_and_inputs
        a	:     str						      =    {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
        return config, inputs_dict






@require_torch
class 				_SCREAMING_SNAKE_CASE( snake_case__							,   snake_case__							,   unittest.TestCase						):
   UpperCamelCase_					:    List[str]			      = (
       (
           ElectraModel,
           ElectraForPreTraining,
           ElectraForMaskedLM,
           ElectraForCausalLM,
           ElectraForMultipleChoice,
           ElectraForTokenClassification,
           ElectraForSequenceClassification,
           ElectraForQuestionAnswering,
       )
       if is_torch_available()
       else ()
   )
   UpperCamelCase_					:    Union[str, Any]			      = (
       {
           'feature-extraction': ElectraModel,
           'fill-mask': ElectraForMaskedLM,
           'question-answering': ElectraForQuestionAnswering,
           'text-classification': ElectraForSequenceClassification,
           'text-generation': ElectraForCausalLM,
           'token-classification': ElectraForTokenClassification,
           'zero-shot': ElectraForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   UpperCamelCase_					:    str			      = True
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_				,  lowerCAmelCase_=False     )						->int:
        a	:     Any						      =    super()._prepare_for_class(lowerCAmelCase_				,  lowerCAmelCase_				,  return_labels=lowerCAmelCase_     )

        if return_labels:
             if model_class in get_values(lowerCAmelCase_     ):
                  a	:     Optional[Any]						      =    torch.zeros(
                      (self.model_tester.batch_size, self.model_tester.seq_length)				,  dtype=torch.long				,  device=lowerCAmelCase_     )
        return inputs_dict
   def _lowercase(     self     )						->Union[str, Any]:
        a	:     int						      =    ElectraModelTester(self     )
        a	:     Optional[int]						      =    ConfigTester(self				,  config_class=lowerCAmelCase_				,  hidden_size=37     )
   def _lowercase(     self     )						->Any:
        self.config_tester.run_common_tests()
   def _lowercase(     self     )						->int:
        a	:     Dict						      =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_electra_model(*lowerCAmelCase_     )
   def _lowercase(     self     )						->Optional[int]:
        a	:     Optional[int]						      =    self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_electra_model_as_decoder(*lowerCAmelCase_     )
   def _lowercase(     self     )						->Union[str, Any]:
        a	:     List[str]						      =    self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
             a	:     int						      =    type
             self.model_tester.create_and_check_electra_model(*lowerCAmelCase_     )
   def _lowercase(     self     )						->Dict:
        a	:     str						      =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_electra_for_masked_lm(*lowerCAmelCase_     )
   def _lowercase(     self     )						->Dict:
        a	:     Optional[int]						      =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_electra_for_token_classification(*lowerCAmelCase_     )
   def _lowercase(     self     )						->int:
        a	:     Dict						      =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_electra_for_pretraining(*lowerCAmelCase_     )
   def _lowercase(     self     )						->Tuple:
        a	:     Tuple						      =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_electra_for_sequence_classification(*lowerCAmelCase_     )
   def _lowercase(     self     )						->Union[str, Any]:
        a	:     Optional[Any]						      =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_electra_for_question_answering(*lowerCAmelCase_     )
   def _lowercase(     self     )						->List[Any]:
        a	:     Any						      =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_electra_for_multiple_choice(*lowerCAmelCase_     )
   @slow
   def _lowercase(     self     )						->Tuple:
        for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             a	:     Union[str, Any]						      =    ElectraModel.from_pretrained(lowerCAmelCase_     )
             self.assertIsNotNone(lowerCAmelCase_     )


   def _lowercase(     self     )						->Optional[int]:
        a	:     Tuple						      =    self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_electra_for_causal_lm(*lowerCAmelCase_     )






@require_torch
class 				_SCREAMING_SNAKE_CASE( unittest.TestCase						):
   @slow
   def _lowercase(     self     )						->str:
        a	:     Tuple						      =    ElectraModel.from_pretrained('''google/electra-small-discriminator'''     )
        a	:     str						      =    torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]     )
        a	:     Any						      =    torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
        a	:     List[str]						      =    model(lowerCAmelCase_				,  attention_mask=lowerCAmelCase_     )[0]
        a	:     str						      =    torch.Size((1, 11, 2_56)     )
        self.assertEqual(output.shape				,  lowerCAmelCase_     )
        a	:     List[Any]						      =    torch.tensor(
            [[[0.44_71, 0.68_21, -0.32_65], [0.46_27, 0.52_55, -0.36_68], [0.45_32, 0.33_13, -0.43_44]]]     )

        self.assertTrue(torch.allclose(output[:, 1:4, 1:4]				,  lowerCAmelCase_				,  atol=1e-4     )     )





from __future__ import annotations

from math import pi, pow



def     lowerCAmelCase		(		_lowerCAmelCase				: int | float						):




 """simple docstring"""







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



def     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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						)						)

 UpperCAmelCase__							=    (
     (radius_a - radius_a + centers_distance)
     * (radius_a + radius_a - centers_distance)
     / (2 * centers_distance)
 )
 UpperCAmelCase__							=    (
     (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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		_lowerCAmelCase				: float    ,				_lowerCAmelCase				: 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     lowerCAmelCase		(		):




 """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()





