


import math
import time

from transformers import Trainer, is_torch_tpu_available
from transformers.trainer_utils import PredictionOutput, speed_metrics


if is_torch_tpu_available(check_device=False):
		import torch_xla.core.xla_model as xm
		import torch_xla.debug.metrics as met




class 				UpperCamelCase_			(				UpperCamelCase):

	"""simple docstring"""





	def __init__(				self    :       Dict    ,    *UpperCAmelCase__    :       Dict    ,    UpperCAmelCase__    :       str=None    ,    UpperCAmelCase__    :       Union[str, Any]=None    ,    **UpperCAmelCase__    :       Union[str, Any]     ) ->			int:
						super().__init__(*UpperCamelCase__    ,    **UpperCamelCase__     )
						__SCREAMING_SNAKE_CASE		     =       eval_examples
						__SCREAMING_SNAKE_CASE		     =       post_process_function




	def 						UpperCAmelCase_   (				self    :       List[str]    ,    UpperCAmelCase__    :       Optional[int]=None    ,    UpperCAmelCase__    :       Union[str, Any]=None    ,    UpperCAmelCase__    :       Union[str, Any]=None    ,    UpperCAmelCase__    :       Dict = "eval"     ) ->			Optional[Any]:
						__SCREAMING_SNAKE_CASE		     =       self.eval_dataset if eval_dataset is None else eval_dataset
						__SCREAMING_SNAKE_CASE		     =       self.get_eval_dataloader(UpperCamelCase__     )
						__SCREAMING_SNAKE_CASE		     =       self.eval_examples if eval_examples is None else eval_examples

						# Temporarily disable metric computation, we will do it in the loop here.
						__SCREAMING_SNAKE_CASE		     =       self.compute_metrics
						__SCREAMING_SNAKE_CASE		     =       None
						__SCREAMING_SNAKE_CASE		     =       self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
						__SCREAMING_SNAKE_CASE		     =       time.time()
						try:
											__SCREAMING_SNAKE_CASE		     =       eval_loop(
											    UpperCamelCase__    ,    description="Evaluation"    ,    prediction_loss_only=True if compute_metrics is None else None    ,    ignore_keys=UpperCamelCase__    ,    metric_key_prefix=UpperCamelCase__    ,    )
						finally:
											__SCREAMING_SNAKE_CASE		     =       compute_metrics
						__SCREAMING_SNAKE_CASE		     =       self.args.eval_batch_size * self.args.world_size
						if F"""{metric_key_prefix}_jit_compilation_time""" in output.metrics:
											start_time += output.metrics[F"""{metric_key_prefix}_jit_compilation_time"""]
						output.metrics.update(
						    speed_metrics(
						        UpperCamelCase__    ,    UpperCamelCase__    ,    num_samples=output.num_samples    ,    num_steps=math.ceil(output.num_samples / total_batch_size     )    ,    )     )
						if self.post_process_function is not None and self.compute_metrics is not None and self.args.should_save:
											# Only the main node write the results by default
											__SCREAMING_SNAKE_CASE		     =       self.post_process_function(UpperCamelCase__    ,    UpperCamelCase__    ,    output.predictions     )
											__SCREAMING_SNAKE_CASE		     =       self.compute_metrics(UpperCamelCase__     )

											# Prefix all keys with metric_key_prefix + '_'
											for key in list(metrics.keys()     ):
																if not key.startswith(F"""{metric_key_prefix}_"""     ):
																					__SCREAMING_SNAKE_CASE		     =       metrics.pop(UpperCamelCase__     )
											metrics.update(output.metrics     )
						else:
											__SCREAMING_SNAKE_CASE		     =       output.metrics

						if self.args.should_log:
											# Only the main node log the results by default
											self.log(UpperCamelCase__     )

						if self.args.tpu_metrics_debug or self.args.debug:
											# tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)
											xm.master_print(met.metrics_report()     )

						__SCREAMING_SNAKE_CASE		     =       self.callback_handler.on_evaluate(self.args    ,    self.state    ,    self.control    ,    UpperCamelCase__     )
						return metrics




	def 						UpperCAmelCase_   (				self    :       str    ,    UpperCAmelCase__    :       str    ,    UpperCAmelCase__    :       Any    ,    UpperCAmelCase__    :       int=None    ,    UpperCAmelCase__    :       str = "test"     ) ->			List[str]:
						__SCREAMING_SNAKE_CASE		     =       self.get_test_dataloader(UpperCamelCase__     )

						# Temporarily disable metric computation, we will do it in the loop here.
						__SCREAMING_SNAKE_CASE		     =       self.compute_metrics
						__SCREAMING_SNAKE_CASE		     =       None
						__SCREAMING_SNAKE_CASE		     =       self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
						__SCREAMING_SNAKE_CASE		     =       time.time()
						try:
											__SCREAMING_SNAKE_CASE		     =       eval_loop(
											    UpperCamelCase__    ,    description="Prediction"    ,    prediction_loss_only=True if compute_metrics is None else None    ,    ignore_keys=UpperCamelCase__    ,    metric_key_prefix=UpperCamelCase__    ,    )
						finally:
											__SCREAMING_SNAKE_CASE		     =       compute_metrics
						__SCREAMING_SNAKE_CASE		     =       self.args.eval_batch_size * self.args.world_size
						if F"""{metric_key_prefix}_jit_compilation_time""" in output.metrics:
											start_time += output.metrics[F"""{metric_key_prefix}_jit_compilation_time"""]
						output.metrics.update(
						    speed_metrics(
						        UpperCamelCase__    ,    UpperCamelCase__    ,    num_samples=output.num_samples    ,    num_steps=math.ceil(output.num_samples / total_batch_size     )    ,    )     )

						if self.post_process_function is None or self.compute_metrics is None:
											return output

						__SCREAMING_SNAKE_CASE		     =       self.post_process_function(UpperCamelCase__    ,    UpperCamelCase__    ,    output.predictions    ,    "predict"     )
						__SCREAMING_SNAKE_CASE		     =       self.compute_metrics(UpperCamelCase__     )

						# Prefix all keys with metric_key_prefix + '_'
						for key in list(metrics.keys()     ):
											if not key.startswith(F"""{metric_key_prefix}_"""     ):
																__SCREAMING_SNAKE_CASE		     =       metrics.pop(UpperCamelCase__     )
						metrics.update(output.metrics     )
						return PredictionOutput(predictions=predictions.predictions    ,    label_ids=predictions.label_ids    ,    metrics=UpperCamelCase__     )




