
"""simple docstring"""





import unittest

from transformers import BigBirdConfig, 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

		from transformers.models.big_bird.modeling_flax_big_bird import (
		    FlaxBigBirdForCausalLM,
		    FlaxBigBirdForMaskedLM,
		    FlaxBigBirdForMultipleChoice,
		    FlaxBigBirdForPreTraining,
		    FlaxBigBirdForQuestionAnswering,
		    FlaxBigBirdForSequenceClassification,
		    FlaxBigBirdForTokenClassification,
		    FlaxBigBirdModel,
		)



class __lowerCAmelCase				(					unittest.TestCase   ):




			"""simple docstring"""







			def __init__(				self						:					List[Any]       ,   _snake_case						:					Dict       ,   _snake_case						:					List[str]=2       ,   _snake_case						:					Any=56       ,   _snake_case						:					List[Any]=True       ,   _snake_case						:					Optional[int]=True       ,   _snake_case						:					Optional[int]=True       ,   _snake_case						:					Any=True       ,   _snake_case						:					Optional[int]=99       ,   _snake_case						:					Optional[int]=32       ,   _snake_case						:					List[Any]=2       ,   _snake_case						:					Dict=2       ,   _snake_case						:					Any=7       ,   _snake_case						:					int="gelu_new"       ,   _snake_case						:					int=0.1       ,   _snake_case						:					str=0.1       ,   _snake_case						:					Any=512       ,   _snake_case						:					Union[str, Any]=16       ,   _snake_case						:					Optional[Any]=2       ,   _snake_case						:					str=0.0_2       ,   _snake_case						:					str=4       ,   _snake_case						:					List[Any]="block_sparse"       ,   _snake_case						:					Dict=True       ,   _snake_case						:					Any=False       ,   _snake_case						:					Any=2       ,   _snake_case						:					Optional[Any]=3       ,   )      -> List[Any]:







								"""simple docstring"""
								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

								A_				 =						rescale_embeddings
								A_				 =						attention_type
								A_				 =						use_bias
								A_				 =						block_size
								A_				 =						num_random_blocks




			def      lowerCamelCase__     (				self						:					Any	)      -> Any:







								"""simple docstring"""
								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_				 =						None
								if self.use_token_type_ids:
													A_				 =						ids_tensor([self.batch_size, self.seq_length]       ,   self.type_vocab_size	)

								A_				 =						BigBirdConfig(
								    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=_snake_case       ,   initializer_range=self.initializer_range       ,   attention_type=self.attention_type       ,   block_size=self.block_size       ,   num_random_blocks=self.num_random_blocks       ,   use_bias=self.use_bias       ,   rescale_embeddings=self.rescale_embeddings       ,   )

								return config, input_ids, token_type_ids, attention_mask






			def      lowerCamelCase__     (				self						:					Dict	)      -> Dict:







								"""simple docstring"""
								A_				 =						self.prepare_config_and_inputs()
								A_ ,    A_ ,    A_ ,    A_				 =						config_and_inputs
								A_				 =						{
								    "input_ids": input_ids,
								    "token_type_ids": token_type_ids,
								    "attention_mask": attention_mask,
								}
								return config, inputs_dict





