


"""simple docstring"""





from queue import Queue
from typing import TYPE_CHECKING, Optional


if TYPE_CHECKING:
 from ..models.auto import AutoTokenizer



class 		snake_case_:






     def      lowerCamelCase__     (	self  :					List[str]					,				UpperCamelCase_  :					List[str]				):
           raise NotImplementedError()






     def      lowerCamelCase__     (	self  :					List[Any]				):
           raise NotImplementedError()



class 		snake_case_(       a__			):






     def __init__(	self  :					Optional[int]					,				UpperCamelCase_  :					"AutoTokenizer"					,				UpperCamelCase_  :					bool = False					,				**UpperCamelCase_  :					Optional[int]				):
           lowerCAmelCase					:	Tuple       =   tokenizer
           lowerCAmelCase					:	str       =   skip_prompt
           lowerCAmelCase					:	Dict       =   decode_kwargs

           # variables used in the streaming process
           lowerCAmelCase					:	List[Any]       =   []
           lowerCAmelCase					:	Optional[int]       =   0
           lowerCAmelCase					:	Union[str, Any]       =   True






     def      lowerCamelCase__     (	self  :					Optional[int]					,				UpperCamelCase_  :					Optional[int]				):
           if len(value.shape				) > 1 and value.shape[0] > 1:
                 raise ValueError('''TextStreamer only supports batch size 1'''				)
           elif len(value.shape				) > 1:
                 lowerCAmelCase					:	Optional[Any]       =   value[0]

           if self.skip_prompt and self.next_tokens_are_prompt:
                 lowerCAmelCase					:	Optional[int]       =   False
                 return

           # Add the new token to the cache and decodes the entire thing.
           self.token_cache.extend(value.tolist()				)
           lowerCAmelCase					:	List[Any]       =   self.tokenizer.decode(self.token_cache					,				**self.decode_kwargs				)

           # After the symbol for a new line, we flush the cache.
           if text.endswith('''\n'''				):
                 lowerCAmelCase					:	Tuple       =   text[self.print_len :]
                 lowerCAmelCase					:	List[Any]       =   []
                 lowerCAmelCase					:	str       =   0
           # If the last token is a CJK character, we print the characters.
           elif len(UpperCamelCase_				) > 0 and self._is_chinese_char(ord(text[-1]				)				):
                 lowerCAmelCase					:	Tuple       =   text[self.print_len :]
                 self.print_len += len(UpperCamelCase_				)
           # Otherwise, prints until the last space char (simple heuristic to avoid printing incomplete words,
           # which may change with the subsequent token -- there are probably smarter ways to do this!)
           else:
                 lowerCAmelCase					:	Dict       =   text[self.print_len : text.rfind(''' '''				) + 1]
                 self.print_len += len(UpperCamelCase_				)

           self.on_finalized_text(UpperCamelCase_				)






     def      lowerCamelCase__     (	self  :					Optional[int]				):
           # Flush the cache, if it exists
           if len(self.token_cache				) > 0:
                 lowerCAmelCase					:	Dict       =   self.tokenizer.decode(self.token_cache					,				**self.decode_kwargs				)
                 lowerCAmelCase					:	Optional[int]       =   text[self.print_len :]
                 lowerCAmelCase					:	Dict       =   []
                 lowerCAmelCase					:	Tuple       =   0
           else:
                 lowerCAmelCase					:	List[str]       =   ''''''

           lowerCAmelCase					:	Tuple       =   True
           self.on_finalized_text(UpperCamelCase_					,				stream_end=UpperCamelCase_				)






     def      lowerCamelCase__     (	self  :					int					,				UpperCamelCase_  :					str					,				UpperCamelCase_  :					bool = False				):
           print(UpperCamelCase_					,				flush=UpperCamelCase_					,				end='''''' if not stream_end else None				)






     def      lowerCamelCase__     (	self  :					str					,				UpperCamelCase_  :					List[Any]				):
           # This defines a "chinese character" as anything in the CJK Unicode block:
           #   https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)
           #
           # Note that the CJK Unicode block is NOT all Japanese and Korean characters,
           # despite its name. The modern Korean Hangul alphabet is a different block,
           # as is Japanese Hiragana and Katakana. Those alphabets are used to write
           # space-separated words, so they are not treated specially and handled
           # like the all of the other languages.
           if (
               (cp >= 0X4_E_0_0 and cp <= 0X9_F_F_F)
               or (cp >= 0X3_4_0_0 and cp <= 0X4_D_B_F)  #
               or (cp >= 0X2_0_0_0_0 and cp <= 0X2_A_6_D_F)  #
               or (cp >= 0X2_A_7_0_0 and cp <= 0X2_B_7_3_F)  #
               or (cp >= 0X2_B_7_4_0 and cp <= 0X2_B_8_1_F)  #
               or (cp >= 0X2_B_8_2_0 and cp <= 0X2_C_E_A_F)  #
               or (cp >= 0XF_9_0_0 and cp <= 0XF_A_F_F)
               or (cp >= 0X2_F_8_0_0 and cp <= 0X2_F_A_1_F)  #
           ):  #
                 return True

           return False



class 		snake_case_(       a__			):






     def __init__(	self  :					Any					,				UpperCamelCase_  :					"AutoTokenizer"					,				UpperCamelCase_  :					bool = False					,				UpperCamelCase_  :					Optional[float] = None					,				**UpperCamelCase_  :					List[str]				):
           super().__init__(UpperCamelCase_					,				UpperCamelCase_					,				**UpperCamelCase_				)
           lowerCAmelCase					:	Tuple       =   Queue()
           lowerCAmelCase					:	Dict       =   None
           lowerCAmelCase					:	Dict       =   timeout






     def      lowerCamelCase__     (	self  :					Any					,				UpperCamelCase_  :					str					,				UpperCamelCase_  :					bool = False				):
           self.text_queue.put(UpperCamelCase_					,				timeout=self.timeout				)
           if stream_end:
                 self.text_queue.put(self.stop_signal					,				timeout=self.timeout				)






     def __iter__(	self  :					Union[str, Any]				):
           return self






     def      lowerCamelCase__     (	self  :					Optional[Any]				):
           lowerCAmelCase					:	Optional[int]       =   self.text_queue.get(timeout=self.timeout				)
           if value == self.stop_signal:
                 raise StopIteration()
           else:
                 return value






"""simple docstring"""





def      _snake_case						(						_snake_case				:			float ,   _snake_case				:			list[float]			):
      if discount_rate < 0:
            raise ValueError('''Discount rate cannot be negative'''			)
      if not cash_flows:
            raise ValueError('''Cash flows list cannot be empty'''			)
      lowerCAmelCase					:	List[str]       =   sum(
          cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_snake_case			)			)
      return round(_snake_case ,   ndigits=2			)


if __name__ == "__main__":
 import doctest

 doctest.testmod()