"""simple docstring"""







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

a__       :							List[str]        =  6_37_81_37.0
a__       :							Tuple        =  6_35_67_52.31_42_45
a__       :							str        =  6_3_7_8_1_3_7




def      UpperCAmelCase__ (lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE		     =       (AXIS_A - AXIS_B) / AXIS_A
					__SCREAMING_SNAKE_CASE		     =       atan((1 - flattening) * tan(radians(lowerCAmelCase_     )     )     )
					__SCREAMING_SNAKE_CASE		     =       atan((1 - flattening) * tan(radians(lowerCAmelCase_     )     )     )
					__SCREAMING_SNAKE_CASE		     =       radians(lowerCAmelCase_     )
					__SCREAMING_SNAKE_CASE		     =       radians(lowerCAmelCase_     )
					# Equation
					__SCREAMING_SNAKE_CASE		     =       sin((phi_a - phi_a) / 2     )
					__SCREAMING_SNAKE_CASE		     =       sin((lambda_a - lambda_a) / 2     )
					# Square both values
					sin_sq_phi *= sin_sq_phi
					sin_sq_lambda *= sin_sq_lambda
					__SCREAMING_SNAKE_CASE		     =       sqrt(sin_sq_phi + (cos(lowerCAmelCase_     ) * cos(lowerCAmelCase_     ) * sin_sq_lambda)     )
					return 2 * RADIUS * asin(lowerCAmelCase_     )


if __name__ == "__main__":
		import doctest

		doctest.testmod()
