

'''simple docstring'''
from math import pi, sqrt, tan




def 	UpperCamelCase   (       lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if side_length < 0:
    raise ValueError('''surface_area_cube() only accepts non-negative values'''	)
  return 6 * side_length**2




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if length < 0 or breadth < 0 or height < 0:
    raise ValueError('''surface_area_cuboid() only accepts non-negative values'''	)
  return 2 * ((length * breadth) + (breadth * height) + (length * height))




def 	UpperCamelCase   (       lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if radius < 0:
    raise ValueError('''surface_area_sphere() only accepts non-negative values'''	)
  return 4 * pi * radius**2




def 	UpperCamelCase   (       lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if radius < 0:
    raise ValueError('''surface_area_hemisphere() only accepts non-negative values'''	)
  return 3 * pi * radius**2




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if radius < 0 or height < 0:
    raise ValueError('''surface_area_cone() only accepts non-negative values'''	)
  return pi * radius * (radius + (height**2 + radius**2) ** 0.5)




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if radius_a < 0 or radius_a < 0 or height < 0:
    raise ValueError(
        '''surface_area_conical_frustum() only accepts non-negative values'''	)
  lowercase									=(height**2 + (radius_a - radius_a) ** 2) ** 0.5
  return pi * ((slant_height * (radius_a + radius_a)) + radius_a**2 + radius_a**2)




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if radius < 0 or height < 0:
    raise ValueError('''surface_area_cylinder() only accepts non-negative values'''	)
  return 2 * pi * radius * (height + radius)




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if torus_radius < 0 or tube_radius < 0:
    raise ValueError('''surface_area_torus() only accepts non-negative values'''	)
  if torus_radius < tube_radius:
    raise ValueError(
        '''surface_area_torus() does not support spindle or self intersecting tori'''	)
  return 4 * pow(lowercase_     ,					2	) * torus_radius * tube_radius




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



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




def 	UpperCamelCase   (       lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if side_length < 0:
    raise ValueError('''area_square() only accepts non-negative values'''	)
  return side_length**2




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if base < 0 or height < 0:
    raise ValueError('''area_triangle() only accepts non-negative values'''	)
  return (base * height) / 2




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if sidea < 0 or sidea < 0 or sidea < 0:
    raise ValueError('''area_triangle_three_sides() only accepts non-negative values'''	)
  elif sidea + sidea < sidea or sidea + sidea < sidea or sidea + sidea < sidea:
    raise ValueError('''Given three sides do not form a triangle'''	)
  lowercase									=(sidea + sidea + sidea) / 2
  lowercase									=sqrt(
      semi_perimeter
      * (semi_perimeter - sidea)
      * (semi_perimeter - sidea)
      * (semi_perimeter - sidea)	)
  return area




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if base < 0 or height < 0:
    raise ValueError('''area_parallelogram() only accepts non-negative values'''	)
  return base * height




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if basea < 0 or basea < 0 or height < 0:
    raise ValueError('''area_trapezium() only accepts non-negative values'''	)
  return 1 / 2 * (basea + basea) * height




def 	UpperCamelCase   (       lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if radius < 0:
    raise ValueError('''area_circle() only accepts non-negative values'''	)
  return pi * radius**2




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if radius_x < 0 or radius_y < 0:
    raise ValueError('''area_ellipse() only accepts non-negative values'''	)
  return pi * radius_x * radius_y




def 	UpperCamelCase   (       lowercase_						:    float     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if diagonal_a < 0 or diagonal_a < 0:
    raise ValueError('''area_rhombus() only accepts non-negative values'''	)
  return 1 / 2 * diagonal_a * diagonal_a




def 	UpperCamelCase   (       lowercase_						:    int     ,					lowercase_						:    float	)		->	float:




  '''simple docstring'''



  if not isinstance(lowercase_     ,					lowercase_	) or sides < 3:
    raise ValueError(
        '''area_reg_polygon() only accepts integers greater than or \
equal to three as number of sides'''	)
  elif length < 0:
    raise ValueError(
        '''area_reg_polygon() only accepts non-negative values as \
length of a side'''	)
  return (sides * length**2) / (4 * tan(pi / sides	))
  return (sides * length**2) / (4 * tan(pi / sides	))


if __name__ == "__main__":
     import doctest

     doctest.testmod(verbose=True)  # verbose so we can see methods missing tests

     print('''[DEMO] Areas of various geometric shapes: \n''')
     print(F"""Rectangle: {area_rectangle(10, 20) = }""")
     print(F"""Square: {area_square(10) = }""")
     print(F"""Triangle: {area_triangle(10, 10) = }""")
     print(F"""Triangle: {area_triangle_three_sides(5, 12, 13) = }""")
     print(F"""Parallelogram: {area_parallelogram(10, 20) = }""")
     print(F"""Rhombus: {area_rhombus(10, 20) = }""")
     print(F"""Trapezium: {area_trapezium(10, 20, 30) = }""")
     print(F"""Circle: {area_circle(20) = }""")
     print(F"""Ellipse: {area_ellipse(10, 20) = }""")
     print('''\nSurface Areas of various geometric shapes: \n''')
     print(F"""Cube: {surface_area_cube(20) = }""")
     print(F"""Cuboid: {surface_area_cuboid(10, 20, 30) = }""")
     print(F"""Sphere: {surface_area_sphere(20) = }""")
     print(F"""Hemisphere: {surface_area_hemisphere(20) = }""")
     print(F"""Cone: {surface_area_cone(10, 20) = }""")
     print(F"""Conical Frustum: {surface_area_conical_frustum(10, 20, 30) = }""")
     print(F"""Cylinder: {surface_area_cylinder(10, 20) = }""")
     print(F"""Torus: {surface_area_torus(20, 10) = }""")
     print(F"""Equilateral Triangle: {area_reg_polygon(3, 10) = }""")
     print(F"""Square: {area_reg_polygon(4, 10) = }""")
     print(F"""Reqular Pentagon: {area_reg_polygon(5, 10) = }""")






import argparse
import os
import pickle
import sys

import torch

from transformers import TransfoXLConfig, TransfoXLLMHeadModel, load_tf_weights_in_transfo_xl
from transformers.models.transfo_xl import tokenization_transfo_xl as data_utils
from transformers.models.transfo_xl.tokenization_transfo_xl import CORPUS_NAME, VOCAB_FILES_NAMES
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()

# We do this to be able to load python 2 datasets pickles
# See e.g. https://stackoverflow.com/questions/2121874/python-pickling-after-changing-a-modules-directory/2121918#2121918
__magic_name__  :  Tuple					=       data_utils.TransfoXLTokenizer
__magic_name__  :  int					=       data_utils.TransfoXLCorpus
__magic_name__  :  List[str]					=       data_utils
__magic_name__  :  str					=       data_utils
def 		a_							( __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase				):
  if transfo_xl_dataset_file:
    # Convert a pre-processed corpus (see original TensorFlow repo)
    with open(__lowerCAmelCase   , '''rb'''				) as fp:
      lowerCAmelCase__										=      pickle.load(__lowerCAmelCase   , encoding='''latin1'''				)
    # Save vocabulary and dataset cache as Dictionaries (should be better than pickles for the long-term)
    lowerCAmelCase__										=      pytorch_dump_folder_path + '''/''' + VOCAB_FILES_NAMES['''pretrained_vocab_file''']
    print(F"""Save vocabulary to {pytorch_vocab_dump_path}"""				)
    lowerCAmelCase__										=      corpus.vocab.__dict__
    torch.save(__lowerCAmelCase   , __lowerCAmelCase				)

    lowerCAmelCase__										=      corpus.__dict__
    corpus_dict_no_vocab.pop('''vocab'''   , __lowerCAmelCase				)
    lowerCAmelCase__										=      pytorch_dump_folder_path + '''/''' + CORPUS_NAME
    print(F"""Save dataset to {pytorch_dataset_dump_path}"""				)
    torch.save(__lowerCAmelCase   , __lowerCAmelCase				)

  if tf_checkpoint_path:
    # Convert a pre-trained TensorFlow model
    lowerCAmelCase__										=      os.path.abspath(__lowerCAmelCase				)
    lowerCAmelCase__										=      os.path.abspath(__lowerCAmelCase				)

    print(F"""Converting Transformer XL checkpoint from {tf_path} with config at {config_path}."""				)
    # Initialise PyTorch model
    if transfo_xl_config_file == "":
      lowerCAmelCase__										=      TransfoXLConfig()
    else:
      lowerCAmelCase__										=      TransfoXLConfig.from_json_file(__lowerCAmelCase				)
    print(F"""Building PyTorch model from configuration: {config}"""				)
    lowerCAmelCase__										=      TransfoXLLMHeadModel(__lowerCAmelCase				)

    lowerCAmelCase__										=      load_tf_weights_in_transfo_xl(__lowerCAmelCase   , __lowerCAmelCase   , __lowerCAmelCase				)
    # Save pytorch-model
    lowerCAmelCase__										=      os.path.join(__lowerCAmelCase   , __lowerCAmelCase				)
    lowerCAmelCase__										=      os.path.join(__lowerCAmelCase   , __lowerCAmelCase				)
    print(F"""Save PyTorch model to {os.path.abspath(__lowerCAmelCase				)}"""				)
    torch.save(model.state_dict()   , __lowerCAmelCase				)
    print(F"""Save configuration file to {os.path.abspath(__lowerCAmelCase				)}"""				)
    with open(__lowerCAmelCase   , '''w'''   , encoding='''utf-8'''				) as f:
      f.write(config.to_json_string()				)


if __name__ == "__main__":
      __magic_name__  :  int					=       argparse.ArgumentParser()
      parser.add_argument(
          """--pytorch_dump_folder_path""",
          default=None,
          type=str,
          required=True,
          help="""Path to the folder to store the PyTorch model or dataset/vocab.""",
      )
      parser.add_argument(
          """--tf_checkpoint_path""",
          default="""""",
          type=str,
          help="""An optional path to a TensorFlow checkpoint path to be converted.""",
      )
      parser.add_argument(
          """--transfo_xl_config_file""",
          default="""""",
          type=str,
          help=(
              """An optional config json file corresponding to the pre-trained BERT model. \n"""
              """This specifies the model architecture."""
          ),
      )
      parser.add_argument(
          """--transfo_xl_dataset_file""",
          default="""""",
          type=str,
          help="""An optional dataset file to be converted in a vocabulary.""",
      )
      __magic_name__  :  Optional[Any]					=       parser.parse_args()
      convert_transfo_xl_checkpoint_to_pytorch(
          args.tf_checkpoint_path,
          args.transfo_xl_config_file,
          args.pytorch_dump_folder_path,
          args.transfo_xl_dataset_file,
      )

