






'''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 _lowercase     :




										@staticmethod
										def 		lowerCamelCase_    (							*UpperCamelCase__:    Dict      ,							**UpperCamelCase__:    Optional[int]					):
																	pass

@is_pipeline_test
@require_torch
@require_vision
class _lowercase     (    unittest.TestCase		):
							a    				=	MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING




							def 		lowerCamelCase_    (							self:    Optional[int]      ,							UpperCamelCase__:    Optional[Any]      ,							UpperCamelCase__:    List[Any]      ,							UpperCamelCase__:    Tuple					):
														lowerCamelCase__ :     List[str]	  =	pipeline("""visual-question-answering"""      ,							model="""hf-internal-testing/tiny-vilt-random-vqa"""					)
														lowerCamelCase__ :     Union[str, Any]	  =	[
														    {
														        """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 		lowerCamelCase_    (							self:    List[Any]      ,							UpperCamelCase__:    List[Any]      ,							UpperCamelCase__:    Union[str, Any]					):
														lowerCamelCase__ :     Tuple	  =	vqa_pipeline(UpperCamelCase__      ,							top_k=1					)
														self.assertEqual(
														    UpperCamelCase__      ,							[
														        [{"""score""": ANY(UpperCamelCase__					), """answer""": ANY(UpperCamelCase__					)}],
														        [{"""score""": ANY(UpperCamelCase__					), """answer""": ANY(UpperCamelCase__					)}],
														    ]      ,							)




							@require_torch
							def 		lowerCamelCase_    (							self:    Dict					):
														lowerCamelCase__ :     Union[str, Any]	  =	pipeline("""visual-question-answering"""      ,							model="""hf-internal-testing/tiny-vilt-random-vqa"""					)
														lowerCamelCase__ :     List[Any]	  =	"""./tests/fixtures/tests_samples/COCO/000000039769.png"""
														lowerCamelCase__ :     Dict	  =	"""How many cats are there?"""

														lowerCamelCase__ :     str	  =	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__					)}]					)

														lowerCamelCase__ :     Dict	  =	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 		lowerCamelCase_    (							self:    Optional[Any]					):
														lowerCamelCase__ :     str	  =	pipeline("""visual-question-answering"""      ,							model="""dandelin/vilt-b32-finetuned-vqa"""					)
														lowerCamelCase__ :     Any	  =	"""./tests/fixtures/tests_samples/COCO/000000039769.png"""
														lowerCamelCase__ :     Optional[Any]	  =	"""How many cats are there?"""

														lowerCamelCase__ :     Union[str, Any]	  =	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"""}]					)

														lowerCamelCase__ :     List[Any]	  =	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"""}]					)

														lowerCamelCase__ :     List[str]	  =	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 		lowerCamelCase_    (							self:    int					):
														pass









'''simple docstring'''







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

_A     :      List[str]   					=637_8137.0
_A     :      Dict   					=635_6752.31_4245
_A     :      int   					=6_378_137





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase				)				->	float:
							lowerCamelCase__ :     str	  =	(AXIS_A - AXIS_B) / AXIS_A
							lowerCamelCase__ :     Dict	  =	atan((1 - flattening) * tan(radians(UpperCamelCase				)				)				)
							lowerCamelCase__ :     Dict	  =	atan((1 - flattening) * tan(radians(UpperCamelCase				)				)				)
							lowerCamelCase__ :     Optional[Any]	  =	radians(UpperCamelCase				)
							lowerCamelCase__ :     List[Any]	  =	radians(UpperCamelCase				)
							# Equation
							lowerCamelCase__ :     Tuple	  =	sin((phi_a - phi_a) / 2				)
							lowerCamelCase__ :     List[Any]	  =	sin((lambda_a - lambda_a) / 2				)
							# Square both values
							sin_sq_phi *= sin_sq_phi
							sin_sq_lambda *= sin_sq_lambda
							lowerCamelCase__ :     Tuple	  =	sqrt(sin_sq_phi + (cos(UpperCamelCase				) * cos(UpperCamelCase				) * sin_sq_lambda)				)
							return 2 * RADIUS * asin(UpperCamelCase				)


if __name__ == "__main__":
			import doctest

			doctest.testmod()

