





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


lowercase				:	Optional[int]      						=  logging.get_logger(__name__)

lowercase				:	Tuple      						=  {"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

lowercase				:	Optional[int]      						=  {
    """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"""
        ),
    },
}

lowercase				:	Dict      						=  {
    """Salesforce/codegen-350M-mono""": 2_0_4_8,
}





class 			A__   (							__UpperCAmelCase     ):




			"""simple docstring"""



			__A       :    List[str]	  =  VOCAB_FILES_NAMES
			__A       :    Tuple	  =  PRETRAINED_VOCAB_FILES_MAP
			__A       :    List[Any]	  =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			__A       :    List[str]	  =  ["""input_ids""", """attention_mask"""]
			__A       :    Dict	  =  CodeGenTokenizer

			def __init__( self ,  lowercase=None ,  lowercase=None ,  lowercase=None ,  lowercase="<|endoftext|>" ,  lowercase="<|endoftext|>" ,  lowercase="<|endoftext|>" ,  lowercase=False ,  **lowercase ,  )      ->						Union[str, Any]:







										'''simple docstring'''

										super().__init__(
										    _lowercase ,  _lowercase ,  tokenizer_file=_lowercase ,  unk_token=_lowercase ,  bos_token=_lowercase ,  eos_token=_lowercase ,  add_prefix_space=_lowercase ,  **_lowercase ,  )

										if kwargs.pop('add_bos_token' ,  _lowercase):
																	a__						:     Optional[Any]			=    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.')

										a__						:     str			=    json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__())
										if pre_tok_state.get('add_prefix_space' ,  _lowercase) != add_prefix_space:
																	a__						:     Tuple			=    getattr(_lowercase ,  pre_tok_state.pop('type'))
																	a__						:     str			=    add_prefix_space
																	a__						:     Dict			=    pre_tok_class(**_lowercase)

										a__						:     Tuple			=    add_prefix_space

			def 							__lowercase		( self ,  *lowercase ,  **lowercase)      ->						BatchEncoding:







										'''simple docstring'''

										a__						:     Optional[int]			=    kwargs.get('is_split_into_words' ,  _lowercase)
										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(*_lowercase ,  **_lowercase)

			def 							__lowercase		( self ,  *lowercase ,  **lowercase)      ->						BatchEncoding:







										'''simple docstring'''

										a__						:     Union[str, Any]			=    kwargs.get('is_split_into_words' ,  _lowercase)

										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(*_lowercase ,  **_lowercase)

			def 							__lowercase		( self ,  lowercase ,  lowercase = None)      ->						Tuple[str]:







										'''simple docstring'''

										a__						:     Dict			=    self._tokenizer.model.save(_lowercase ,  name=_lowercase)
										return tuple(_lowercase)

			def 							__lowercase		( self ,  lowercase ,  lowercase = False ,  lowercase = None ,  lowercase = None ,  **lowercase ,  )      ->						str:







										'''simple docstring'''

										a__						:     List[Any]			=    super().decode(
										    token_ids=_lowercase ,  skip_special_tokens=_lowercase ,  clean_up_tokenization_spaces=_lowercase ,  **_lowercase ,  )

										if truncate_before_pattern is not None and len(_lowercase) > 0:
																	a__						:     Dict			=    self.truncate(_lowercase ,  _lowercase)

										return decoded_text

			def 							__lowercase		( self ,  lowercase ,  lowercase)      ->						Tuple:







										'''simple docstring'''

										def find_re(lowercase ,  lowercase ,  lowercase):
																	a__						:     int			=    pattern.search(_lowercase ,  _lowercase)
																	return m.start() if m else -1

										a__						:     Any			=    [re.compile(_lowercase ,  re.MULTILINE) for pattern in truncate_before_pattern]

										a__						:     Optional[int]			=    list(re.finditer('^print' ,  _lowercase ,  re.MULTILINE))

										if len(_lowercase) > 1:
																	a__						:     List[str]			=    completion[: prints[1].start()]

										a__						:     str			=    list(re.finditer('^def' ,  _lowercase ,  re.MULTILINE))

										if len(_lowercase) > 1:
																	a__						:     Optional[int]			=    completion[: defs[1].start()]

										a__						:     Tuple			=    0

										a__						:     Tuple			=    [
										    pos for pos in [find_re(_lowercase ,  _lowercase ,  _lowercase) for terminal in terminals] if pos != -1
										]

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









def A_     (		A__		,				A__		,				A__    )  ->		float:
       if principal <= 0:
              raise Exception('Principal borrowed must be > 0'    )
       if rate_per_annum < 0:
              raise Exception('Rate of interest must be >= 0'    )
       if years_to_repay <= 0 or not isinstance(A__		,				A__    ):
              raise Exception('Years to repay must be an integer > 0'    )

       # Yearly rate is divided by 12 to get monthly rate
       a__						:     str			=    rate_per_annum / 12

       # Years to repay is multiplied by 12 to get number of payments as payment is monthly
       a__						:     List[Any]			=    years_to_repay * 12

       return (
           principal
           * rate_per_month
           * (1 + rate_per_month) ** number_of_payments
           / ((1 + rate_per_month) ** number_of_payments - 1)
       )


if __name__ == "__main__":
    import doctest

    doctest.testmod()


