

'''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 		__SCREAMING_SNAKE_CASE    ( unittest.TestCase			):
				lowerCamelCase_							=						MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
				lowerCamelCase_							=						TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING







				def    lowerCamelCase_  (					self    :		Optional[int]		,				UpperCAmelCase__    :		Optional[Any]		,				UpperCAmelCase__    :		Dict		,				UpperCAmelCase__    :		List[Any]      ):
										'''simple docstring'''
										lowercase   :       int								=TextaTextGenerationPipeline(model=UpperCAmelCase__		,				tokenizer=UpperCAmelCase__      )
										return generator, ["Something to write", "Something else"]







				def    lowerCamelCase_  (					self    :		Any		,				UpperCAmelCase__    :		Optional[int]		,				UpperCAmelCase__    :		Tuple      ):
										'''simple docstring'''
										lowercase   :       Optional[Any]								=generator('''Something there'''      )
										self.assertEqual(UpperCAmelCase__		,				[{'''generated_text''': ANY(UpperCAmelCase__      )}]      )
										# These are encoder decoder, they don't just append to incoming string
										self.assertFalse(outputs[0]['''generated_text'''].startswith('''Something there'''      )      )

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

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

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







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

										lowercase   :       Any								=3
										lowercase   :       Optional[Any]								=generator(
										    '''Something there'''		,				num_return_sequences=UpperCAmelCase__		,				num_beams=UpperCAmelCase__		,				)
										lowercase   :       Optional[int]								=[
										    {'''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(UpperCAmelCase__		,				UpperCAmelCase__      )

										lowercase   :       Optional[Any]								=generator('''This is a test'''		,				do_sample=UpperCAmelCase__		,				num_return_sequences=2		,				return_tensors=UpperCAmelCase__      )
										self.assertEqual(
										    UpperCAmelCase__		,				[
										        {'''generated_token_ids''': ANY(torch.Tensor      )},
										        {'''generated_token_ids''': ANY(torch.Tensor      )},
										    ]		,				)
										lowercase   :       Any								=generator.model.config.eos_token_id
										lowercase   :       Optional[int]								='''<pad>'''
										lowercase   :       Tuple								=generator(
										    ['''This is a test''', '''This is a second test''']		,				do_sample=UpperCAmelCase__		,				num_return_sequences=2		,				batch_size=2		,				return_tensors=UpperCAmelCase__		,				)
										self.assertEqual(
										    UpperCAmelCase__		,				[
										        [
										            {'''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    :		Tuple      ):
										'''simple docstring'''
										lowercase   :       List[str]								=pipeline('''text2text-generation'''		,				model='''patrickvonplaten/t5-tiny-random'''		,				framework='''tf'''      )
										# do_sample=False necessary for reproducibility
										lowercase   :       List[str]								=generator('''Something there'''		,				do_sample=UpperCAmelCase__      )
										self.assertEqual(UpperCAmelCase__		,				[{'''generated_text''': ''''''}]      )








'''simple docstring'''





import math






def 							_lowerCAmelCase (      __magic_name__	:    float      ,   __magic_name__	:    float	)							->     float:
						if (
						    not isinstance(__magic_name__      ,   (int, float)	)
						    or power_factor < -1
						    or power_factor > 1
						):
												raise ValueError('''power_factor must be a valid float value between -1 and 1.'''	)
						return apparent_power * power_factor






def 							_lowerCAmelCase (      __magic_name__	:    float      ,   __magic_name__	:    float	)							->     float:
						if (
						    not isinstance(__magic_name__      ,   (int, float)	)
						    or power_factor < -1
						    or power_factor > 1
						):
												raise ValueError('''power_factor must be a valid float value between -1 and 1.'''	)
						return apparent_power * math.sqrt(1 - power_factor**2	)


if __name__ == "__main__":
							import doctest

							doctest.testmod()





