






'''simple docstring'''





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


__A							:							Any  							=		logging.get_logger(__name__)

__A							:							str  							=		"""▁"""

__A							:							Optional[Any]  							=		{"""vocab_file""": """sentencepiece.bpe.model"""}

__A							:							Any  							=		{
    """vocab_file""": {
        """facebook/xglm-564M""": """https://huggingface.co/facebook/xglm-564M/resolve/main/sentencepiece.bpe.model""",
    }
}

__A							:							int  							=		{
    """facebook/xglm-564M""": 20_48,
}
class 				lowercase       (							_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							VOCAB_FILES_NAMES
    lowerCAmelCase__      				=							PRETRAINED_VOCAB_FILES_MAP
    lowerCAmelCase__      				=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    lowerCAmelCase__      				=							["input_ids", "attention_mask"]

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

     '''simple docstring'''




     lowerCamelCase__  =     {} if sp_model_kwargs is None else sp_model_kwargs

     # Compatibility with the original tokenizer
     lowerCamelCase__  =     7
     lowerCamelCase__  =     [f'''<madeupword{i}>''' for i in range(self.num_madeup_words     )]

     lowerCamelCase__  =     kwargs.get("additional_special_tokens"				,     []     )
     kwargs["additional_special_tokens"] += [
         word for word in madeup_words if word not in kwargs["additional_special_tokens"]
     ]

     super().__init__(
         bos_token=__lowerCamelCase				,     eos_token=__lowerCamelCase				,     unk_token=__lowerCamelCase				,     sep_token=__lowerCamelCase				,     cls_token=__lowerCamelCase				,     pad_token=__lowerCamelCase				,     sp_model_kwargs=self.sp_model_kwargs				,     **__lowerCamelCase				,     )

     lowerCamelCase__  =     spm.SentencePieceProcessor(**self.sp_model_kwargs     )
     self.sp_model.Load(str(__lowerCamelCase     )     )
     lowerCamelCase__  =     vocab_file

     # Original fairseq vocab and spm vocab must be "aligned":
     # Vocab    |    0    |    1    |   2    |    3    |  4  |  5  |  6  |   7   |   8   |  9
     # -------- | ------- | ------- | ------ | ------- | --- | --- | --- | ----- | ----- | ----
     # fairseq  | '<s>'   | '<pad>' | '</s>' | '<unk>' | ',' | '.' | '▁' | 's'   | '▁de' | '-'
     # spm      | '<unk>' | '<s>'   | '</s>' | ','     | '.' | '▁' | 's' | '▁de' | '-'   | '▁a'

     # The first "real" token "," has position 4 in the original fairseq vocab and position 3 in the spm vocab
     lowerCamelCase__  =     1

     # Mimic fairseq token-to-id alignment for the first 4 token
     lowerCamelCase__  =     {"<s>": 0, "<pad>": 1, "</s>": 2, "<unk>": 3}

     lowerCamelCase__  =     len(self.sp_model     )
     lowerCamelCase__  =     {f'''<madeupword{i}>''': sp_size + i + self.fairseq_offset for i in range(self.num_madeup_words     )}
     self.fairseq_tokens_to_ids.update(__lowerCamelCase     )

     lowerCamelCase__  =     {v: k for k, v in self.fairseq_tokens_to_ids.items()}

    def __getstate__(					self     :     Dict     )							->							Optional[Any]:

     '''simple docstring'''




     lowerCamelCase__  =     self.__dict__.copy()
     lowerCamelCase__  =     None
     lowerCamelCase__  =     self.sp_model.serialized_model_proto()
     return state

    def __setstate__(					self     :     List[Any]				,     __lowerCamelCase     :     int     )							->							Any:

     '''simple docstring'''




     lowerCamelCase__  =     d

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

     lowerCamelCase__  =     spm.SentencePieceProcessor(**self.sp_model_kwargs     )
     self.sp_model.LoadFromSerializedProto(self.sp_model_proto     )

    def    a__				(					self     :     str				,     __lowerCamelCase     :     List[int]				,     __lowerCamelCase     :     Optional[List[int]] = None     )							->							List[int]:

     '''simple docstring'''




     if token_ids_a is None:
      return [self.sep_token_id] + token_ids_a
     lowerCamelCase__  =     [self.sep_token_id]
     return sep + token_ids_a + sep + sep + token_ids_a

    def    a__				(					self     :     Any				,     __lowerCamelCase     :     List[int]				,     __lowerCamelCase     :     Optional[List[int]] = None				,     __lowerCamelCase     :     bool = False     )							->							List[int]:

     '''simple docstring'''




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

     if token_ids_a is None:
      return [1] + ([0] * len(__lowerCamelCase     ))
     return [1] + ([0] * len(__lowerCamelCase     )) + [1, 1] + ([0] * len(__lowerCamelCase     ))

    def    a__				(					self     :     str				,     __lowerCamelCase     :     List[int]				,     __lowerCamelCase     :     Optional[List[int]] = None     )							->							List[int]:

     '''simple docstring'''




     lowerCamelCase__  =     [self.sep_token_id]

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

    @property
    def    a__				(					self     :     Any     )							->							Dict:

     '''simple docstring'''




     return len(self.sp_model     ) + self.fairseq_offset + self.num_madeup_words

    def    a__				(					self     :     Optional[Any]     )							->							Optional[Any]:

     '''simple docstring'''




     lowerCamelCase__  =     {self.convert_ids_to_tokens(__lowerCamelCase     ): i for i in range(self.vocab_size     )}
     vocab.update(self.added_tokens_encoder     )
     return vocab

    def    a__				(					self     :     Union[str, Any]				,     __lowerCamelCase     :     str     )							->							List[str]:

     '''simple docstring'''




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

    def    a__				(					self     :     List[Any]				,     __lowerCamelCase     :     Optional[int]     )							->							List[Any]:

     '''simple docstring'''




     if token in self.fairseq_tokens_to_ids:
      return self.fairseq_tokens_to_ids[token]
     lowerCamelCase__  =     self.sp_model.PieceToId(__lowerCamelCase     )

     # Need to return unknown token if the SP model returned 0
     return spm_id + self.fairseq_offset if spm_id else self.unk_token_id

    def    a__				(					self     :     Tuple				,     __lowerCamelCase     :     int     )							->							str:

     '''simple docstring'''




     if index in self.fairseq_ids_to_tokens:
      return self.fairseq_ids_to_tokens[index]
     return self.sp_model.IdToPiece(index - self.fairseq_offset     )

    def    a__				(					self     :     Tuple				,     __lowerCamelCase     :     Optional[int]     )							->							List[Any]:

     '''simple docstring'''




     lowerCamelCase__  =     "".join(__lowerCamelCase     ).replace(__lowerCamelCase				,     " "     ).strip()
     return out_string




    def    a__				(					self     :     List[Any]				,     __lowerCamelCase     :     str				,     __lowerCamelCase     :     Optional[str] = None     )							->							Tuple[str]:

     '''simple docstring'''




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

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

     return (out_vocab_file,)













'''simple docstring'''





from decimal import Decimal, getcontext
from math import ceil, factorial






def    lowerCamelCase_     (    lowercase__):

 if not isinstance(lowercase__				,     lowercase__):
  raise TypeError("Undefined for non-integers")
 elif precision < 1:
  raise ValueError("Undefined for non-natural numbers")

 lowerCamelCase__  =     precision
 lowerCamelCase__  =     ceil(precision / 14)
 lowerCamelCase__  =     426880 * Decimal(10005).sqrt()
 lowerCamelCase__  =     1
 lowerCamelCase__  =     13591409
 lowerCamelCase__  =     Decimal(lowercase__)
 for k in range(1				,     lowercase__):
  lowerCamelCase__  =     factorial(6 * k) // (factorial(3 * k) * factorial(lowercase__) ** 3)
  linear_term += 545140134
  exponential_term *= -262537412640768000
  partial_sum += Decimal(multinomial_term * linear_term) / exponential_term
 return str(constant_term / partial_sum)[:-1]


if __name__ == "__main__":
 __A							:							Dict  							=		50
 print(F"""The first {n} digits of pi is: {pi(n)}""")

