



"""simple docstring"""





from __future__ import annotations

from numpy import array, cos, cross, floataa, radians, sin
from numpy.typing import NDArray




def 	UpperCAmelCase     (		A	:						float     ,				A	:						float     ,				A	:						bool = False       ):

		'''simple docstring'''


		if radian_mode:
				return [magnitude * cos(A       ), magnitude * sin(A       )]
		return [magnitude * cos(radians(A       )       ), magnitude * sin(radians(A       )       )]




def 	UpperCAmelCase     (		A	:						NDArray[floataa]     ,				A	:						NDArray[floataa]     ,				A	:						float = 10**-1       ):

		'''simple docstring'''


		_UpperCAmelCase							 =		cross(A     ,				A       )
		_UpperCAmelCase							 =		sum(A       )
		return abs(A       ) < eps


if __name__ == "__main__":
					# Test to check if it works
					lowercase  							=					array(
					    [
					        polar_force(718.4, 1_80 - 30),
					        polar_force(879.54, 45),
					        polar_force(1_00, -90),
					    ]
					)

					lowercase  							=					array([[0, 0], [0, 0], [0, 0]])

					assert in_static_equilibrium(forces, location)

					# Problem 1 in image_data/2D_problems.jpg
					lowercase  							=					array(
					    [
					        polar_force(30 * 9.81, 15),
					        polar_force(2_15, 1_80 - 45),
					        polar_force(2_64, 90 - 30),
					    ]
					)

					lowercase  							=					array([[0, 0], [0, 0], [0, 0]])

					assert in_static_equilibrium(forces, location)

					# Problem in image_data/2D_problems_1.jpg
					lowercase  							=					array([[0, -20_00], [0, -12_00], [0, 1_56_00], [0, -1_24_00]])

					lowercase  							=					array([[0, 0], [6, 0], [10, 0], [12, 0]])

					assert in_static_equilibrium(forces, location)

					import doctest

					doctest.testmod()







"""simple docstring"""





import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TextaTextGenerationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from transformers.utils import is_torch_available

from .test_pipelines_common import ANY


if is_torch_available():
					import torch




@is_pipeline_test
class 			lowercase__			(      unittest.TestCase    ):
							'''simple docstring'''







							_UpperCAmelCase      				=					MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
							_UpperCAmelCase      				=					TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING






							def        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case						)			->							Dict:
									_UpperCAmelCase							 =		TextaTextGenerationPipeline(model=snake_case	,       tokenizer=snake_case						)
									return generator, ["Something to write", "Something else"]






							def        lowerCamelCase_   (  self	,       snake_case	,       snake_case						)			->							Dict:
									_UpperCAmelCase							 =		generator('Something there'						)
									self.assertEqual(snake_case	,       [{'generated_text': ANY(snake_case						)}]						)
									# These are encoder decoder, they don't just append to incoming string
									self.assertFalse(outputs[0]['generated_text'].startswith('Something there'						)						)

									_UpperCAmelCase							 =		generator(['This is great !', 'Something else']	,       num_return_sequences=2	,       do_sample=snake_case						)
									self.assertEqual(
									    snake_case	,       [
									        [{'generated_text': ANY(snake_case						)}, {'generated_text': ANY(snake_case						)}],
									        [{'generated_text': ANY(snake_case						)}, {'generated_text': ANY(snake_case						)}],
									    ]	,       )

									_UpperCAmelCase							 =		generator(
									    ['This is great !', 'Something else']	,       num_return_sequences=2	,       batch_size=2	,       do_sample=snake_case						)
									self.assertEqual(
									    snake_case	,       [
									        [{'generated_text': ANY(snake_case						)}, {'generated_text': ANY(snake_case						)}],
									        [{'generated_text': ANY(snake_case						)}, {'generated_text': ANY(snake_case						)}],
									    ]	,       )

									with self.assertRaises(snake_case						):
											generator(4						)






							@require_torch
							def        lowerCamelCase_   (  self						)			->							Dict:
									_UpperCAmelCase							 =		pipeline('text2text-generation'	,       model='patrickvonplaten/t5-tiny-random'	,       framework='pt'						)
									# do_sample=False necessary for reproducibility
									_UpperCAmelCase							 =		generator('Something there'	,       do_sample=snake_case						)
									self.assertEqual(snake_case	,       [{'generated_text': ''}]						)

									_UpperCAmelCase							 =		3
									_UpperCAmelCase							 =		generator(
									    'Something there'	,       num_return_sequences=snake_case	,       num_beams=snake_case	,       )
									_UpperCAmelCase							 =		[
									    {'generated_text': 'Beide Beide Beide Beide Beide Beide Beide Beide Beide'},
									    {'generated_text': 'Beide Beide Beide Beide Beide Beide Beide Beide'},
									    {'generated_text': ''},
									]
									self.assertEqual(snake_case	,       snake_case						)

									_UpperCAmelCase							 =		generator('This is a test'	,       do_sample=snake_case	,       num_return_sequences=2	,       return_tensors=snake_case						)
									self.assertEqual(
									    snake_case	,       [
									        {'generated_token_ids': ANY(torch.Tensor						)},
									        {'generated_token_ids': ANY(torch.Tensor						)},
									    ]	,       )
									_UpperCAmelCase							 =		generator.model.config.eos_token_id
									_UpperCAmelCase							 =		'<pad>'
									_UpperCAmelCase							 =		generator(
									    ['This is a test', 'This is a second test']	,       do_sample=snake_case	,       num_return_sequences=2	,       batch_size=2	,       return_tensors=snake_case	,       )
									self.assertEqual(
									    snake_case	,       [
									        [
									            {'generated_token_ids': ANY(torch.Tensor						)},
									            {'generated_token_ids': ANY(torch.Tensor						)},
									        ],
									        [
									            {'generated_token_ids': ANY(torch.Tensor						)},
									            {'generated_token_ids': ANY(torch.Tensor						)},
									        ],
									    ]	,       )






							@require_tf
							def        lowerCamelCase_   (  self						)			->							Any:
									_UpperCAmelCase							 =		pipeline('text2text-generation'	,       model='patrickvonplaten/t5-tiny-random'	,       framework='tf'						)
									# do_sample=False necessary for reproducibility
									_UpperCAmelCase							 =		generator('Something there'	,       do_sample=snake_case						)
									self.assertEqual(snake_case	,       [{'generated_text': ''}]						)


