"""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 				snake_case       ( unittest.TestCase				):




					"""simple docstring"""

					snake_case__				    = MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
					snake_case__				    = TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING







					def 		__lowerCAmelCase						(				self   :	Dict    ,lowerCamelCase__   :	Optional[Any]    ,lowerCamelCase__   :	Any    ,lowerCamelCase__   :	Any			):
									UpperCAmelCase__             =							TextaTextGenerationPipeline(model=lowerCamelCase__    ,tokenizer=lowerCamelCase__			)
									return generator, ["Something to write", "Something else"]







					def 		__lowerCAmelCase						(				self   :	Dict    ,lowerCamelCase__   :	Optional[Any]    ,lowerCamelCase__   :	Optional[Any]			):
									UpperCAmelCase__             =							generator('Something there'			)
									self.assertEqual(lowerCamelCase__    ,[{'generated_text': ANY(lowerCamelCase__			)}]			)
									# 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=lowerCamelCase__			)
									self.assertEqual(
									    lowerCamelCase__    ,[
									        [{'generated_text': ANY(lowerCamelCase__			)}, {'generated_text': ANY(lowerCamelCase__			)}],
									        [{'generated_text': ANY(lowerCamelCase__			)}, {'generated_text': ANY(lowerCamelCase__			)}],
									    ]    ,)

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

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







					@require_torch
					def 		__lowerCAmelCase						(				self   :	Optional[Any]			):
									UpperCAmelCase__             =							pipeline('text2text-generation'    ,model='patrickvonplaten/t5-tiny-random'    ,framework='pt'			)
									# do_sample=False necessary for reproducibility
									UpperCAmelCase__             =							generator('Something there'    ,do_sample=lowerCamelCase__			)
									self.assertEqual(lowerCamelCase__    ,[{'generated_text': ''}]			)

									UpperCAmelCase__             =							3
									UpperCAmelCase__             =							generator(
									    'Something there'    ,num_return_sequences=lowerCamelCase__    ,num_beams=lowerCamelCase__    ,)
									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(lowerCamelCase__    ,lowerCamelCase__			)

									UpperCAmelCase__             =							generator('This is a test'    ,do_sample=lowerCamelCase__    ,num_return_sequences=2    ,return_tensors=lowerCamelCase__			)
									self.assertEqual(
									    lowerCamelCase__    ,[
									        {'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=lowerCamelCase__    ,num_return_sequences=2    ,batch_size=2    ,return_tensors=lowerCamelCase__    ,)
									self.assertEqual(
									    lowerCamelCase__    ,[
									        [
									            {'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=lowerCamelCase__			)
									self.assertEqual(lowerCamelCase__    ,[{'generated_text': ''}]			)







'''simple docstring'''
def 			a      (			__a   )  ->	"list[int]":



					'''simple docstring'''






					if upper_limit < 0:
										raise ValueError('''Limit for the Catalan sequence must be ≥ 0'''   )

					UpperCamelCase__   :Optional[Any]												= [0] * (upper_limit + 1)

					# Base case: C(0) = C(1) = 1
					UpperCamelCase__   :int												= 1
					if upper_limit > 0:
										UpperCamelCase__   :int												= 1

					# Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i
					for i in range(2 ,					upper_limit + 1   ):
										for j in range(__a   ):
															catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1]

					return catalan_list


if __name__ == "__main__":
		print('''\n********* Catalan Numbers Using Dynamic Programming ************\n''')
		print('''\n*** Enter -1 at any time to quit ***''')
		print('''\nEnter the upper limit (≥ 0) for the Catalan number sequence: ''', end='''''')
		try:
				while True:
						__snake_case							      =     int(input().strip())
						if N < 0:
								print('''\n********* Goodbye!! ************''')
								break
						else:
								print(F"""The Catalan numbers from 0 through {N} are:""")
								print(catalan_numbers(N))
								print('''Try another upper limit for the sequence: ''', end='''''')
		except (NameError, ValueError):
				print('''\n********* Invalid input, goodbye! ************\n''')

		import doctest

		doctest.testmod()