




'''simple docstring'''





import unittest

from transformers import 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 		__A      :

													@staticmethod
													def     A__						(		*__snake_case   :int    , **__snake_case   :str ):
																	'''simple docstring'''

																	pass




@is_pipeline_test
@require_vision
class 		__A      (			unittest.TestCase			):

						@require_torch
						def     A__						(		self   :Tuple ):
										'''simple docstring'''

										__magic_name__	:	List[str]								=pipeline(
										    model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""    , )
										__magic_name__	:	Optional[Any]								=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
										__magic_name__	:	Optional[int]								=image_classifier(__snake_case    , candidate_labels=["""a""", """b""", """c"""] )

										# The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
										# python and torch versions.
										self.assertIn(
										    nested_simplify(__snake_case )    , [
										        [{"""score""": 0.333, """label""": """a"""}, {"""score""": 0.333, """label""": """b"""}, {"""score""": 0.333, """label""": """c"""}],
										        [{"""score""": 0.333, """label""": """a"""}, {"""score""": 0.333, """label""": """c"""}, {"""score""": 0.333, """label""": """b"""}],
										    ]    , )

										__magic_name__	:	List[str]								=image_classifier([image] * 5    , candidate_labels=["""A""", """B""", """C"""]    , batch_size=2 )
										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										    ]    , )

						@require_tf
						def     A__						(		self   :Optional[Any] ):
										'''simple docstring'''

										__magic_name__	:	Dict								=pipeline(
										    model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""    , framework="""tf""" )
										__magic_name__	:	Tuple								=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
										__magic_name__	:	int								=image_classifier(__snake_case    , candidate_labels=["""a""", """b""", """c"""] )

										self.assertEqual(
										    nested_simplify(__snake_case )    , [{"""score""": 0.333, """label""": """a"""}, {"""score""": 0.333, """label""": """b"""}, {"""score""": 0.333, """label""": """c"""}]    , )

										__magic_name__	:	str								=image_classifier([image] * 5    , candidate_labels=["""A""", """B""", """C"""]    , batch_size=2 )
										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										    ]    , )

						@slow
						@require_torch
						def     A__						(		self   :int ):
										'''simple docstring'''

										__magic_name__	:	Optional[int]								=pipeline(
										    task="""zero-shot-image-classification"""    , model="""openai/clip-vit-base-patch32"""    , )
										# This is an image of 2 cats with remotes and no planes
										__magic_name__	:	int								=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
										__magic_name__	:	int								=image_classifier(__snake_case    , candidate_labels=["""cat""", """plane""", """remote"""] )

										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        {"""score""": 0.511, """label""": """remote"""},
										        {"""score""": 0.485, """label""": """cat"""},
										        {"""score""": 0.004, """label""": """plane"""},
										    ]    , )

										__magic_name__	:	List[str]								=image_classifier([image] * 5    , candidate_labels=["""cat""", """plane""", """remote"""]    , batch_size=2 )
										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        [
										            {"""score""": 0.511, """label""": """remote"""},
										            {"""score""": 0.485, """label""": """cat"""},
										            {"""score""": 0.004, """label""": """plane"""},
										        ],
										    ]
										    * 5    , )


						@slow
						@require_tf
						def     A__						(		self   :str ):
										'''simple docstring'''

										__magic_name__	:	Optional[Any]								=pipeline(
										    task="""zero-shot-image-classification"""    , model="""openai/clip-vit-base-patch32"""    , framework="""tf""" )
										# This is an image of 2 cats with remotes and no planes
										__magic_name__	:	List[str]								=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
										__magic_name__	:	Any								=image_classifier(__snake_case    , candidate_labels=["""cat""", """plane""", """remote"""] )
										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        {"""score""": 0.511, """label""": """remote"""},
										        {"""score""": 0.485, """label""": """cat"""},
										        {"""score""": 0.004, """label""": """plane"""},
										    ]    , )

										__magic_name__	:	Any								=image_classifier([image] * 5    , candidate_labels=["""cat""", """plane""", """remote"""]    , batch_size=2 )
										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        [
										            {"""score""": 0.511, """label""": """remote"""},
										            {"""score""": 0.485, """label""": """cat"""},
										            {"""score""": 0.004, """label""": """plane"""},
										        ],
										    ]
										    * 5    , )










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

from .haversine_distance import haversine_distance

UpperCAmelCase_		:				Dict									=     637_8137.0
UpperCAmelCase_		:				List[Any]									=     635_6752.31_4245
UpperCAmelCase_		:				List[str]									=     6378137




def 		lowerCAmelCase_   (	lowerCamelCase	,     lowerCamelCase	,     lowerCamelCase	,     lowerCamelCase   ):
				__magic_name__	:	str								=(AXIS_A - AXIS_B) / AXIS_A
				# Parametric latitudes
				# https://en.wikipedia.org/wiki/Latitude#Parametric_(or_reduced)_latitude
				__magic_name__	:	str								=atan((1 - flattening) * tan(radians(lowerCamelCase   )   )   )
				__magic_name__	:	List[Any]								=atan((1 - flattening) * tan(radians(lowerCamelCase   )   )   )

				# Compute central angle between two points
				# using haversine theta. sigma =  haversine_distance / equatorial radius
				__magic_name__	:	List[Any]								=haversine_distance(lowerCamelCase	,     lowerCamelCase	,     lowerCamelCase	,     lowerCamelCase   ) / EQUATORIAL_RADIUS

				# Intermediate P and Q values
				__magic_name__	:	Tuple								=(b_lata + b_lata) / 2
				__magic_name__	:	int								=(b_lata - b_lata) / 2

				# Intermediate X value
				# X = (sigma - sin(sigma)) * sin^2Pcos^2Q / cos^2(sigma/2)
				__magic_name__	:	Optional[int]								=(sin(lowerCamelCase   ) ** 2) * (cos(lowerCamelCase   ) ** 2)
				__magic_name__	:	Any								=cos(sigma / 2   ) ** 2
				__magic_name__	:	List[Any]								=(sigma - sin(lowerCamelCase   )) * (x_numerator / x_demonimator)

				# Intermediate Y value
				# Y = (sigma + sin(sigma)) * cos^2Psin^2Q / sin^2(sigma/2)
				__magic_name__	:	Any								=(cos(lowerCamelCase   ) ** 2) * (sin(lowerCamelCase   ) ** 2)
				__magic_name__	:	Optional[Any]								=sin(sigma / 2   ) ** 2
				__magic_name__	:	str								=(sigma + sin(lowerCamelCase   )) * (y_numerator / y_denominator)

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


if __name__ == "__main__":
							import doctest

							doctest.testmod()




