


"""simple docstring"""







import unittest

from transformers import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING, is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
		from PIL import Image
else:




		class 				UpperCamelCase_			:

			"""simple docstring"""





			@staticmethod
			def 						UpperCAmelCase_   (				*UpperCAmelCase__    :       List[Any]    ,    **UpperCAmelCase__    :       Optional[Any]     ) ->			Optional[int]:
								pass




@is_pipeline_test
@require_torch
@require_vision
class 				UpperCamelCase_			(				unittest.TestCase):

	"""simple docstring"""





	snake_case__       :						List[Any]					      =    MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING




	def 						UpperCAmelCase_   (				self    :       Dict    ,    UpperCAmelCase__    :       Tuple    ,    UpperCAmelCase__    :       List[Any]    ,    UpperCAmelCase__    :       Optional[int]     ) ->			str:
						__SCREAMING_SNAKE_CASE		     =       pipeline("visual-question-answering"    ,    model="hf-internal-testing/tiny-vilt-random-vqa"     )
						__SCREAMING_SNAKE_CASE		     =       [
						    {
						        "image": Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     ),
						        "question": "How many cats are there?",
						    },
						    {
						        "image": "./tests/fixtures/tests_samples/COCO/000000039769.png",
						        "question": "How many cats are there?",
						    },
						]
						return vqa_pipeline, examples




	def 						UpperCAmelCase_   (				self    :       Dict    ,    UpperCAmelCase__    :       List[Any]    ,    UpperCAmelCase__    :       Any     ) ->			Any:
						__SCREAMING_SNAKE_CASE		     =       vqa_pipeline(UpperCAmelCase__    ,    top_k=1     )
						self.assertEqual(
						    UpperCAmelCase__    ,    [
						        [{"score": ANY(UpperCAmelCase__     ), "answer": ANY(UpperCAmelCase__     )}],
						        [{"score": ANY(UpperCAmelCase__     ), "answer": ANY(UpperCAmelCase__     )}],
						    ]    ,    )




	@require_torch
	def 						UpperCAmelCase_   (				self    :       Optional[Any]     ) ->			int:
						__SCREAMING_SNAKE_CASE		     =       pipeline("visual-question-answering"    ,    model="hf-internal-testing/tiny-vilt-random-vqa"     )
						__SCREAMING_SNAKE_CASE		     =       "./tests/fixtures/tests_samples/COCO/000000039769.png"
						__SCREAMING_SNAKE_CASE		     =       "How many cats are there?"

						__SCREAMING_SNAKE_CASE		     =       vqa_pipeline(image=UpperCAmelCase__    ,    question="How many cats are there?"    ,    top_k=2     )
						self.assertEqual(
						    UpperCAmelCase__    ,    [{"score": ANY(UpperCAmelCase__     ), "answer": ANY(UpperCAmelCase__     )}, {"score": ANY(UpperCAmelCase__     ), "answer": ANY(UpperCAmelCase__     )}]     )

						__SCREAMING_SNAKE_CASE		     =       vqa_pipeline({"image": image, "question": question}    ,    top_k=2     )
						self.assertEqual(
						    UpperCAmelCase__    ,    [{"score": ANY(UpperCAmelCase__     ), "answer": ANY(UpperCAmelCase__     )}, {"score": ANY(UpperCAmelCase__     ), "answer": ANY(UpperCAmelCase__     )}]     )




	@slow
	@require_torch
	def 						UpperCAmelCase_   (				self    :       Tuple     ) ->			Any:
						__SCREAMING_SNAKE_CASE		     =       pipeline("visual-question-answering"    ,    model="dandelin/vilt-b32-finetuned-vqa"     )
						__SCREAMING_SNAKE_CASE		     =       "./tests/fixtures/tests_samples/COCO/000000039769.png"
						__SCREAMING_SNAKE_CASE		     =       "How many cats are there?"

						__SCREAMING_SNAKE_CASE		     =       vqa_pipeline(image=UpperCAmelCase__    ,    question=UpperCAmelCase__    ,    top_k=2     )
						self.assertEqual(
						    nested_simplify(UpperCAmelCase__    ,    decimals=4     )    ,    [{"score": 0.8_799, "answer": "2"}, {"score": 0.296, "answer": "1"}]     )

						__SCREAMING_SNAKE_CASE		     =       vqa_pipeline({"image": image, "question": question}    ,    top_k=2     )
						self.assertEqual(
						    nested_simplify(UpperCAmelCase__    ,    decimals=4     )    ,    [{"score": 0.8_799, "answer": "2"}, {"score": 0.296, "answer": "1"}]     )

						__SCREAMING_SNAKE_CASE		     =       vqa_pipeline(
						    [{"image": image, "question": question}, {"image": image, "question": question}]    ,    top_k=2     )
						self.assertEqual(
						    nested_simplify(UpperCAmelCase__    ,    decimals=4     )    ,    [[{"score": 0.8_799, "answer": "2"}, {"score": 0.296, "answer": "1"}]] * 2    ,    )




	@require_tf
	@unittest.skip("Visual question answering not implemented in TF"     )
	def 						UpperCAmelCase_   (				self    :       str     ) ->			Optional[Any]:
						pass




"""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()
