






from __future__ import annotations

from math import pi, pow

def 						snake_case      (UpperCAmelCase__						) ->       float:
  if side_length < 0:
    raise ValueError('vol_cube() only accepts non-negative values'						)
  return pow(UpperCAmelCase__			,					3						)

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       float:
  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(UpperCAmelCase__			,					2						) * (3 * radius - height)

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__			,					UpperCAmelCase__						) ->       float:
  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(UpperCAmelCase__			,					UpperCAmelCase__						)						)

  UpperCamelCase_:      Any					   =       (
      (radius_a - radius_a + centers_distance)
      * (radius_a + radius_a - centers_distance)
      / (2 * centers_distance)
  )
  UpperCamelCase_:      Tuple					   =       (
      (radius_a - radius_a + centers_distance)
      * (radius_a + radius_a - centers_distance)
      / (2 * centers_distance)
  )

  return vol_spherical_cap(UpperCAmelCase__			,					UpperCAmelCase__						) + vol_spherical_cap(UpperCAmelCase__			,					UpperCAmelCase__						)

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__			,					UpperCAmelCase__						) ->       float:

  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(UpperCAmelCase__			,					UpperCAmelCase__						)						)

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

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

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       float:
  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 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       float:
  if height < 0 or radius < 0:
    raise ValueError('vol_right_circ_cone() only accepts non-negative values'						)
  return pi * pow(UpperCAmelCase__			,					2						) * height / 3.0

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

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       float:
  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 						snake_case      (UpperCAmelCase__						) ->       float:
  if radius < 0:
    raise ValueError('vol_sphere() only accepts non-negative values'						)
  # Volume is 4/3 * pi * radius cubed
  return 4 / 3 * pi * pow(UpperCAmelCase__			,					3						)

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

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

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__			,					UpperCAmelCase__						) ->       float:
  # Volume - (outer_radius squared - inner_radius squared) * pi * height
  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(UpperCAmelCase__			,					2						) - pow(UpperCAmelCase__			,					2						)) * height

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__			,					UpperCAmelCase__						) ->       float:
  # Volume is 1/3 * pi * height *
  #           (radius_1 squared + radius_2 squared + radius_1 * radius_2)
  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(UpperCAmelCase__			,					2						) + pow(UpperCAmelCase__			,					2						) + radius_a * radius_a)
  )

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

def 						snake_case      () ->       Optional[Any]:
  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()







from __future__ import annotations

import unittest

from transformers import CTRLConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers.models.ctrl.modeling_tf_ctrl import (
       TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFCTRLForSequenceClassification,
       TFCTRLLMHeadModel,
       TFCTRLModel,
   )




