




import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
 from transformers.models.roberta.modeling_flax_roberta import (
     FlaxRobertaForCausalLM,
     FlaxRobertaForMaskedLM,
     FlaxRobertaForMultipleChoice,
     FlaxRobertaForQuestionAnswering,
     FlaxRobertaForSequenceClassification,
     FlaxRobertaForTokenClassification,
     FlaxRobertaModel,
 )







class   A(						unittest.TestCase   ):



 '''simple docstring'''


 def __init__(				self					:  Optional[Any]						,							A_					:  int						,							A_					:  Union[str, Any]=13						,							A_					:  List[str]=7						,							A_					:  int=True						,							A_					:  Optional[Any]=True						,							A_					:  Union[str, Any]=True						,							A_					:  Dict=True						,							A_					:  int=99						,							A_					:  Tuple=32						,							A_					:  List[str]=5						,							A_					:  List[str]=4						,							A_					:  Any=37						,							A_					:  Optional[int]="gelu"						,							A_					:  Tuple=0.1						,							A_					:  List[Any]=0.1						,							A_					:  List[Any]=512						,							A_					:  List[Any]=16						,							A_					:  int=2						,							A_					:  Any=0.02						,							A_					:  Tuple=4						,							)   ->	List[Any]:

       """simple docstring"""






       lowerCamelCase_		     =    parent
       lowerCamelCase_		     =    batch_size
       lowerCamelCase_		     =    seq_length
       lowerCamelCase_		     =    is_training
       lowerCamelCase_		     =    use_attention_mask
       lowerCamelCase_		     =    use_token_type_ids
       lowerCamelCase_		     =    use_labels
       lowerCamelCase_		     =    vocab_size
       lowerCamelCase_		     =    hidden_size
       lowerCamelCase_		     =    num_hidden_layers
       lowerCamelCase_		     =    num_attention_heads
       lowerCamelCase_		     =    intermediate_size
       lowerCamelCase_		     =    hidden_act
       lowerCamelCase_		     =    hidden_dropout_prob
       lowerCamelCase_		     =    attention_probs_dropout_prob
       lowerCamelCase_		     =    max_position_embeddings
       lowerCamelCase_		     =    type_vocab_size
       lowerCamelCase_		     =    type_sequence_label_size
       lowerCamelCase_		     =    initializer_range
       lowerCamelCase_		     =    num_choices

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

       """simple docstring"""






       lowerCamelCase_		     =    ids_tensor([self.batch_size, self.seq_length]						,							self.vocab_size  )

       lowerCamelCase_		     =    None
       if self.use_attention_mask:
             lowerCamelCase_		     =    random_attention_mask([self.batch_size, self.seq_length]  )

       lowerCamelCase_		     =    None
       if self.use_token_type_ids:
             lowerCamelCase_		     =    ids_tensor([self.batch_size, self.seq_length]						,							self.type_vocab_size  )

       lowerCamelCase_		     =    RobertaConfig(
           vocab_size=self.vocab_size						,							hidden_size=self.hidden_size						,							num_hidden_layers=self.num_hidden_layers						,							num_attention_heads=self.num_attention_heads						,							intermediate_size=self.intermediate_size						,							hidden_act=self.hidden_act						,							hidden_dropout_prob=self.hidden_dropout_prob						,							attention_probs_dropout_prob=self.attention_probs_dropout_prob						,							max_position_embeddings=self.max_position_embeddings						,							type_vocab_size=self.type_vocab_size						,							is_decoder=A_						,							initializer_range=self.initializer_range						,							)

       return config, input_ids, token_type_ids, attention_mask

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

       """simple docstring"""






       lowerCamelCase_		     =    self.prepare_config_and_inputs()
       lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_		     =    config_and_inputs
       lowerCamelCase_		     =    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
       return config, inputs_dict





 def 				a__ (				self					:  Tuple  )   ->	Dict:

       """simple docstring"""






       lowerCamelCase_		     =    self.prepare_config_and_inputs()
       lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_		     =    config_and_inputs

       lowerCamelCase_		     =    True
       lowerCamelCase_		     =    floats_tensor([self.batch_size, self.seq_length, self.hidden_size]  )
       lowerCamelCase_		     =    ids_tensor([self.batch_size, self.seq_length]						,							vocab_size=2  )

       return (
           config,
           input_ids,
           token_type_ids,
           encoder_hidden_states,
           encoder_attention_mask,
       )







@require_flax
class   A(						UpperCamelCase							,      unittest.TestCase   ):



 '''simple docstring'''


 UpperCamelCase						   =						True

 UpperCamelCase						   =						(
     (
         FlaxRobertaModel,
         FlaxRobertaForCausalLM,
         FlaxRobertaForMaskedLM,
         FlaxRobertaForSequenceClassification,
         FlaxRobertaForTokenClassification,
         FlaxRobertaForMultipleChoice,
         FlaxRobertaForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )

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

       """simple docstring"""






       lowerCamelCase_		     =    FlaxRobertaModelTester(self  )





 @slow
 def 				a__ (				self					:  str  )   ->	str:

       """simple docstring"""






       for model_class_name in self.all_model_classes:
             lowerCamelCase_		     =    model_class_name.from_pretrained('roberta-base'						,							from_pt=A_  )
             lowerCamelCase_		     =    model(np.ones((1, 1)  )  )
             self.assertIsNotNone(A_  )









def 			_SCREAMING_SNAKE_CASE			(							lowercase	:       float	,							lowercase	:       list[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_		     =    sum(
          cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(lowercase     )     )
      return round(lowercase	,							ndigits=2     )


if __name__ == "__main__":
 import doctest

 doctest.testmod()