@require_flax
class __lowerCAmelCase				(					_lowercase     ,				unittest.TestCase   ):




			"""simple docstring"""







			snake_case	      =				(
			    (
			        FlaxBigBirdForCausalLM,
			        FlaxBigBirdModel,
			        FlaxBigBirdForPreTraining,
			        FlaxBigBirdForMaskedLM,
			        FlaxBigBirdForMultipleChoice,
			        FlaxBigBirdForQuestionAnswering,
			        FlaxBigBirdForSequenceClassification,
			        FlaxBigBirdForTokenClassification,
			    )
			    if is_flax_available()
			    else ()
			)

			snake_case	      =				False
			snake_case	      =				False




			def      lowerCamelCase__     (				self						:					Union[str, Any]	)      -> Optional[Any]:







								"""simple docstring"""
								A_				 =						FlaxBigBirdModelTester(self	)




			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def      lowerCamelCase__     (				self						:					Tuple	)      -> Dict:







								"""simple docstring"""
								super().test_from_pretrained_save_pretrained()




			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def      lowerCamelCase__     (				self						:					str	)      -> Dict:







								"""simple docstring"""
								super().test_from_pretrained_with_no_automatic_init()




			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def      lowerCamelCase__     (				self						:					Optional[Any]	)      -> List[Any]:







								"""simple docstring"""
								super().test_no_automatic_init()




			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def      lowerCamelCase__     (				self						:					Optional[Any]	)      -> Union[str, Any]:







								"""simple docstring"""
								super().test_hidden_states_output()




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







								"""simple docstring"""
								for model_class_name in self.all_model_classes:
													A_				 =						model_class_name.from_pretrained("google/bigbird-roberta-base"	)
													self.assertIsNotNone(_snake_case	)




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







								"""simple docstring"""
								if self.test_attn_probs:
													super().test_attention_outputs()




			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def      lowerCamelCase__     (				self						:					int	)      -> Union[str, Any]:







								"""simple docstring"""
								A_ ,    A_				 =						self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
													with self.subTest(model_class.__name__	):
																		A_				 =						self._prepare_for_class(_snake_case       ,   _snake_case	)
																		A_				 =						model_class(_snake_case	)

																		@jax.jit
																		def model_jitted(_snake_case						:					Any       ,   _snake_case						:					Optional[int]=None       ,   **_snake_case						:					Union[str, Any]	):
																							return model(input_ids=_snake_case       ,   attention_mask=_snake_case       ,   **_snake_case	)

																		with self.subTest("JIT Enabled"	):
																							A_				 =						model_jitted(**_snake_case	).to_tuple()

																		with self.subTest("JIT Disabled"	):
																							with jax.disable_jit():
																												A_				 =						model_jitted(**_snake_case	).to_tuple()

																		self.assertEqual(len(_snake_case	)       ,   len(_snake_case	)	)
																		for jitted_output, output in zip(_snake_case       ,   _snake_case	):
																							self.assertEqual(jitted_output.shape       ,   output.shape	)






			def      lowerCamelCase__     (				self						:					Optional[int]       ,   _snake_case						:					Any       ,   _snake_case						:					Tuple       ,   _snake_case						:					Optional[int]       ,   _snake_case						:					Optional[int]=1e-5       ,   _snake_case						:					Any="outputs"       ,   _snake_case						:					int=None	)      -> Union[str, Any]:







								"""simple docstring"""
								# `bigbird_block_sparse_attention` in `FlaxBigBird` returns `attention_probs = None`, while in PyTorch version,
								# an effort was done to return `attention_probs` (yet to be verified).
								if name.startswith("outputs.attentions"	):
													return
								else:
													super().check_pt_flax_outputs(_snake_case       ,   _snake_case       ,   _snake_case       ,   _snake_case       ,   _snake_case       ,   _snake_case	)






"""simple docstring"""





from math import atan, cos, radians, sin, tan

from .haversine_distance import haversine_distance

UpperCamelCase_					:						Tuple				= 637_8137.0
UpperCamelCase_					:						List[str]				= 635_6752.31_4245
UpperCamelCase_					:						Dict				= 637_8137
def 							A_     (__a				,   __a				,   __a				,   __a				):

					'''simple docstring'''





					A_				 =						(AXIS_A - AXIS_B) / AXIS_A
					# Parametric latitudes
					# https://en.wikipedia.org/wiki/Latitude#Parametric_(or_reduced)_latitude
					A_				 =						atan((1 - flattening) * tan(radians(__a				)				)				)
					A_				 =						atan((1 - flattening) * tan(radians(__a				)				)				)

					# Compute central angle between two points
					# using haversine theta. sigma =  haversine_distance / equatorial radius
					A_				 =						haversine_distance(__a				,   __a				,   __a				,   __a				) / EQUATORIAL_RADIUS

					# Intermediate P and Q values
					A_				 =						(b_lata + b_lata) / 2
					A_				 =						(b_lata - b_lata) / 2

					# Intermediate X value
					# X = (sigma - sin(sigma)) * sin^2Pcos^2Q / cos^2(sigma/2)
					A_				 =						(sin(__a				) ** 2) * (cos(__a				) ** 2)
					A_				 =						cos(sigma / 2				) ** 2
					A_				 =						(sigma - sin(__a				)) * (x_numerator / x_demonimator)

					# Intermediate Y value
					# Y = (sigma + sin(sigma)) * cos^2Psin^2Q / sin^2(sigma/2)
					A_				 =						(cos(__a				) ** 2) * (sin(__a				) ** 2)
					A_				 =						sin(sigma / 2				) ** 2
					A_				 =						(sigma + sin(__a				)) * (y_numerator / y_denominator)

					return EQUATORIAL_RADIUS * (sigma - ((flattening / 2) * (x_value + y_value)))


if __name__ == "__main__":
		import doctest

		doctest.testmod()