class        _lowerCAmelCase( UpperCAmelCase_      ):





       """simple docstring"""







       def __init__(      self						,    _lowerCamelCase						,    ):
         UpperCamelCase_:      Tuple					   =       parent
         UpperCamelCase_:      Optional[Any]					   =       1_3
         UpperCamelCase_:      Any					   =       7
         UpperCamelCase_:      Any					   =       True
         UpperCamelCase_:      List[Any]					   =       True
         UpperCamelCase_:      Dict					   =       True
         UpperCamelCase_:      Optional[Any]					   =       True
         UpperCamelCase_:      Tuple					   =       True
         UpperCamelCase_:      Any					   =       9_9
         UpperCamelCase_:      Dict					   =       3_2
         UpperCamelCase_:      Dict					   =       2
         UpperCamelCase_:      List[Any]					   =       4
         UpperCamelCase_:      int					   =       3_7
         UpperCamelCase_:      List[str]					   =       'gelu'
         UpperCamelCase_:      Union[str, Any]					   =       0.1
         UpperCamelCase_:      int					   =       0.1
         UpperCamelCase_:      int					   =       5_1_2
         UpperCamelCase_:      str					   =       1_6
         UpperCamelCase_:      List[str]					   =       2
         UpperCamelCase_:      Optional[int]					   =       0.0_2
         UpperCamelCase_:      int					   =       3
         UpperCamelCase_:      Tuple					   =       4
         UpperCamelCase_:      List[Any]					   =       None
         UpperCamelCase_:      Union[str, Any]					   =       self.vocab_size - 1





       def     _a					(      self							):
         UpperCamelCase_:      Optional[Any]					   =       ids_tensor([self.batch_size, self.seq_length]						,    self.vocab_size							)

         UpperCamelCase_:      List[str]					   =       None
         if self.use_input_mask:
           UpperCamelCase_:      str					   =       random_attention_mask([self.batch_size, self.seq_length]							)

         UpperCamelCase_:      Optional[Any]					   =       None
         if self.use_token_type_ids:
           UpperCamelCase_:      str					   =       ids_tensor([self.batch_size, self.seq_length]						,    self.type_vocab_size							)

         UpperCamelCase_:      Dict					   =       None
         if self.use_mc_token_ids:
           UpperCamelCase_:      str					   =       ids_tensor([self.batch_size, self.num_choices]						,    self.seq_length							)

         UpperCamelCase_:      Any					   =       None
         UpperCamelCase_:      Any					   =       None
         UpperCamelCase_:      Dict					   =       None
         if self.use_labels:
           UpperCamelCase_:      str					   =       ids_tensor([self.batch_size]						,    self.type_sequence_label_size							)
           UpperCamelCase_:      Dict					   =       ids_tensor([self.batch_size, self.seq_length]						,    self.num_labels							)
           UpperCamelCase_:      Union[str, Any]					   =       ids_tensor([self.batch_size]						,    self.num_choices							)

         UpperCamelCase_:      List[str]					   =       CTRLConfig(
             vocab_size=self.vocab_size						,    n_embd=self.hidden_size						,    n_layer=self.num_hidden_layers						,    n_head=self.num_attention_heads						,    n_positions=self.max_position_embeddings						,    pad_token_id=self.pad_token_id						,    )

         UpperCamelCase_:      Tuple					   =       ids_tensor([self.num_hidden_layers, self.num_attention_heads]						,    2							)

         return (
             config,
             input_ids,
             input_mask,
             head_mask,
             token_type_ids,
             mc_token_ids,
             sequence_labels,
             token_labels,
             choice_labels,
         )





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    *_lowerCamelCase							):
         UpperCamelCase_:      Dict					   =       TFCTRLModel(config=_lowerCamelCase							)
         UpperCamelCase_:      int					   =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         UpperCamelCase_:      Optional[int]					   =       model(_lowerCamelCase							)

         UpperCamelCase_:      Optional[int]					   =       [input_ids, None, input_mask]  # None is the input for 'past'
         UpperCamelCase_:      Dict					   =       model(_lowerCamelCase							)

         UpperCamelCase_:      List[str]					   =       model(_lowerCamelCase							)

         self.parent.assertEqual(result.last_hidden_state.shape						,    (self.batch_size, self.seq_length, self.hidden_size)							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    *_lowerCamelCase							):
         UpperCamelCase_:      int					   =       TFCTRLLMHeadModel(config=_lowerCamelCase							)
         UpperCamelCase_:      Optional[int]					   =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         UpperCamelCase_:      List[Any]					   =       model(_lowerCamelCase							)
         self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.seq_length, self.vocab_size)							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    *_lowerCamelCase							):
         UpperCamelCase_:      List[str]					   =       self.num_labels
         UpperCamelCase_:      Dict					   =       ids_tensor([self.batch_size]						,    self.type_sequence_label_size							)
         UpperCamelCase_:      List[Any]					   =       {
             'input_ids': input_ids,
             'token_type_ids': token_type_ids,
             'labels': sequence_labels,
         }
         UpperCamelCase_:      List[str]					   =       TFCTRLForSequenceClassification(_lowerCamelCase							)
         UpperCamelCase_:      Tuple					   =       model(_lowerCamelCase							)
         self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.num_labels)							)





       def     _a					(      self							):
         UpperCamelCase_:      int					   =       self.prepare_config_and_inputs()

         (
             (
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,
         ):      str					   =       config_and_inputs

         UpperCamelCase_:      List[str]					   =       {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
         return config, inputs_dict







@require_tf
class        _lowerCAmelCase( UpperCAmelCase_							,			UpperCAmelCase_							,			unittest.TestCase      ):





       """simple docstring"""







       a       :	Tuple								=(TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else ()
       a       :	str								=(TFCTRLLMHeadModel,) if is_tf_available() else ()
       a       :	int								=(
           {
               '''feature-extraction''': TFCTRLModel,
               '''text-classification''': TFCTRLForSequenceClassification,
               '''text-generation''': TFCTRLLMHeadModel,
               '''zero-shot''': TFCTRLForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )
       a       :	Tuple								=False
       a       :	str								=False





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase							):
         if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
           # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
           # `CTRLConfig` was never used in pipeline tests, either because of a missing checkpoint or because a tiny
           # config could not be created.
           return True

         return False





       def     _a					(      self							):
         UpperCamelCase_:      List[str]					   =       TFCTRLModelTester(self							)
         UpperCamelCase_:      List[Any]					   =       ConfigTester(self						,    config_class=_lowerCamelCase						,    n_embd=3_7							)





       def     _a					(      self							):
         self.config_tester.run_common_tests()





       def     _a					(      self							):
         UpperCamelCase_:      Dict					   =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_ctrl_model(*_lowerCamelCase							)





       def     _a					(      self							):
         UpperCamelCase_:      Optional[int]					   =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_ctrl_lm_head(*_lowerCamelCase							)





       def     _a					(      self							):
         UpperCamelCase_:      Union[str, Any]					   =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_ctrl_for_sequence_classification(*_lowerCamelCase							)





       def     _a					(      self							):
         UpperCamelCase_   ,UpperCamelCase_:      Union[str, Any]					   =       self.model_tester.prepare_config_and_inputs_for_common()
         UpperCamelCase_:      Optional[Any]					   =       [TFCTRLLMHeadModel]
         UpperCamelCase_:      Optional[Any]					   =       [TFCTRLForSequenceClassification]

         for model_class in self.all_model_classes:
           UpperCamelCase_:      Union[str, Any]					   =       model_class(_lowerCamelCase							)
           model.build()  # may be needed for the get_bias() call below
           assert isinstance(model.get_input_embeddings()						,    tf.keras.layers.Layer							)

           if model_class in list_lm_models:
             UpperCamelCase_:      str					   =       model.get_output_embeddings()
             assert isinstance(_lowerCamelCase						,    tf.keras.layers.Layer							)
             UpperCamelCase_:      List[Any]					   =       model.get_bias()
             assert isinstance(_lowerCamelCase						,    _lowerCamelCase							)
             for k, v in name.items():
               assert isinstance(_lowerCamelCase						,    tf.Variable							)
           elif model_class in list_other_models_with_output_ebd:
             UpperCamelCase_:      Any					   =       model.get_output_embeddings()
             assert isinstance(_lowerCamelCase						,    tf.keras.layers.Layer							)
             UpperCamelCase_:      List[Any]					   =       model.get_bias()
             assert name is None
           else:
             UpperCamelCase_:      Dict					   =       model.get_output_embeddings()
             assert x is None
             UpperCamelCase_:      Optional[int]					   =       model.get_bias()
             assert name is None





       @slow
       def     _a					(      self							):
         for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           UpperCamelCase_:      Optional[Any]					   =       TFCTRLModel.from_pretrained(_lowerCamelCase							)
           self.assertIsNotNone(_lowerCamelCase							)







@require_tf
class        _lowerCAmelCase( unittest.TestCase      ):





       """simple docstring"""







       @slow
       def     _a					(      self							):
         UpperCamelCase_:      Optional[int]					   =       TFCTRLLMHeadModel.from_pretrained('ctrl'							)
         UpperCamelCase_:      Any					   =       tf.convert_to_tensor([[1_1_8_5_9, 0, 1_6_1_1, 8]]						,    dtype=tf.intaa							)  # Legal the president is
         UpperCamelCase_:      Dict					   =       [
             1_1_8_5_9,
             0,
             1_6_1_1,
             8,
             5,
             1_5_0,
             2_6_4_4_9,
             2,
             1_9,
             3_4_8,
             4_6_9,
             3,
             2_5_9_5,
             4_8,
             2_0_7_4_0,
             2_4_6_5_3_3,
             2_4_6_5_3_3,
             1_9,
             3_0,
             5,
         ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

         UpperCamelCase_:      List[str]					   =       model.generate(_lowerCamelCase						,    do_sample=_lowerCamelCase							)
         self.assertListEqual(output_ids[0].numpy().tolist()						,    _lowerCamelCase							)