



import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers.testing_utils import require_vision
from transformers.utils import is_vision_available


if is_vision_available():
				from PIL import Image

				from transformers import AutoProcessor, BlipaProcessor, BlipImageProcessor, GPTaTokenizer, PreTrainedTokenizerFast


@require_vision
class       a							(			unittest.TestCase				):



		def 	__lowerCamelCase			(     self     :Union[str, Any]  ):
						snake_case__	:      Dict     		=	tempfile.mkdtemp()

						snake_case__	:      Tuple     		=	BlipImageProcessor()
						snake_case__	:      str     		=	GPTaTokenizer.from_pretrained('''hf-internal-testing/tiny-random-GPT2Model'''  )

						snake_case__	:      Any     		=	BlipaProcessor(__lowercase   ,__lowercase  )

						processor.save_pretrained(self.tmpdirname  )



		def 	__lowerCamelCase			(     self     :List[str]   ,**__lowercase     :int  ):
						return AutoProcessor.from_pretrained(self.tmpdirname   ,**__lowercase  ).tokenizer



		def 	__lowerCamelCase			(     self     :Optional[Any]   ,**__lowercase     :Any  ):
						return AutoProcessor.from_pretrained(self.tmpdirname   ,**__lowercase  ).image_processor



		def 	__lowerCamelCase			(     self     :List[Any]  ):
						shutil.rmtree(self.tmpdirname  )



		def 	__lowerCamelCase			(     self     :Optional[int]  ):
						snake_case__	:      Optional[Any]     		=	[np.random.randint(2_5_5   ,size=(3, 3_0, 4_0_0)   ,dtype=np.uinta  )]

						snake_case__	:      int     		=	[Image.fromarray(np.moveaxis(__lowercase   ,0   ,-1  )  ) for x in image_inputs]

						return image_inputs



		def 	__lowerCamelCase			(     self     :List[Any]  ):
						snake_case__	:      Tuple     		=	BlipaProcessor(tokenizer=self.get_tokenizer()   ,image_processor=self.get_image_processor()  )
						processor.save_pretrained(self.tmpdirname  )

						snake_case__	:      Optional[Any]     		=	self.get_tokenizer(bos_token='''(BOS)'''   ,eos_token='''(EOS)'''  )
						snake_case__	:      Optional[Any]     		=	self.get_image_processor(do_normalize=__lowercase   ,padding_value=1.0  )

						snake_case__	:      List[Any]     		=	BlipaProcessor.from_pretrained(
						    self.tmpdirname   ,bos_token='''(BOS)'''   ,eos_token='''(EOS)'''   ,do_normalize=__lowercase   ,padding_value=1.0  )

						self.assertEqual(processor.tokenizer.get_vocab()   ,tokenizer_add_kwargs.get_vocab()  )
						self.assertIsInstance(processor.tokenizer   ,__lowercase  )

						self.assertEqual(processor.image_processor.to_json_string()   ,image_processor_add_kwargs.to_json_string()  )
						self.assertIsInstance(processor.image_processor   ,__lowercase  )



		def 	__lowerCamelCase			(     self     :Dict  ):
						snake_case__	:      List[str]     		=	self.get_image_processor()
						snake_case__	:      str     		=	self.get_tokenizer()

						snake_case__	:      Union[str, Any]     		=	BlipaProcessor(tokenizer=__lowercase   ,image_processor=__lowercase  )

						snake_case__	:      Tuple     		=	self.prepare_image_inputs()

						snake_case__	:      Any     		=	image_processor(__lowercase   ,return_tensors='''np'''  )
						snake_case__	:      Dict     		=	processor(images=__lowercase   ,return_tensors='''np'''  )

						for key in input_feat_extract.keys():
										self.assertAlmostEqual(input_feat_extract[key].sum()   ,input_processor[key].sum()   ,delta=1e-2  )



		def 	__lowerCamelCase			(     self     :Optional[int]  ):
						snake_case__	:      List[Any]     		=	self.get_image_processor()
						snake_case__	:      str     		=	self.get_tokenizer()

						snake_case__	:      Optional[Any]     		=	BlipaProcessor(tokenizer=__lowercase   ,image_processor=__lowercase  )

						snake_case__	:      str     		=	'''lower newer'''

						snake_case__	:      str     		=	processor(text=__lowercase  )

						snake_case__	:      Tuple     		=	tokenizer(__lowercase   ,return_token_type_ids=__lowercase  )

						for key in encoded_tok.keys():
										self.assertListEqual(encoded_tok[key]   ,encoded_processor[key]  )



		def 	__lowerCamelCase			(     self     :List[str]  ):
						snake_case__	:      int     		=	self.get_image_processor()
						snake_case__	:      Optional[Any]     		=	self.get_tokenizer()

						snake_case__	:      List[Any]     		=	BlipaProcessor(tokenizer=__lowercase   ,image_processor=__lowercase  )

						snake_case__	:      Tuple     		=	'''lower newer'''
						snake_case__	:      List[Any]     		=	self.prepare_image_inputs()

						snake_case__	:      int     		=	processor(text=__lowercase   ,images=__lowercase  )

						self.assertListEqual(list(inputs.keys()  )   ,['''pixel_values''', '''input_ids''', '''attention_mask''']  )

						# test if it raises when no input is passed
						with pytest.raises(__lowercase  ):
										processor()



		def 	__lowerCamelCase			(     self     :Optional[int]  ):
						snake_case__	:      str     		=	self.get_image_processor()
						snake_case__	:      Optional[int]     		=	self.get_tokenizer()

						snake_case__	:      Tuple     		=	BlipaProcessor(tokenizer=__lowercase   ,image_processor=__lowercase  )

						snake_case__	:      List[Any]     		=	[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

						snake_case__	:      int     		=	processor.batch_decode(__lowercase  )
						snake_case__	:      List[str]     		=	tokenizer.batch_decode(__lowercase  )

						self.assertListEqual(__lowercase   ,__lowercase  )






		def 	__lowerCamelCase			(     self     :Any  ):
						snake_case__	:      Dict     		=	self.get_image_processor()
						snake_case__	:      str     		=	self.get_tokenizer()

						snake_case__	:      Union[str, Any]     		=	BlipaProcessor(tokenizer=__lowercase   ,image_processor=__lowercase  )

						snake_case__	:      int     		=	'''lower newer'''
						snake_case__	:      Optional[Any]     		=	self.prepare_image_inputs()

						snake_case__	:      str     		=	processor(text=__lowercase   ,images=__lowercase  )

						# For now the processor supports only ['pixel_values', 'input_ids', 'attention_mask']
						self.assertListEqual(list(inputs.keys()  )   ,['''pixel_values''', '''input_ids''', '''attention_mask''']  )









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

A__	:			Optional[int]			   = 637_8137.0
A__	:			List[str]			   = 635_6752.31_4245
A__	:			Union[str, Any]			   = 6_37_81_37






def   a			(						lowerCamelCase_		,   lowerCamelCase_		,   lowerCamelCase_		,   lowerCamelCase_				):






				'''simple docstring'''
				lowercase__    =			(AXIS_A - AXIS_B) / AXIS_A
				lowercase__    =			atan((1 - flattening) * tan(radians(lowerCamelCase_				)				)				)
				lowercase__    =			atan((1 - flattening) * tan(radians(lowerCamelCase_				)				)				)
				lowercase__    =			radians(lowerCamelCase_				)
				lowercase__    =			radians(lowerCamelCase_				)
				# Equation
				lowercase__    =			sin((phi_a - phi_a) / 2				)
				lowercase__    =			sin((lambda_a - lambda_a) / 2				)
				# Square both values
				sin_sq_phi *= sin_sq_phi
				sin_sq_lambda *= sin_sq_lambda
				lowercase__    =			sqrt(sin_sq_phi + (cos(lowerCamelCase_				) * cos(lowerCamelCase_				) * sin_sq_lambda)				)
				return 2 * RADIUS * asin(lowerCamelCase_				)


if __name__ == "__main__":
							import doctest

							doctest.testmod()




