






import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
     import torch

     from transformers.activations import gelu_new, gelu_python, get_activation






@require_torch
class 		lowercase_					(	unittest.TestCase   ):






      '''simple docstring'''




      def       __lowerCAmelCase					(      self      :						List[str]  )    ->List[str]:




       """simple docstring"""


       a		  =      torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]  )
       a		  =      get_activation('''gelu'''  )
       self.assertTrue(torch.allclose(gelu_python(__UpperCAmelCase  ) ,					torch_builtin(__UpperCAmelCase  )  )  )
       self.assertFalse(torch.allclose(gelu_python(__UpperCAmelCase  ) ,					gelu_new(__UpperCAmelCase  )  )  )







      def       __lowerCAmelCase					(      self      :						Optional[Any]  )    ->List[Any]:




       """simple docstring"""


       a		  =      torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]  )
       a		  =      get_activation('''gelu'''  )
       a		  =      get_activation('''gelu_10'''  )

       a		  =      torch_builtin(__UpperCAmelCase  )
       a		  =      geluaa(__UpperCAmelCase  )

       a		  =      torch.where(y_gelu_aa < 10.0 ,					1 ,					0  )

       self.assertTrue(torch.max(__UpperCAmelCase  ).item() == 10.0  )
       self.assertTrue(torch.allclose(y_gelu * clipped_mask ,					y_gelu_aa * clipped_mask  )  )







      def       __lowerCAmelCase					(      self      :						List[Any]  )    ->Optional[int]:




       """simple docstring"""


       get_activation('''gelu'''  )
       get_activation('''gelu_10'''  )
       get_activation('''gelu_fast'''  )
       get_activation('''gelu_new'''  )
       get_activation('''gelu_python'''  )
       get_activation('''gelu_pytorch_tanh'''  )
       get_activation('''linear'''  )
       get_activation('''mish'''  )
       get_activation('''quick_gelu'''  )
       get_activation('''relu'''  )
       get_activation('''sigmoid'''  )
       get_activation('''silu'''  )
       get_activation('''swish'''  )
       get_activation('''tanh'''  )
       with self.assertRaises(__UpperCAmelCase  ):
        get_activation('''bogus'''  )
       with self.assertRaises(__UpperCAmelCase  ):
        get_activation(__UpperCAmelCase  )







      def       __lowerCAmelCase					(      self      :						Any  )    ->str:




       """simple docstring"""


       a		  =      get_activation('''gelu'''  )
       a		  =      1
       a		  =      get_activation('''gelu'''  )
       self.assertEqual(acta.a ,					1  )
       with self.assertRaises(__UpperCAmelCase  ):
        a		  =      acta.a






"""simple docstring"""







def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


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

					__SCREAMING_SNAKE_CASE						   =				[0] * (upper_limit + 1)

					# Base case: C(0) = C(1) = 1
					__SCREAMING_SNAKE_CASE						   =				1
					if upper_limit > 0:
										__SCREAMING_SNAKE_CASE						   =				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(lowerCAmelCase_   ):
															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:
						a__				:							List[str]						=     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()
