





'''simple docstring'''


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





     def 							lowercase__				(			self		: Tuple						):





        """simple docstring"""




        lowercase_      :List[str]         =			torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]						)
        lowercase_      :Union[str, Any]         =			get_activation("gelu"						)
        self.assertTrue(torch.allclose(gelu_python(lowercase						)     ,				torch_builtin(lowercase						)						)						)
        self.assertFalse(torch.allclose(gelu_python(lowercase						)     ,				gelu_new(lowercase						)						)						)





     def 							lowercase__				(			self		: Dict						):





        """simple docstring"""




        lowercase_      :Optional[int]         =			torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]						)
        lowercase_      :Optional[int]         =			get_activation("gelu"						)
        lowercase_      :Optional[Any]         =			get_activation("gelu_10"						)

        lowercase_      :List[str]         =			torch_builtin(lowercase						)
        lowercase_      :Optional[int]         =			geluaa(lowercase						)

        lowercase_      :List[Any]         =			torch.where(y_gelu_aa < 10.0     ,				1     ,				0						)

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





     def 							lowercase__				(			self		: Union[str, Any]						):





        """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(lowercase						):
           get_activation("bogus"						)
        with self.assertRaises(lowercase						):
           get_activation(lowercase						)







     def 							lowercase__				(			self		: List[Any]						):





        """simple docstring"""




        lowercase_      :str         =			get_activation("gelu"						)
        lowercase_      :Optional[int]         =			1
        lowercase_      :Any         =			get_activation("gelu"						)
        self.assertEqual(acta.a     ,				1						)
        with self.assertRaises(lowercase						):
           lowercase_      :int         =			acta.a









'''simple docstring'''


import numpy as np
def 							UpperCAmelCase_  (						__lowerCamelCase : str     ,__lowerCamelCase : Optional[Any]     ,__lowerCamelCase : int     ,__lowerCamelCase : List[str]     ,__lowerCamelCase : List[Any]			):
   lowercase_      :Dict         =			int(np.ceil((x_end - xa) / h			)			)
   lowercase_      :Optional[int]         =			np.zeros((n + 1,)			)
   lowercase_      :Tuple         =			ya
   lowercase_      :List[str]         =			xa

   for k in range(__lowerCamelCase			):
      lowercase_      :Any         =			f(__lowerCamelCase     ,y[k]			)
      lowercase_      :Optional[Any]         =			f(x + 0.5 * h     ,y[k] + 0.5 * h * ka			)
      lowercase_      :Optional[Any]         =			f(x + 0.5 * h     ,y[k] + 0.5 * h * ka			)
      lowercase_      :Any         =			f(x + h     ,y[k] + h * ka			)
      lowercase_      :Tuple         =			y[k] + (1 / 6) * h * (ka + 2 * ka + 2 * ka + ka)
      x += h

   return y


if __name__ == "__main__":
 import doctest

 doctest.testmod()


