
import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
    import jax.numpy as jnp

    from transformers.models.albert.modeling_flax_albert import (
        FlaxAlbertForMaskedLM,
        FlaxAlbertForMultipleChoice,
        FlaxAlbertForPreTraining,
        FlaxAlbertForQuestionAnswering,
        FlaxAlbertForSequenceClassification,
        FlaxAlbertForTokenClassification,
        FlaxAlbertModel,
    )




class 				_lowerCamelCase (      unittest.TestCase ):





     """simple docstring"""







     def __init__(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE=1_3						,						__SCREAMING_SNAKE_CASE=7						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=9_9						,						__SCREAMING_SNAKE_CASE=3_2						,						__SCREAMING_SNAKE_CASE=5						,						__SCREAMING_SNAKE_CASE=4						,						__SCREAMING_SNAKE_CASE=3_7						,						__SCREAMING_SNAKE_CASE="gelu"						,						__SCREAMING_SNAKE_CASE=0.1						,						__SCREAMING_SNAKE_CASE=0.1						,						__SCREAMING_SNAKE_CASE=5_1_2						,						__SCREAMING_SNAKE_CASE=1_6						,						__SCREAMING_SNAKE_CASE=2						,						__SCREAMING_SNAKE_CASE=0.02						,						__SCREAMING_SNAKE_CASE=4						,						)  ->   str:




           """simple docstring"""







           UpperCamelCase__    :   Tuple					=				parent
           UpperCamelCase__    :   int					=				batch_size
           UpperCamelCase__    :   int					=				seq_length
           UpperCamelCase__    :   Tuple					=				is_training
           UpperCamelCase__    :   Any					=				use_attention_mask
           UpperCamelCase__    :   Union[str, Any]					=				use_token_type_ids
           UpperCamelCase__    :   Optional[int]					=				use_labels
           UpperCamelCase__    :   Dict					=				vocab_size
           UpperCamelCase__    :   Union[str, Any]					=				hidden_size
           UpperCamelCase__    :   Union[str, Any]					=				num_hidden_layers
           UpperCamelCase__    :   List[str]					=				num_attention_heads
           UpperCamelCase__    :   Optional[Any]					=				intermediate_size
           UpperCamelCase__    :   int					=				hidden_act
           UpperCamelCase__    :   List[Any]					=				hidden_dropout_prob
           UpperCamelCase__    :   Optional[Any]					=				attention_probs_dropout_prob
           UpperCamelCase__    :   Optional[Any]					=				max_position_embeddings
           UpperCamelCase__    :   int					=				type_vocab_size
           UpperCamelCase__    :   List[str]					=				type_sequence_label_size
           UpperCamelCase__    :   Tuple					=				initializer_range
           UpperCamelCase__    :   Optional[int]					=				num_choices






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   str:




           """simple docstring"""







           UpperCamelCase__    :   Optional[Any]					=				ids_tensor([self.batch_size, self.seq_length]						,						self.vocab_size  )

           UpperCamelCase__    :   Tuple					=				None
           if self.use_attention_mask:
                 UpperCamelCase__    :   Dict					=				random_attention_mask([self.batch_size, self.seq_length]  )

           UpperCamelCase__    :   Tuple					=				None
           if self.use_token_type_ids:
                 UpperCamelCase__    :   Union[str, Any]					=				ids_tensor([self.batch_size, self.seq_length]						,						self.type_vocab_size  )

           UpperCamelCase__    :   List[str]					=				AlbertConfig(
               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=__SCREAMING_SNAKE_CASE						,						initializer_range=self.initializer_range						,						)

           return config, input_ids, token_type_ids, attention_mask






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Tuple:




           """simple docstring"""







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




@require_flax
class 				_lowerCamelCase (      UpperCamelCase_	,							unittest.TestCase ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  (
         (
             FlaxAlbertModel,
             FlaxAlbertForPreTraining,
             FlaxAlbertForMaskedLM,
             FlaxAlbertForMultipleChoice,
             FlaxAlbertForQuestionAnswering,
             FlaxAlbertForSequenceClassification,
             FlaxAlbertForTokenClassification,
             FlaxAlbertForQuestionAnswering,
         )
         if is_flax_available()
         else ()
     )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   int:




           """simple docstring"""







           UpperCamelCase__    :   Union[str, Any]					=				FlaxAlbertModelTester(self  )






     @slow
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   List[Any]:




           """simple docstring"""







           for model_class_name in self.all_model_classes:
                 UpperCamelCase__    :   str					=				model_class_name.from_pretrained('''albert-base-v2'''  )
                 UpperCamelCase__    :   int					=				model(np.ones((1, 1)  )  )
                 self.assertIsNotNone(__SCREAMING_SNAKE_CASE  )




@require_flax
class 				_lowerCamelCase (      unittest.TestCase ):





     """simple docstring"""







     @slow
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Optional[int]:




           """simple docstring"""







           UpperCamelCase__    :   Union[str, Any]					=				FlaxAlbertModel.from_pretrained('''albert-base-v2'''  )
           UpperCamelCase__    :   Any					=				np.array([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]  )
           UpperCamelCase__    :   str					=				np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
           UpperCamelCase__    :   List[str]					=				model(__SCREAMING_SNAKE_CASE						,						attention_mask=__SCREAMING_SNAKE_CASE  )[0]
           UpperCamelCase__    :   Tuple					=				(1, 1_1, 7_6_8)
           self.assertEqual(output.shape						,						__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Tuple					=				np.array(
               [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]  )

           self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]						,						__SCREAMING_SNAKE_CASE						,						atol=1e-4  )  )




from __future__ import annotations

from collections.abc import Callable


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__ ,		UpperCamelCase__ ,		UpperCamelCase__ ,		UpperCamelCase__ = 1_0_0 ,		):
      UpperCamelCase__    :   Union[str, Any]					=				x_start
      UpperCamelCase__    :   List[Any]					=				fnc(UpperCamelCase__		)
      UpperCamelCase__    :   Any					=				0.0
      for _ in range(UpperCamelCase__		):
            # Approximates small segments of curve as linear and solve
            # for trapezoidal area
            UpperCamelCase__    :   str					=				(x_end - x_start) / steps + xa
            UpperCamelCase__    :   Dict					=				fnc(UpperCamelCase__		)
            area += abs(fxa + fxa		) * (xa - xa) / 2
            # Increment step
            UpperCamelCase__    :   Tuple					=				xa
            UpperCamelCase__    :   Union[str, Any]					=				fxa
      return area


if __name__ == "__main__":


    def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__		):
          return x**3 + x**2

    print("f(x) = x^3 + x^2")
    print("The area between the curve, x = -5, x = 5 and the x axis is:")
    lowerCamelCase      =1_0
    while i <= 1_0_0_0_0_0:
        print(F'''with {i} steps: {trapezoidal_area(f, -5, 5, i)}''')
        i *= 1_0


