def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__						)					->       float:





       """simple docstring"""


       if discount_rate < 0:
              raise ValueError("Discount rate cannot be negative"						)
       if not cash_flows:
              raise ValueError("Cash flows list cannot be empty"						)
       __UpperCAmelCase  :				Tuple       				=		sum(
           cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(lowerCamelCase__						)						)
       return round(lowerCamelCase__							,    ndigits=2						)


if __name__ == "__main__":
   import doctest

   doctest.testmod()







'''simple docstring'''




import json
import re
from typing import TYPE_CHECKING, List, Optional, Tuple, Union

import numpy as np

from ...utils import is_tf_available, is_torch_available, logging


if TYPE_CHECKING:
   if is_torch_available():
      import torch
   if is_tf_available():
      import tensorflow as tf

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_codegen import CodeGenTokenizer


_a   :	Union[str, Any] 							=   logging.get_logger(__name__)

_a   :	Any 							=   {"vocab_file": "vocab.json", "merges_file": "merges.txt", "tokenizer_file": "tokenizer.json"}

_a   :	Tuple 							=   {
    "vocab_file": {
        "Salesforce/codegen-350M-mono": "https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/vocab.json",
    },
    "merges_file": {
        "Salesforce/codegen-350M-mono": "https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/merges.txt",
    },
    "tokenizer_file": {
        "Salesforce/codegen-350M-mono": (
            "https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/tokenizer.json"
        ),
    },
}

_a   :	Dict 							=   {
    "Salesforce/codegen-350M-mono": 2048,
}






class 		__A       (__magic_name__   ):
       snake_case       :Optional[Any]				    =					VOCAB_FILES_NAMES
       snake_case       :str				    =					PRETRAINED_VOCAB_FILES_MAP
       snake_case       :Optional[Any]				    =					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       snake_case       :Tuple				    =					["input_ids", "attention_mask"]
       snake_case       :Dict				    =					CodeGenTokenizer






       def __init__(      self				,     UpperCamelCase_=None				,     UpperCamelCase_=None				,     UpperCamelCase_=None				,     UpperCamelCase_="<|endoftext|>"				,     UpperCamelCase_="<|endoftext|>"				,     UpperCamelCase_="<|endoftext|>"				,     UpperCamelCase_=False				,     **UpperCamelCase_				,     ):
              super().__init__(
                  UpperCamelCase_				,     UpperCamelCase_				,     tokenizer_file=UpperCamelCase_				,     unk_token=UpperCamelCase_				,     bos_token=UpperCamelCase_				,     eos_token=UpperCamelCase_				,     add_prefix_space=UpperCamelCase_				,     **UpperCamelCase_				,     )

              if kwargs.pop("add_bos_token"				,     UpperCamelCase_      ):
                     __UpperCAmelCase  :				int       				=		kwargs.pop("name_or_path"				,     ""      )
                     raise ValueError(
                         "Currenty GPT2's fast tokenizer does NOT support adding a BOS token."
                         "Instead you should use GPT2's slow tokenizer class `CodeGenTokenizer` as follows: \n"
                         f"""`CodeGenTokenizer.from_pretrained('{model_id}')`\nor\n"""
                         f"""`AutoTokenizer.from_pretrained('{model_id}', use_fast=False)`\n"""
                         "This issue will be fixed soon, see: https://github.com/huggingface/tokenizers/pull/1005."
                         " so that the fast tokenizer works correctly."      )

              __UpperCAmelCase  :				Any       				=		json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()      )
              if pre_tok_state.get("add_prefix_space"				,     UpperCamelCase_      ) != add_prefix_space:
                     __UpperCAmelCase  :				str       				=		getattr(UpperCamelCase_				,     pre_tok_state.pop("type"      )      )
                     __UpperCAmelCase  :				Optional[int]       				=		add_prefix_space
                     __UpperCAmelCase  :				Tuple       				=		pre_tok_class(**UpperCamelCase_      )

              __UpperCAmelCase  :				Tuple       				=		add_prefix_space






       def 			_snake_case						(      self				,     *UpperCamelCase_				,     **UpperCamelCase_      ):
              __UpperCAmelCase  :				Optional[Any]       				=		kwargs.get("is_split_into_words"				,     UpperCamelCase_      )
              assert self.add_prefix_space or not is_split_into_words, (
                  f"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
                  "to use it with pretokenized inputs."
              )

              return super()._batch_encode_plus(*UpperCamelCase_				,     **UpperCamelCase_      )






       def 			_snake_case						(      self				,     *UpperCamelCase_				,     **UpperCamelCase_      ):
              __UpperCAmelCase  :				Any       				=		kwargs.get("is_split_into_words"				,     UpperCamelCase_      )

              assert self.add_prefix_space or not is_split_into_words, (
                  f"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
                  "to use it with pretokenized inputs."
              )

              return super()._encode_plus(*UpperCamelCase_				,     **UpperCamelCase_      )






       def 			_snake_case						(      self				,     UpperCamelCase_				,     UpperCamelCase_ = None      ):
              __UpperCAmelCase  :				int       				=		self._tokenizer.model.save(UpperCamelCase_				,     name=UpperCamelCase_      )
              return tuple(UpperCamelCase_      )






       def 			_snake_case						(      self				,     UpperCamelCase_				,     UpperCamelCase_ = False				,     UpperCamelCase_ = None				,     UpperCamelCase_ = None				,     **UpperCamelCase_				,     ):
              __UpperCAmelCase  :				str       				=		super().decode(
                  token_ids=UpperCamelCase_				,     skip_special_tokens=UpperCamelCase_				,     clean_up_tokenization_spaces=UpperCamelCase_				,     **UpperCamelCase_				,     )

              if truncate_before_pattern is not None and len(UpperCamelCase_      ) > 0:
                     __UpperCAmelCase  :				Union[str, Any]       				=		self.truncate(UpperCamelCase_				,     UpperCamelCase_      )

              return decoded_text







       def 			_snake_case						(      self				,     UpperCamelCase_				,     UpperCamelCase_      ):
              def find_re(UpperCamelCase_				,     UpperCamelCase_				,     UpperCamelCase_      ):
                     __UpperCAmelCase  :				Dict       				=		pattern.search(UpperCamelCase_				,     UpperCamelCase_      )
                     return m.start() if m else -1

              __UpperCAmelCase  :				List[str]       				=		[re.compile(UpperCamelCase_				,     re.MULTILINE      ) for pattern in truncate_before_pattern]

              __UpperCAmelCase  :				Optional[Any]       				=		list(re.finditer("^print"				,     UpperCamelCase_				,     re.MULTILINE      )      )

              if len(UpperCamelCase_      ) > 1:
                     __UpperCAmelCase  :				List[Any]       				=		completion[: prints[1].start()]

              __UpperCAmelCase  :				Tuple       				=		list(re.finditer("^def"				,     UpperCamelCase_				,     re.MULTILINE      )      )

              if len(UpperCamelCase_      ) > 1:
                     __UpperCAmelCase  :				Union[str, Any]       				=		completion[: defs[1].start()]

              __UpperCAmelCase  :				Dict       				=		0

              __UpperCAmelCase  :				Dict       				=		[
                  pos for pos in [find_re(UpperCamelCase_				,     UpperCamelCase_				,     UpperCamelCase_      ) for terminal in terminals] if pos != -1
              ]

              if len(UpperCamelCase_      ) > 0:
                     return completion[: min(UpperCamelCase_      )]
              else:
                     return completion






