


import unittest

import numpy as np

from transformers import DistilBertConfig, 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.distilbert.modeling_flax_distilbert import (
           FlaxDistilBertForMaskedLM,
           FlaxDistilBertForMultipleChoice,
           FlaxDistilBertForQuestionAnswering,
           FlaxDistilBertForSequenceClassification,
           FlaxDistilBertForTokenClassification,
           FlaxDistilBertModel,
       )

class       __magic_name__	(     unittest.TestCase):


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





      '''simple docstring'''






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


     def      UpperCAmelCase__	(      self							:     List[str]			)  ->      List[str]:





      '''simple docstring'''






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

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

      UpperCamelCase__					:    Optional[int]          =   DistilBertConfig(
          vocab_size=self.vocab_size							,	dim=self.hidden_size							,	n_layers=self.num_hidden_layers							,	n_heads=self.num_attention_heads							,	hidden_dim=self.intermediate_size							,	hidden_act=self.hidden_act							,	dropout=self.hidden_dropout_prob							,	attention_dropout=self.attention_probs_dropout_prob							,	max_position_embeddings=self.max_position_embeddings							,	initializer_range=self.initializer_range							,	tie_weights_=lowerCamelCase__							,	)

      return config, input_ids, attention_mask


     def      UpperCAmelCase__	(      self							:     List[Any]			)  ->      Tuple:





      '''simple docstring'''






      UpperCamelCase__					:    Any          =   self.prepare_config_and_inputs()
      UpperCamelCase__       ,				UpperCamelCase__       ,				UpperCamelCase__					:    List[str]          =   config_and_inputs
      UpperCamelCase__					:    Tuple          =   {'''input_ids''': input_ids, '''attention_mask''': attention_mask}
      return config, inputs_dict



@require_flax
class       __magic_name__	(     __lowerCAmelCase					,				unittest.TestCase):
     A:		Union[str, Any]			=      (
         (
             FlaxDistilBertModel,
             FlaxDistilBertForMaskedLM,
             FlaxDistilBertForMultipleChoice,
             FlaxDistilBertForQuestionAnswering,
             FlaxDistilBertForSequenceClassification,
             FlaxDistilBertForTokenClassification,
             FlaxDistilBertForQuestionAnswering,
         )
         if is_flax_available()
         else ()
     )


     def      UpperCAmelCase__	(      self							:     List[Any]			)  ->      Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__					:    Optional[Any]          =   FlaxDistilBertModelTester(self			)


     @slow
     def      UpperCAmelCase__	(      self							:     List[str]			)  ->      int:





      '''simple docstring'''






      for model_class_name in self.all_model_classes:
       UpperCamelCase__					:    List[Any]          =   model_class_name.from_pretrained('''distilbert-base-uncased'''			)
       UpperCamelCase__					:    List[str]          =   model(np.ones((1, 1)			)			)
       self.assertIsNotNone(lowerCamelCase__			)



@require_flax
class       __magic_name__	(     unittest.TestCase):


     @slow
     def      UpperCAmelCase__	(      self							:     Dict			)  ->      str:





      '''simple docstring'''






      UpperCamelCase__					:    Any          =   FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased'''			)
      UpperCamelCase__					:    Optional[Any]          =   np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]			)
      UpperCamelCase__					:    int          =   np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
      UpperCamelCase__					:    Optional[int]          =   model(lowerCamelCase__							,	attention_mask=lowerCamelCase__			)[0]
      UpperCamelCase__					:    Optional[int]          =   (1, 11, 768)
      self.assertEqual(output.shape							,	lowerCamelCase__			)
      UpperCamelCase__					:    Optional[int]          =   np.array([[[-0.1639, 0.3299, 0.1648], [-0.1746, 0.3289, 0.1710], [-0.1884, 0.3357, 0.1810]]]			)

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






from math import factorial, radians

def 			_a  (				SCREAMING_SNAKE_CASE	:				float    , SCREAMING_SNAKE_CASE	:				int = 18    , SCREAMING_SNAKE_CASE	:				int = 10     ):







 """simple docstring"""



 UpperCamelCase__					:    Dict          =   angle_in_degrees - ((angle_in_degrees // 360.0) * 360.0)

 # Converting from degrees to radians
 UpperCamelCase__					:    int          =   radians(SCREAMING_SNAKE_CASE     )

 UpperCamelCase__					:    Tuple          =   angle_in_radians
 UpperCamelCase__					:    str          =   3
 UpperCamelCase__					:    int          =   -1

 for _ in range(SCREAMING_SNAKE_CASE     ):
  result += (b * (angle_in_radians**a)) / factorial(SCREAMING_SNAKE_CASE     )

  UpperCamelCase__					:    List[Any]          =   -b  # One positive term and the next will be negative and so on...
  a += 2  # Increased by 2 for every term.

 return round(SCREAMING_SNAKE_CASE    , SCREAMING_SNAKE_CASE     )


if __name__ == "__main__":
       __import__("doctest").testmod()


