"""simple docstring"""





import shutil
import tempfile
import unittest

from transformers import ClapFeatureExtractor, ClapProcessor, RobertaTokenizer, RobertaTokenizerFast
from transformers.testing_utils import require_sentencepiece, require_torchaudio

from .test_feature_extraction_clap import floats_list
@require_torchaudio
@require_sentencepiece
class        _snake_case   (    unittest.TestCase						):






						def 					lowerCamelCase__   (				self					:	Optional[int]			):
													__lowerCamelCase    :						Optional[Any]						      =   'laion/clap-htsat-unfused'
													__lowerCamelCase    :						str						      =   tempfile.mkdtemp()






						def 					lowerCamelCase__   (				self					:	int							,    **UpperCAmelCase					:	Union[str, Any]			):
													return RobertaTokenizer.from_pretrained(self.checkpoint							,    **__UpperCAmelCase			)






						def 					lowerCamelCase__   (				self					:	Union[str, Any]							,    **UpperCAmelCase					:	Optional[int]			):
													return ClapFeatureExtractor.from_pretrained(self.checkpoint							,    **__UpperCAmelCase			)






						def 					lowerCamelCase__   (				self					:	List[str]			):
													shutil.rmtree(self.tmpdirname			)






						def 					lowerCamelCase__   (				self					:	Union[str, Any]			):
													__lowerCamelCase    :						Tuple						      =   self.get_tokenizer()
													__lowerCamelCase    :						Tuple						      =   self.get_feature_extractor()

													__lowerCamelCase    :						Optional[Any]						      =   ClapProcessor(tokenizer=__UpperCAmelCase							,    feature_extractor=__UpperCAmelCase			)

													processor.save_pretrained(self.tmpdirname			)
													__lowerCamelCase    :						Any						      =   ClapProcessor.from_pretrained(self.tmpdirname			)

													self.assertEqual(processor.tokenizer.get_vocab()							,    tokenizer.get_vocab()			)
													self.assertIsInstance(processor.tokenizer							,    __UpperCAmelCase			)

													self.assertEqual(processor.feature_extractor.to_json_string()							,    feature_extractor.to_json_string()			)
													self.assertIsInstance(processor.feature_extractor							,    __UpperCAmelCase			)






						def 					lowerCamelCase__   (				self					:	List[Any]			):
													__lowerCamelCase    :						List[Any]						      =   ClapProcessor(tokenizer=self.get_tokenizer()							,    feature_extractor=self.get_feature_extractor()			)
													processor.save_pretrained(self.tmpdirname			)

													__lowerCamelCase    :						Optional[int]						      =   self.get_tokenizer(bos_token="(BOS)"							,    eos_token="(EOS)"			)
													__lowerCamelCase    :						List[Any]						      =   self.get_feature_extractor(do_normalize=__UpperCAmelCase							,    padding_value=1.0			)

													__lowerCamelCase    :						str						      =   ClapProcessor.from_pretrained(
													    self.tmpdirname							,    bos_token="(BOS)"							,    eos_token="(EOS)"							,    do_normalize=__UpperCAmelCase							,    padding_value=1.0			)

													self.assertEqual(processor.tokenizer.get_vocab()							,    tokenizer_add_kwargs.get_vocab()			)
													self.assertIsInstance(processor.tokenizer							,    __UpperCAmelCase			)

													self.assertEqual(processor.feature_extractor.to_json_string()							,    feature_extractor_add_kwargs.to_json_string()			)
													self.assertIsInstance(processor.feature_extractor							,    __UpperCAmelCase			)






						def 					lowerCamelCase__   (				self					:	str			):
													__lowerCamelCase    :						Any						      =   self.get_feature_extractor()
													__lowerCamelCase    :						List[str]						      =   self.get_tokenizer()

													__lowerCamelCase    :						List[str]						      =   ClapProcessor(tokenizer=__UpperCAmelCase							,    feature_extractor=__UpperCAmelCase			)

													__lowerCamelCase    :						str						      =   floats_list((3, 1000)			)

													__lowerCamelCase    :						Optional[Any]						      =   feature_extractor(__UpperCAmelCase							,    return_tensors="np"			)
													__lowerCamelCase    :						Optional[int]						      =   processor(audios=__UpperCAmelCase							,    return_tensors="np"			)

													for key in input_feat_extract.keys():
																				self.assertAlmostEqual(input_feat_extract[key].sum()							,    input_processor[key].sum()							,    delta=1E-2			)






						def 					lowerCamelCase__   (				self					:	Optional[Any]			):
													__lowerCamelCase    :						Optional[Any]						      =   self.get_feature_extractor()
													__lowerCamelCase    :						Dict						      =   self.get_tokenizer()

													__lowerCamelCase    :						Dict						      =   ClapProcessor(tokenizer=__UpperCAmelCase							,    feature_extractor=__UpperCAmelCase			)

													__lowerCamelCase    :						Optional[Any]						      =   'This is a test string'

													__lowerCamelCase    :						Optional[int]						      =   processor(text=__UpperCAmelCase			)

													__lowerCamelCase    :						Union[str, Any]						      =   tokenizer(__UpperCAmelCase			)

													for key in encoded_tok.keys():
																				self.assertListEqual(encoded_tok[key]							,    encoded_processor[key]			)






						def 					lowerCamelCase__   (				self					:	Tuple			):
													__lowerCamelCase    :						int						      =   self.get_feature_extractor()
													__lowerCamelCase    :						Dict						      =   self.get_tokenizer()

													__lowerCamelCase    :						Optional[int]						      =   ClapProcessor(tokenizer=__UpperCAmelCase							,    feature_extractor=__UpperCAmelCase			)

													__lowerCamelCase    :						Union[str, Any]						      =   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

													__lowerCamelCase    :						List[Any]						      =   processor.batch_decode(__UpperCAmelCase			)
													__lowerCamelCase    :						int						      =   tokenizer.batch_decode(__UpperCAmelCase			)

													self.assertListEqual(__UpperCAmelCase							,    __UpperCAmelCase			)







						def 					lowerCamelCase__   (				self					:	Union[str, Any]			):
													__lowerCamelCase    :						List[str]						      =   self.get_feature_extractor()
													__lowerCamelCase    :						List[str]						      =   self.get_tokenizer()

													__lowerCamelCase    :						Union[str, Any]						      =   ClapProcessor(tokenizer=__UpperCAmelCase							,    feature_extractor=__UpperCAmelCase			)

													self.assertListEqual(
													    processor.model_input_names[2:]							,    feature_extractor.model_input_names							,    msg="`processor` and `feature_extractor` model input names do not match"							,    )






"""simple docstring"""





def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE			)					->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'			)
  lowerCAmelCase__			:Union[str, Any]											=							sum(
      cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_SCREAMING_SNAKE_CASE			)			)
  return round(_SCREAMING_SNAKE_CASE     ,   ndigits=2			)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
