






"""simple docstring"""



import os
import re
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


a  :						Union[str, Any]					       =							logging.get_logger(__name__)
a  :						Optional[Any]					       =							{'''vocab_file''': '''spiece.model'''}

a  :						Tuple					       =							{
    '''vocab_file''': {
        '''google/fnet-base''': '''https://huggingface.co/google/fnet-base/resolve/main/spiece.model''',
        '''google/fnet-large''': '''https://huggingface.co/google/fnet-large/resolve/main/spiece.model''',
    },
}

a  :						List[str]					       =							{
    '''google/fnet-base''': 512,
    '''google/fnet-large''': 512,
}

a  :						str					       =							'''▁'''


class 	_UpperCamelCase ( __UpperCamelCase							):



    '''simple docstring'''


    __lowercase    :   List[Any]											=						VOCAB_FILES_NAMES
    __lowercase    :   int											=						PRETRAINED_VOCAB_FILES_MAP
    __lowercase    :   Any											=						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    __lowercase    :   List[str]											=						['input_ids', 'token_type_ids']


    def __init__(      self   ,			__lowercase   ,			__lowercase=False   ,			__lowercase=True   ,			__lowercase=True   ,			__lowercase="<unk>"   ,			__lowercase="[SEP]"   ,			__lowercase="<pad>"   ,			__lowercase="[CLS]"   ,			__lowercase="[MASK]"   ,			__lowercase = None   ,			**__lowercase   ,			):
     # Mask token behave like a normal word, i.e. include the space before it and
     # is included in the raw text, there should be a match in a non-normalized sentence.
     UpperCAmelCase__ 						=				(
         AddedToken(__lowercase   ,			lstrip=__lowercase   ,			rstrip=__lowercase   ,			normalized=__lowercase			)
         if isinstance(__lowercase   ,			__lowercase			)
         else mask_token
     )

     UpperCAmelCase__ 						=				{} if sp_model_kwargs is None else sp_model_kwargs

     super().__init__(
         do_lower_case=__lowercase   ,			remove_space=__lowercase   ,			keep_accents=__lowercase   ,			unk_token=__lowercase   ,			sep_token=__lowercase   ,			pad_token=__lowercase   ,			cls_token=__lowercase   ,			mask_token=__lowercase   ,			sp_model_kwargs=self.sp_model_kwargs   ,			**__lowercase   ,			)

     UpperCAmelCase__ 						=				do_lower_case
     UpperCAmelCase__ 						=				remove_space
     UpperCAmelCase__ 						=				keep_accents
     UpperCAmelCase__ 						=				vocab_file

     UpperCAmelCase__ 						=				spm.SentencePieceProcessor(**self.sp_model_kwargs			)
     self.sp_model.Load(__lowercase			)


    @property
    def 		A__      (      self			):
     return len(self.sp_model			)


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				{self.convert_ids_to_tokens(__lowercase			): i for i in range(self.vocab_size			)}
     vocab.update(self.added_tokens_encoder			)
     return vocab


    def __getstate__(      self			):
     UpperCAmelCase__ 						=				self.__dict__.copy()
     UpperCAmelCase__ 						=				None
     return state


    def __setstate__(      self   ,			__lowercase			):
     UpperCAmelCase__ 						=				d

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

     UpperCAmelCase__ 						=				spm.SentencePieceProcessor(**self.sp_model_kwargs			)
     self.sp_model.Load(self.vocab_file			)


    def 		A__      (      self   ,			__lowercase			):
     if self.remove_space:
      UpperCAmelCase__ 						=				""" """.join(inputs.strip().split()			)
     else:
      UpperCAmelCase__ 						=				inputs
     UpperCAmelCase__ 						=				outputs.replace("""``"""   ,			"""\""""			).replace("""''"""   ,			"""\""""			)

     if not self.keep_accents:
      UpperCAmelCase__ 						=				unicodedata.normalize("""NFKD"""   ,			__lowercase			)
      UpperCAmelCase__ 						=				"""""".join([c for c in outputs if not unicodedata.combining(__lowercase			)]			)
     if self.do_lower_case:
      UpperCAmelCase__ 						=				outputs.lower()

     return outputs


    def 		A__      (      self   ,			__lowercase			):
     UpperCAmelCase__ 						=				self.preprocess_text(__lowercase			)
     UpperCAmelCase__ 						=				self.sp_model.encode(__lowercase   ,			out_type=__lowercase			)
     UpperCAmelCase__ 						=				[]
     for piece in pieces:
      if len(__lowercase			) > 1 and piece[-1] == str(""","""			) and piece[-2].isdigit():
       UpperCAmelCase__ 						=				self.sp_model.EncodeAsPieces(piece[:-1].replace(__lowercase   ,			""""""			)			)
       if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
        if len(cur_pieces[0]			) == 1:
         UpperCAmelCase__ 						=				cur_pieces[1:]
        else:
         UpperCAmelCase__ 						=				cur_pieces[0][1:]
       cur_pieces.append(piece[-1]			)
       new_pieces.extend(__lowercase			)
      else:
       new_pieces.append(__lowercase			)

     return new_pieces


    def 		A__      (      self   ,			__lowercase			):
     return self.sp_model.PieceToId(__lowercase			)


    def 		A__      (      self   ,			__lowercase			):
     return self.sp_model.IdToPiece(__lowercase			)


    def 		A__      (      self   ,			__lowercase			):
     UpperCAmelCase__ 						=				[]
     UpperCAmelCase__ 						=				""""""
     UpperCAmelCase__ 						=				False
     for token in tokens:
      # make sure that special tokens are not decoded using sentencepiece model
      if token in self.all_special_tokens:
       if not prev_is_special:
        out_string += " "
       out_string += self.sp_model.decode(__lowercase			) + token
       UpperCAmelCase__ 						=				True
       UpperCAmelCase__ 						=				[]
      else:
       current_sub_tokens.append(__lowercase			)
       UpperCAmelCase__ 						=				False
     out_string += self.sp_model.decode(__lowercase			)
     return out_string.strip()


    def 		A__      (      self   ,			__lowercase   ,			__lowercase = False   ,			__lowercase = None   ,			__lowercase = True   ,			**__lowercase   ,			):
     UpperCAmelCase__ 						=				kwargs.pop("""use_source_tokenizer"""   ,			__lowercase			)

     UpperCAmelCase__ 						=				self.convert_ids_to_tokens(__lowercase   ,			skip_special_tokens=__lowercase			)

     # To avoid mixing byte-level and unicode for byte-level BPT
     # we need to build string separately for added tokens and byte-level tokens
     # cf. https://github.com/huggingface/transformers/issues/1133
     UpperCAmelCase__ 						=				[]
     UpperCAmelCase__ 						=				[]
     for token in filtered_tokens:
      if skip_special_tokens and token in self.all_special_ids:
       continue
      if token in self.added_tokens_encoder:
       if current_sub_text:
        sub_texts.append(self.convert_tokens_to_string(__lowercase			)			)
        UpperCAmelCase__ 						=				[]
       sub_texts.append(__lowercase			)
      else:
       current_sub_text.append(__lowercase			)
     if current_sub_text:
      sub_texts.append(self.convert_tokens_to_string(__lowercase			)			)

     # Mimic the behavior of the Rust tokenizer:
     # No space after <unk>
     if spaces_between_special_tokens:
      UpperCAmelCase__ 						=				re.sub(r"""(<unk>) """   ,			r"""\1"""   ,			""" """.join(__lowercase			)			)
     else:
      UpperCAmelCase__ 						=				"""""".join(__lowercase			)

     UpperCAmelCase__ 						=				(
         clean_up_tokenization_spaces
         if clean_up_tokenization_spaces is not None
         else self.clean_up_tokenization_spaces
     )
     if clean_up_tokenization_spaces:
      UpperCAmelCase__ 						=				self.clean_up_tokenization(__lowercase			)
      return clean_text
     else:
      return text


    def 		A__      (      self   ,			__lowercase   ,			__lowercase = None			):
     UpperCAmelCase__ 						=				[self.sep_token_id]
     UpperCAmelCase__ 						=				[self.cls_token_id]
     if token_ids_a is None:
      return cls + token_ids_a + sep
     return cls + token_ids_a + sep + token_ids_a + sep


    def 		A__      (      self   ,			__lowercase   ,			__lowercase = None   ,			__lowercase = False			):

     if already_has_special_tokens:
      return super().get_special_tokens_mask(
          token_ids_a=__lowercase   ,			token_ids_a=__lowercase   ,			already_has_special_tokens=__lowercase			)

     if token_ids_a is not None:
      return [1] + ([0] * len(__lowercase			)) + [1] + ([0] * len(__lowercase			)) + [1]
     return [1] + ([0] * len(__lowercase			)) + [1]


    def 		A__      (      self   ,			__lowercase   ,			__lowercase = None			):
     UpperCAmelCase__ 						=				[self.sep_token_id]
     UpperCAmelCase__ 						=				[self.cls_token_id]

     if token_ids_a is None:
      return len(cls + token_ids_a + sep			) * [0]
     return len(cls + token_ids_a + sep			) * [0] + len(token_ids_a + sep			) * [1]






    def 		A__      (      self   ,			__lowercase   ,			__lowercase = None			):
     if not os.path.isdir(__lowercase			):
      logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''			)
      return
     UpperCAmelCase__ 						=				os.path.join(
         __lowercase   ,			(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]			)

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

     return (out_vocab_file,)











"""simple docstring"""



from __future__ import annotations

from math import pi, pow




def       snake_case__		(   _SCREAMING_SNAKE_CASE			)    ->float:
 if side_length < 0:
  raise ValueError("""vol_cube() only accepts non-negative values"""			)
 return pow(_SCREAMING_SNAKE_CASE       ,	3			)




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->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(_SCREAMING_SNAKE_CASE       ,	2			) * (3 * radius - height)




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->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(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)			)

 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(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			) + vol_spherical_cap(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->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(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)			)

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




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




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->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__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->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__		(   _SCREAMING_SNAKE_CASE			)    ->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(_SCREAMING_SNAKE_CASE       ,	3			)




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




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->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(_SCREAMING_SNAKE_CASE       ,	2			) * height * pi




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->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(_SCREAMING_SNAKE_CASE       ,	2			) - pow(_SCREAMING_SNAKE_CASE       ,	2			)) * height




def       snake_case__		(   _SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE			)    ->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(_SCREAMING_SNAKE_CASE       ,	2			) + pow(_SCREAMING_SNAKE_CASE       ,	2			) + radius_a * radius_a)
 )




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




def       snake_case__		(   )    ->str:
 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()



