





from math import pi, sqrt, tan






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if side_length < 0:
  raise ValueError("""surface_area_cube() only accepts non-negative values"""   )
 return 6 * side_length**2






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 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 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if radius < 0:
  raise ValueError("""surface_area_sphere() only accepts non-negative values"""   )
 return 4 * pi * radius**2






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if radius < 0:
  raise ValueError("""surface_area_hemisphere() only accepts non-negative values"""   )
 return 3 * pi * radius**2






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 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 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if radius_a < 0 or radius_a < 0 or height < 0:
  raise ValueError(
      """surface_area_conical_frustum() only accepts non-negative values"""   )
 __lowerCAmelCase					:	Any      =       (height**2 + (radius_a - radius_a) ** 2) ** 0.5
 return pi * ((slant_height * (radius_a + radius_a)) + radius_a**2 + radius_a**2)






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if radius < 0 or height < 0:
  raise ValueError("""surface_area_cylinder() only accepts non-negative values"""   )
 return 2 * pi * radius * (height + radius)






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 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(SCREAMING_SNAKE_CASE   ,   2   ) * torus_radius * tube_radius






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if length < 0 or width < 0:
  raise ValueError("""area_rectangle() only accepts non-negative values"""   )
 return length * width






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if side_length < 0:
  raise ValueError("""area_square() only accepts non-negative values"""   )
 return side_length**2






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if base < 0 or height < 0:
  raise ValueError("""area_triangle() only accepts non-negative values"""   )
 return (base * height) / 2






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 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"""   )
 __lowerCAmelCase					:	List[str]      =       (sidea + sidea + sidea) / 2
 __lowerCAmelCase					:	Dict      =       sqrt(
     semi_perimeter
     * (semi_perimeter - sidea)
     * (semi_perimeter - sidea)
     * (semi_perimeter - sidea)   )
 return area






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if base < 0 or height < 0:
  raise ValueError("""area_parallelogram() only accepts non-negative values"""   )
 return base * height






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 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 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if radius < 0:
  raise ValueError("""area_circle() only accepts non-negative values"""   )
 return pi * radius**2






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if radius_x < 0 or radius_y < 0:
  raise ValueError("""area_ellipse() only accepts non-negative values"""   )
 return pi * radius_x * radius_y






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:float   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 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 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:int   ,   SCREAMING_SNAKE_CASE		:float   )      ->   float:
 if not isinstance(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ) 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 os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


_UpperCAmelCase             =							'▁'

_UpperCAmelCase             =							{'vocab_file': 'spiece.model'}

_UpperCAmelCase             =							{
    'vocab_file': {'google/pegasus-xsum': 'https://huggingface.co/google/pegasus-xsum/resolve/main/spiece.model'}
}

_UpperCAmelCase             =							{
    'google/pegasus-xsum': 512,
}


_UpperCAmelCase             =							logging.get_logger(__name__)






class        snake_case_    (		__lowercase						):
  A_      							=   VOCAB_FILES_NAMES

  A_      							=   VOCAB_FILES_NAMES
  A_      							=   PRETRAINED_VOCAB_FILES_MAP
  A_      							=   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  A_      							=   ['input_ids', 'attention_mask']






  def __init__(							self			:					List[Any]       ,  _snake_case			:					Union[str, Any]       ,  _snake_case			:					Union[str, Any]="<pad>"       ,  _snake_case			:					int="</s>"       ,  _snake_case			:					Any="<unk>"       ,  _snake_case			:					Union[str, Any]="<mask_2>"       ,  _snake_case			:					Any="<mask_1>"       ,  _snake_case			:					Optional[int]=None       ,  _snake_case			:					List[str]=103       ,  _snake_case			:					Optional[Dict[str, Any]] = None       ,  **_snake_case			:					Optional[int]       ,  )->None:






   '''simple docstring'''

   __lowerCAmelCase					:	Union[str, Any]      =       offset
   if additional_special_tokens is not None:
    if not isinstance(_snake_case       ,  _snake_case      ):
     raise TypeError(
         F'''additional_special_tokens should be of type {type(_snake_case      )}, but is'''
         F''' {type(_snake_case      )}'''      )

    __lowerCAmelCase					:	List[str]      =       (
        ([mask_token_sent] + additional_special_tokens)
        if mask_token_sent not in additional_special_tokens and mask_token_sent is not None
        else additional_special_tokens
    )
    # fill additional tokens with ..., <unk_token_102> in case not all additional tokens are already taken
    additional_special_tokens_extended += [
        F'''<unk_{i}>''' for i in range(len(_snake_case      )       ,  self.offset - 1      )
    ]

    if len(set(_snake_case      )      ) != len(_snake_case      ):
     raise ValueError(
         """Please make sure that the provided additional_special_tokens do not contain an incorrectly"""
         F''' shifted list of <unk_x> tokens. Found {additional_special_tokens_extended}.'''      )
    __lowerCAmelCase					:	Dict      =       additional_special_tokens_extended
   else:
    __lowerCAmelCase					:	Tuple      =       [mask_token_sent] if mask_token_sent is not None else []
    additional_special_tokens += [F'''<unk_{i}>''' for i in range(2       ,  self.offset      )]

   __lowerCAmelCase					:	Optional[int]      =       {} if sp_model_kwargs is None else sp_model_kwargs

   super().__init__(
       eos_token=_snake_case       ,  unk_token=_snake_case       ,  mask_token=_snake_case       ,  pad_token=_snake_case       ,  mask_token_sent=_snake_case       ,  offset=_snake_case       ,  additional_special_tokens=_snake_case       ,  sp_model_kwargs=self.sp_model_kwargs       ,  **_snake_case       ,  )
   __lowerCAmelCase					:	Optional[Any]      =       mask_token_sent
   __lowerCAmelCase					:	Any      =       vocab_file
   __lowerCAmelCase					:	Any      =       spm.SentencePieceProcessor(**self.sp_model_kwargs      )
   self.sp_model.Load(_snake_case      )

   # add special tokens to encoder dict
   __lowerCAmelCase					:	Dict[int, str]      =       {
       0: self.pad_token,
       1: self.eos_token,
   }

   if self.mask_token_sent is not None:
    self.encoder.update(
        {
            2: self.mask_token_sent,
            3: self.mask_token,
        }      )

   if self.offset > 0:
    # entries 2-104 are only used for pretraining and called <mask_1>, <mask_2>, unk_2, ...unk_102
    # mask_token_sent is already added to list -> so start at 1
    self.encoder.update({i + 3: additional_special_tokens[i] for i in range(1       ,  self.offset - 1      )}      )

   __lowerCAmelCase					:	Dict[str, int]      =       {v: k for k, v in self.encoder.items()}






  @property
  def 				UpperCAmelCase__						(							self			:					str      )->int:






   '''simple docstring'''

   return len(self.sp_model      ) + self.offset






  def 				UpperCAmelCase__						(							self			:					Dict      )->Dict[str, int]:






   '''simple docstring'''

   __lowerCAmelCase					:	Tuple      =       {self.convert_ids_to_tokens(_snake_case      ): i for i in range(self.vocab_size      )}
   vocab.update(self.added_tokens_encoder      )
   return vocab






  def __getstate__(							self			:					Optional[int]      )->str:






   '''simple docstring'''

   __lowerCAmelCase					:	Optional[Any]      =       self.__dict__.copy()
   __lowerCAmelCase					:	Union[str, Any]      =       None
   return state






  def __setstate__(							self			:					Any       ,  _snake_case			:					str      )->Any:






   '''simple docstring'''

   __lowerCAmelCase					:	str      =       d

   # for backward compatibility
   if not hasattr(self       ,  """sp_model_kwargs"""      ):
    __lowerCAmelCase					:	Any      =       {}

   __lowerCAmelCase					:	Optional[int]      =       spm.SentencePieceProcessor(**self.sp_model_kwargs      )
   self.sp_model.Load(self.vocab_file      )






  def 				UpperCAmelCase__						(							self			:					Dict       ,  _snake_case			:					str      )->List[str]:






   '''simple docstring'''

   return self.sp_model.encode(_snake_case       ,  out_type=_snake_case      )






  def 				UpperCAmelCase__						(							self			:					Tuple       ,  _snake_case			:					str      )->int:






   '''simple docstring'''

   if token in self.decoder:
    return self.decoder[token]
   elif token in self.added_tokens_decoder:
    return self.added_tokens_decoder[token]
   __lowerCAmelCase					:	Any      =       self.sp_model.piece_to_id(_snake_case      )
   return sp_id + self.offset






  def 				UpperCAmelCase__						(							self			:					List[Any]       ,  _snake_case			:					int      )->str:






   '''simple docstring'''

   if index in self.encoder:
    return self.encoder[index]
   elif index in self.added_tokens_encoder:
    return self.added_tokens_encoder[index]
   else:
    __lowerCAmelCase					:	Optional[int]      =       self.sp_model.IdToPiece(index - self.offset      )
   return token






  def 				UpperCAmelCase__						(							self			:					Union[str, Any]       ,  _snake_case			:					Optional[int]      )->List[str]:






   '''simple docstring'''

   __lowerCAmelCase					:	Any      =       []
   __lowerCAmelCase					:	Dict      =       """"""
   for token in tokens:
    # make sure that special tokens are not decoded using sentencepiece model
    if token in self.all_special_tokens:
     out_string += self.sp_model.decode(_snake_case      ) + token
     __lowerCAmelCase					:	int      =       []
    else:
     current_sub_tokens.append(_snake_case      )
   out_string += self.sp_model.decode(_snake_case      )
   return out_string.strip()






  def 				UpperCAmelCase__						(							self			:					Optional[int]       ,  _snake_case			:					Dict=False      )->int:






   '''simple docstring'''

   return 1






  def 				UpperCAmelCase__						(							self			:					Tuple       ,  _snake_case			:					Tuple      )->str:






   '''simple docstring'''

   __lowerCAmelCase					:	List[Any]      =       set(self.all_special_ids      )  # call it once instead of inside list comp
   all_special_ids.remove(self.unk_token_id      )  # <unk> is only sometimes special

   return [1 if x in all_special_ids else 0 for x in seq]






  def 				UpperCAmelCase__						(							self			:					List[str]       ,  _snake_case			:					List       ,  _snake_case			:					Optional[List] = None       ,  _snake_case			:					bool = False      )->List[int]:






   '''simple docstring'''

   if already_has_special_tokens:
    return self._special_token_mask(_snake_case      )
   elif token_ids_a is None:
    return self._special_token_mask(_snake_case      ) + [1]
   else:
    return self._special_token_mask(token_ids_a + token_ids_a      ) + [1]






  def 				UpperCAmelCase__						(							self			:					Any       ,  _snake_case			:					Union[str, Any]       ,  _snake_case			:					Tuple=None      )->List[int]:






   '''simple docstring'''

   if token_ids_a is None:
    return token_ids_a + [self.eos_token_id]
   # We don't expect to process pairs, but leave the pair logic for API consistency
   return token_ids_a + token_ids_a + [self.eos_token_id]






  def 				UpperCAmelCase__						(							self			:					Any       ,  _snake_case			:					str       ,  _snake_case			:					Optional[str] = None      )->Tuple[str]:






   '''simple docstring'''

   if not os.path.isdir(_snake_case      ):
    logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''      )
    return
   __lowerCAmelCase					:	Optional[int]      =       os.path.join(
       _snake_case       ,  (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]      )

   if os.path.abspath(self.vocab_file      ) != os.path.abspath(_snake_case      ) and os.path.isfile(self.vocab_file      ):
    copyfile(self.vocab_file       ,  _snake_case      )
   elif not os.path.isfile(self.vocab_file      ):
    with open(_snake_case       ,  """wb"""      ) as fi:
     __lowerCAmelCase					:	Tuple      =       self.sp_model.serialized_model_proto()
     fi.write(_snake_case      )

   return (out_vocab_file,)