


'''simple docstring'''

import time
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, torch_device

from ..test_modeling_common import ids_tensor


if is_torch_available():
	import torch

	from transformers.generation import (
	    MaxLengthCriteria,
	    MaxNewTokensCriteria,
	    MaxTimeCriteria,
	    StoppingCriteriaList,
	    validate_stopping_criteria,
	)


@require_torch
class       a__				( unittest.TestCase      ):







				"""simple docstring"""



				def 					_snake_case  (self       ,			__lowercase		):
										__lowerCAmelCase							       =				3
										__lowerCAmelCase							       =				2_50

										__lowerCAmelCase							       =				ids_tensor((batch_size, length)       ,			__lowercase		)
										__lowerCAmelCase							       =				torch.ones((batch_size, length)       ,			device=__lowercase       ,			dtype=torch.float		) / length
										return input_ids, scores




				def 					_snake_case  (self		):
										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(5		)

										__lowerCAmelCase							       =				StoppingCriteriaList(
										    [
										        MaxLengthCriteria(max_length=10		),
										        MaxTimeCriteria(max_time=0.1		),
										    ]		)

										self.assertFalse(criteria(__lowercase       ,			__lowercase		)		)

										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(9		)
										self.assertFalse(criteria(__lowercase       ,			__lowercase		)		)

										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(10		)
										self.assertTrue(criteria(__lowercase       ,			__lowercase		)		)




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				MaxLengthCriteria(max_length=10		)

										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(5		)
										self.assertFalse(criteria(__lowercase       ,			__lowercase		)		)

										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(9		)
										self.assertFalse(criteria(__lowercase       ,			__lowercase		)		)

										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(10		)
										self.assertTrue(criteria(__lowercase       ,			__lowercase		)		)




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				MaxNewTokensCriteria(start_length=5       ,			max_new_tokens=5		)

										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(5		)
										self.assertFalse(criteria(__lowercase       ,			__lowercase		)		)

										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(9		)
										self.assertFalse(criteria(__lowercase       ,			__lowercase		)		)

										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(10		)
										self.assertTrue(criteria(__lowercase       ,			__lowercase		)		)

										__lowerCAmelCase							       =				StoppingCriteriaList([criteria]		)
										self.assertEqual(criteria_list.max_length       ,			10		)




				def 					_snake_case  (self		):
										__lowerCAmelCase       ,					__lowerCAmelCase							       =				self._get_tensors(5		)

										__lowerCAmelCase							       =				MaxTimeCriteria(max_time=0.1		)
										self.assertFalse(criteria(__lowercase       ,			__lowercase		)		)

										__lowerCAmelCase							       =				MaxTimeCriteria(max_time=0.1       ,			initial_timestamp=time.time() - 0.2		)
										self.assertTrue(criteria(__lowercase       ,			__lowercase		)		)




				def 					_snake_case  (self		):
										validate_stopping_criteria(StoppingCriteriaList([MaxLengthCriteria(10		)]		)       ,			10		)

										with self.assertWarns(__lowercase		):
																validate_stopping_criteria(StoppingCriteriaList([MaxLengthCriteria(10		)]		)       ,			11		)

										__lowerCAmelCase							       =				validate_stopping_criteria(StoppingCriteriaList()       ,			11		)

										self.assertEqual(len(__lowercase		)       ,			1		)





'''simple docstring'''

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

_UpperCAmelCase				: str							    =				6_37_81_37.0
_UpperCAmelCase				: Tuple							    =				6_35_67_52.31_42_45
_UpperCAmelCase				: Optional[Any]							    =				6_3_7_8_1_3_7

def 							__magic_name__(						lowerCamelCase,				lowerCamelCase,				lowerCamelCase,				lowerCamelCase):
						__lowerCAmelCase							       =				(AXIS_A - AXIS_B) / AXIS_A
						__lowerCAmelCase							       =				atan((1 - flattening) * tan(radians(lowerCamelCase)))
						__lowerCAmelCase							       =				atan((1 - flattening) * tan(radians(lowerCamelCase)))
						__lowerCAmelCase							       =				radians(lowerCamelCase)
						__lowerCAmelCase							       =				radians(lowerCamelCase)
						# Equation
						__lowerCAmelCase							       =				sin((phi_a - phi_a) / 2)
						__lowerCAmelCase							       =				sin((lambda_a - lambda_a) / 2)
						# Square both values
						sin_sq_phi *= sin_sq_phi
						sin_sq_lambda *= sin_sq_lambda
						__lowerCAmelCase							       =				sqrt(sin_sq_phi + (cos(lowerCamelCase) * cos(lowerCamelCase) * sin_sq_lambda))
						return 2 * RADIUS * asin(lowerCamelCase)


if __name__ == "__main__":
	import doctest

	doctest.testmod()

