



import unittest

import pytest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    MBartaaTokenizerFast,
    MBartConfig,
    MBartForConditionalGeneration,
    TranslationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch, slow

from .test_pipelines_common import ANY



@is_pipeline_test
class     __snake_case						(					unittest.TestCase						):
							_a      				=			MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
							_a      				=			TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING




							def        UpperCAmelCase__      (	self					:	Any    ,    A_					:	List[Any]    ,    A_					:	int    ,    A_					:	Dict):
									if isinstance(model.config    ,    A_):
											lowerCAmelCase_ ,  lowerCAmelCase_      :					Any     =			list(tokenizer.lang_code_to_id.keys())[:2]
											lowerCAmelCase_      :					List[str]     =			TranslationPipeline(model=A_    ,    tokenizer=A_    ,    src_lang=A_    ,    tgt_lang=A_)
									else:
											lowerCAmelCase_      :					Dict     =			TranslationPipeline(model=A_    ,    tokenizer=A_)
									return translator, ["Some string", "Some other text"]




							def        UpperCAmelCase__      (	self					:	Optional[int]    ,    A_					:	Any    ,    A_					:	Any):
									lowerCAmelCase_      :					Optional[Any]     =			translator('''Some string''')
									self.assertEqual(A_    ,    [{'''translation_text''': ANY(A_)}])

									lowerCAmelCase_      :					List[str]     =			translator(['''Some string'''])
									self.assertEqual(A_    ,    [{'''translation_text''': ANY(A_)}])

									lowerCAmelCase_      :					Tuple     =			translator(['''Some string''', '''other string'''])
									self.assertEqual(A_    ,    [{'''translation_text''': ANY(A_)}, {'''translation_text''': ANY(A_)}])




							@require_torch
							def        UpperCAmelCase__      (	self					:	Union[str, Any]):
									lowerCAmelCase_      :					List[str]     =			pipeline('''translation_en_to_ro'''    ,    model='''patrickvonplaten/t5-tiny-random'''    ,    framework='''pt''')
									lowerCAmelCase_      :					int     =			translator('''This is a test string'''    ,    max_length=2_0)
									self.assertEqual(
									    A_    ,    [
									        {
									            '''translation_text''': (
									                '''Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide'''
									                ''' Beide Beide'''
									            )
									        }
									    ]    ,    )




							@require_tf
							def        UpperCAmelCase__      (	self					:	Tuple):
									lowerCAmelCase_      :					List[Any]     =			pipeline('''translation_en_to_ro'''    ,    model='''patrickvonplaten/t5-tiny-random'''    ,    framework='''tf''')
									lowerCAmelCase_      :					Optional[int]     =			translator('''This is a test string'''    ,    max_length=2_0)
									self.assertEqual(
									    A_    ,    [
									        {
									            '''translation_text''': (
									                '''Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide'''
									                ''' Beide Beide'''
									            )
									        }
									    ]    ,    )




							@require_torch
							def        UpperCAmelCase__      (	self					:	Tuple):
									lowerCAmelCase_      :					Any     =			pipeline('''translation_en_to_de'''    ,    model='''patrickvonplaten/t5-tiny-random'''    ,    framework='''pt''')
									lowerCAmelCase_      :					Tuple     =			translator('''This is a test string'''    ,    max_length=2_0)
									self.assertEqual(
									    A_    ,    [
									        {
									            '''translation_text''': (
									                '''monoton monoton monoton monoton monoton monoton monoton monoton monoton monoton urine urine'''
									                ''' urine urine urine urine urine urine urine'''
									            )
									        }
									    ]    ,    )







							@require_tf
							def        UpperCAmelCase__      (	self					:	Optional[Any]):
									lowerCAmelCase_      :					Any     =			pipeline('''translation_en_to_de'''    ,    model='''patrickvonplaten/t5-tiny-random'''    ,    framework='''tf''')
									lowerCAmelCase_      :					Union[str, Any]     =			translator('''This is a test string'''    ,    max_length=2_0)
									self.assertEqual(
									    A_    ,    [
									        {
									            '''translation_text''': (
									                '''monoton monoton monoton monoton monoton monoton monoton monoton monoton monoton urine urine'''
									                ''' urine urine urine urine urine urine urine'''
									            )
									        }
									    ]    ,    )





