
'''simple docstring'''
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   a_ (      unittest.TestCase					):




			def __init__(       self					,   UpperCAmelCase					,   UpperCAmelCase=13					,   UpperCAmelCase=7					,   UpperCAmelCase=True					,   UpperCAmelCase=True					,   UpperCAmelCase=True					,   UpperCAmelCase=True					,   UpperCAmelCase=99					,   UpperCAmelCase=32					,   UpperCAmelCase=5					,   UpperCAmelCase=4					,   UpperCAmelCase=37					,   UpperCAmelCase="gelu"					,   UpperCAmelCase=0.1					,   UpperCAmelCase=0.1					,   UpperCAmelCase=5_12					,   UpperCAmelCase=16					,   UpperCAmelCase=2					,   UpperCAmelCase=0.02					,   UpperCAmelCase=4					,   ):
				a_      				=						parent
				a_      				=						batch_size
				a_      				=						seq_length
				a_      				=						is_training
				a_      				=						use_attention_mask
				a_      				=						use_token_type_ids
				a_      				=						use_labels
				a_      				=						vocab_size
				a_      				=						hidden_size
				a_      				=						num_hidden_layers
				a_      				=						num_attention_heads
				a_      				=						intermediate_size
				a_      				=						hidden_act
				a_      				=						hidden_dropout_prob
				a_      				=						attention_probs_dropout_prob
				a_      				=						max_position_embeddings
				a_      				=						type_vocab_size
				a_      				=						type_sequence_label_size
				a_      				=						initializer_range
				a_      				=						num_choices




			def 					lowerCAmelCase__					(       self	):
				a_      				=						ids_tensor([self.batch_size, self.seq_length]					,   self.vocab_size	)

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

				a_      				=						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_=UpperCAmelCase					,   )

				return config, input_ids, attention_mask






			def 					lowerCAmelCase__					(       self	):
				a_      				=						self.prepare_config_and_inputs()
				a_				,  a_				,  a_      				=						config_and_inputs
				a_      				=						{"""input_ids""": input_ids, """attention_mask""": attention_mask}
				return config, inputs_dict







@require_flax
class   a_ (      UpperCamelCase__		,  unittest.TestCase					):
			lowerCamelCase__	:			List[str]       =    (
			    (
			        FlaxDistilBertModel,
			        FlaxDistilBertForMaskedLM,
			        FlaxDistilBertForMultipleChoice,
			        FlaxDistilBertForQuestionAnswering,
			        FlaxDistilBertForSequenceClassification,
			        FlaxDistilBertForTokenClassification,
			        FlaxDistilBertForQuestionAnswering,
			    )
			    if is_flax_available()
			    else ()
			)




			def 					lowerCAmelCase__					(       self	):
				a_      				=						FlaxDistilBertModelTester(self	)






			@slow
			def 					lowerCAmelCase__					(       self	):
				for model_class_name in self.all_model_classes:
					a_      				=						model_class_name.from_pretrained("""distilbert-base-uncased"""	)
					a_      				=						model(np.ones((1, 1)	)	)
					self.assertIsNotNone(UpperCAmelCase	)







@require_flax
class   a_ (      unittest.TestCase					):




			@slow
			def 					lowerCAmelCase__					(       self	):
				a_      				=						FlaxDistilBertModel.from_pretrained("""distilbert-base-uncased"""	)
				a_      				=						np.array([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]	)
				a_      				=						np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
				a_      				=						model(UpperCAmelCase					,   attention_mask=UpperCAmelCase	)[0]
				a_      				=						(1, 11, 7_68)
				self.assertEqual(output.shape					,   UpperCAmelCase	)
				a_      				=						np.array([[[-0.16_39, 0.32_99, 0.16_48], [-0.17_46, 0.32_89, 0.17_10], [-0.18_84, 0.33_57, 0.18_10]]]	)

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


'''simple docstring'''
import math






def      UpperCamelCase_				(      A__						):
	return math.sqrt(A__						) * math.sqrt(A__						) == num






def      UpperCamelCase_				(      A__						):
	a_      				=						0
	a_      				=						n
	while left <= right:
		a_      				=						(left + right) // 2
		if mid**2 == n:
			return True
		elif mid**2 > n:
			a_      				=						mid - 1
		else:
			a_      				=						mid + 1
	return False


if __name__ == "__main__":
		import doctest

		doctest.testmod()
