






"""simple docstring"""







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

from .haversine_distance import haversine_distance

_UpperCamelCase					      =  6_37_81_37.0
_UpperCamelCase					      =  6_35_67_52.31_42_45
_UpperCamelCase					      =  6378137

def _a			(		_snake_case				,	_snake_case				,	_snake_case				,	_snake_case							):







      """simple docstring"""






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

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

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

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

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

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


if __name__ == "__main__":
  import doctest

  doctest.testmod()











"""simple docstring"""







import io
import json
import unittest

from parameterized import parameterized

from transformers import FSMTForConditionalGeneration, FSMTTokenizer
from transformers.testing_utils import get_tests_dir, require_torch, slow, torch_device
from utils import calculate_bleu


_UpperCamelCase					      =  get_tests_dir() + """/test_data/fsmt/fsmt_val_data.json"""
with io.open(filename, """r""", encoding="""utf-8""") as f:
  _UpperCamelCase					      =  json.load(f)







@require_torch
class  lowerCamelCase__ (	unittest.TestCase			):






    def     _UpperCamelCase							(			self     ,A ):
          return FSMTTokenizer.from_pretrained(A )






    def     _UpperCamelCase							(			self     ,A ):
          UpperCAmelCase          =	FSMTForConditionalGeneration.from_pretrained(A ).to(A )
          if torch_device == "cuda":
                model.half()
          return model






    @parameterized.expand(
        [
            ["""en-ru""", 26.0],
            ["""ru-en""", 22.0],
            ["""en-de""", 22.0],
            ["""de-en""", 29.0],
        ] )
    @slow
    def     _UpperCamelCase							(			self     ,A     ,A ):
          # note: this test is not testing the best performance since it only evals a small batch
          # but it should be enough to detect a regression in the output quality
          UpperCAmelCase          =	F'''facebook/wmt19-{pair}'''
          UpperCAmelCase          =	self.get_tokenizer(A )
          UpperCAmelCase          =	self.get_model(A )

          UpperCAmelCase          =	bleu_data[pair]["""src"""]
          UpperCAmelCase          =	bleu_data[pair]["""tgt"""]

          UpperCAmelCase          =	tokenizer(A     ,return_tensors="""pt"""     ,truncation=A     ,padding="""longest""" ).to(A )
          UpperCAmelCase          =	model.generate(
              input_ids=batch.input_ids     ,num_beams=8     ,)
          UpperCAmelCase          =	tokenizer.batch_decode(
              A     ,skip_special_tokens=A     ,clean_up_tokenization_spaces=A )
          UpperCAmelCase          =	calculate_bleu(A     ,A )
          print(A )
          self.assertGreaterEqual(scores["""bleu"""]     ,A )