class     __snake_case						(					unittest.TestCase						):




							@require_torch
							@slow
							def        UpperCAmelCase__      (	self					:	Any):
									# We don't provide a default for this pair
									with self.assertRaises(A_):
											pipeline(task='''translation_cn_to_ar''')

									# but we do for this one
									lowerCAmelCase_      :					List[str]     =			pipeline(task='''translation_en_to_de''')
									self.assertEqual(translator._preprocess_params['''src_lang''']    ,    '''en''')
									self.assertEqual(translator._preprocess_params['''tgt_lang''']    ,    '''de''')




							@require_torch
							@slow
							def        UpperCAmelCase__      (	self					:	Union[str, Any]):
									lowerCAmelCase_      :					str     =			MBartForConditionalGeneration.from_pretrained('''facebook/mbart-large-50-many-to-many-mmt''')
									lowerCAmelCase_      :					int     =			MBartaaTokenizerFast.from_pretrained('''facebook/mbart-large-50-many-to-many-mmt''')

									lowerCAmelCase_      :					List[Any]     =			pipeline(task='''translation'''    ,    model=A_    ,    tokenizer=A_)
									# Missing src_lang, tgt_lang
									with self.assertRaises(A_):
											translator('''This is a test''')

									lowerCAmelCase_      :					Optional[Any]     =			translator('''This is a test'''    ,    src_lang='''en_XX'''    ,    tgt_lang='''ar_AR''')
									self.assertEqual(A_    ,    [{'''translation_text''': '''هذا إختبار'''}])

									lowerCAmelCase_      :					Optional[int]     =			translator('''This is a test'''    ,    src_lang='''en_XX'''    ,    tgt_lang='''hi_IN''')
									self.assertEqual(A_    ,    [{'''translation_text''': '''यह एक परीक्षण है'''}])

									# src_lang, tgt_lang can be defined at pipeline call time
									lowerCAmelCase_      :					List[Any]     =			pipeline(task='''translation'''    ,    model=A_    ,    tokenizer=A_    ,    src_lang='''en_XX'''    ,    tgt_lang='''ar_AR''')
									lowerCAmelCase_      :					Union[str, Any]     =			translator('''This is a test''')
									self.assertEqual(A_    ,    [{'''translation_text''': '''هذا إختبار'''}])




							@require_torch
							def        UpperCAmelCase__      (	self					:	Tuple):
									lowerCAmelCase_      :					Optional[int]     =			'''patrickvonplaten/t5-tiny-random'''
									lowerCAmelCase_      :					str     =			pipeline(task='''translation_cn_to_ar'''    ,    model=A_)
									self.assertEqual(translator._preprocess_params['''src_lang''']    ,    '''cn''')
									self.assertEqual(translator._preprocess_params['''tgt_lang''']    ,    '''ar''')




							@require_torch
							def        UpperCAmelCase__      (	self					:	Tuple):
									lowerCAmelCase_      :					Any     =			'''patrickvonplaten/t5-tiny-random'''
									with pytest.warns(A_    ,    match=r'''.*translation_en_to_de.*'''):
											lowerCAmelCase_      :					List[str]     =			pipeline(task='''translation'''    ,    model=A_)
									self.assertEqual(translator.task    ,    '''translation_en_to_de''')
									self.assertEqual(translator._preprocess_params['''src_lang''']    ,    '''en''')
									self.assertEqual(translator._preprocess_params['''tgt_lang''']    ,    '''de''')







							@require_torch
							def        UpperCAmelCase__      (	self					:	Optional[int]):
									with self.assertRaises(A_):
											pipeline(task='''translation''')










from math import radians as angle_to_radians
from math import sin

# Acceleration Constant on Earth (unit m/s^2)
A__  :  Any       = 9.8_0_6_6_5


def       UpperCamelCase(  __UpperCamelCase							:		float					,__UpperCamelCase							:		float			):

		# Ensure valid instance
		if not isinstance(__UpperCamelCase					,(int, float)			):
				raise TypeError('''Invalid velocity. Should be a positive number.'''			)

		if not isinstance(__UpperCamelCase					,(int, float)			):
				raise TypeError('''Invalid angle. Range is 1-90 degrees.'''			)

		# Ensure valid angle
		if angle > 90 or angle < 1:
				raise ValueError('''Invalid angle. Range is 1-90 degrees.'''			)

		# Ensure valid velocity
		if init_velocity < 0:
				raise ValueError('''Invalid velocity. Should be a positive number.'''			)


def       UpperCamelCase(  __UpperCamelCase							:		float					,__UpperCamelCase							:		float			):
		check_args(__UpperCamelCase					,__UpperCamelCase			)
		lowerCAmelCase_      :					Optional[Any]     =			angle_to_radians(2 * angle			)
		return round(init_velocity**2 * sin(__UpperCamelCase			) / g					,2			)


def       UpperCamelCase(  __UpperCamelCase							:		float					,__UpperCamelCase							:		float			):
		check_args(__UpperCamelCase					,__UpperCamelCase			)
		lowerCAmelCase_      :					Any     =			angle_to_radians(__UpperCamelCase			)
		return round(init_velocity**2 * sin(__UpperCamelCase			) ** 2 / (2 * g)					,2			)


def       UpperCamelCase(  __UpperCamelCase							:		float					,__UpperCamelCase							:		float			):
		check_args(__UpperCamelCase					,__UpperCamelCase			)
		lowerCAmelCase_      :					Dict     =			angle_to_radians(__UpperCamelCase			)
		return round(2 * init_velocity * sin(__UpperCamelCase			) / g					,2			)


def       UpperCamelCase(  ):
		lowerCAmelCase_ ,  lowerCAmelCase_      :					Any     =			25, 20
		assert horizontal_distance(__UpperCamelCase					,__UpperCamelCase			) == 4_0.9_7
		assert max_height(__UpperCamelCase					,__UpperCamelCase			) == 3.7_3
		assert total_time(__UpperCamelCase					,__UpperCamelCase			) == 1.7_4


if __name__ == "__main__":
						from doctest import testmod

						testmod()

						# Get input from user
						A__  :  List[Any]       = float(input('''Initial Velocity: ''').strip())

						# Get input from user
						A__  :  Dict       = float(input('''angle: ''').strip())

						# Print results
						print()
						print('''Results: ''')
						print(F'''Horizontal Distance: {horizontal_distance(init_vel, angle)!s} [m]''')
						print(F'''Maximum Height: {max_height(init_vel, angle)!s} [m]''')
						print(F'''Total Time: {total_time(init_vel, angle)!s} [s]''')





