



'''simple docstring'''





import math

import tensorflow as tf
from packaging import version

def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      lowerCamelCase								=		tf.convert_to_tensor(UpperCAmelCase__ )
      lowerCamelCase								=		0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0 )   ,   x.dtype ) ))

      return x * cdf

def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      lowerCamelCase								=		tf.convert_to_tensor(UpperCAmelCase__ )
      lowerCamelCase								=		tf.cast(math.pi   ,   x.dtype )
      lowerCamelCase								=		tf.cast(0.0_4_4_7_1_5   ,   x.dtype )
      lowerCamelCase								=		0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi ) * (x + coeff * tf.pow(UpperCAmelCase__   ,   3 )) ))

      return x * cdf

def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      lowerCamelCase								=		tf.convert_to_tensor(UpperCAmelCase__ )

      return x * tf.tanh(tf.math.softplus(UpperCAmelCase__ ) )

def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      lowerCamelCase								=		tf.convert_to_tensor(UpperCAmelCase__ )
      lowerCamelCase								=		tf.cast(0.0_4_4_7_1_5   ,   x.dtype )
      lowerCamelCase								=		tf.cast(0.7_9_7_8_8_4_5_6_0_8   ,   x.dtype )

      return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x) ))

def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      lowerCamelCase								=		tf.convert_to_tensor(UpperCAmelCase__ )
      lowerCamelCase								=		tf.cast(1.7_0_2   ,   x.dtype )
      return x * tf.math.sigmoid(coeff * x )

def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      return tf.clip_by_value(_gelu(UpperCAmelCase__ )   ,   -10   ,   10 )

def     __lowercase(	UpperCAmelCase__   ,   UpperCAmelCase__=-1 ):


      """simple docstring"""



      lowerCamelCase			,							lowerCamelCase								=		tf.split(UpperCAmelCase__   ,   2   ,   axis=UpperCAmelCase__ )
      return a * tf.math.sigmoid(UpperCAmelCase__ )


if version.parse(tf.version.VERSION) >= version.parse('2.4'):

     def     __lowercase(	UpperCAmelCase__ ):


           """simple docstring"""



           return tf.keras.activations.gelu(UpperCAmelCase__   ,   approximate=UpperCAmelCase__ )

     a_						:     Tuple	     =		tf.keras.activations.gelu






     a_						:     List[Any]	     =		approximate_gelu_wrap
else:
     a_						:     Tuple	     =		_gelu
     a_						:     Optional[int]	     =		_gelu_new


a_						:     Optional[int]	     =		{
    'gelu': gelu,
    'gelu_10': gelu_aa,
    'gelu_fast': gelu_fast,
    'gelu_new': gelu_new,
    'glu': glu,
    'mish': mish,
    'quick_gelu': quick_gelu,
    'relu': tf.keras.activations.relu,
    'sigmoid': tf.keras.activations.sigmoid,
    'silu': tf.keras.activations.swish,
    'swish': tf.keras.activations.swish,
    'tanh': tf.keras.activations.tanh,
}






def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      if activation_string in ACTaFN:
            return ACTaFN[activation_string]
      else:
            raise KeyError(F"""function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys() )}""" )




import unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate

def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      return x + 2






class    lowerCamelCase__  (						unittest.TestCase):
     """simple docstring"""



     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"x = 3"
           lowerCamelCase								=		{}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           assert result == 3
           self.assertDictEqual(__a				,			{"x": 3}    )

           lowerCamelCase								=		"x = y"
           lowerCamelCase								=		{"y": 5}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 5, "y": 5}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"y = add_two(x)"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 3, "y": 5}    )

           # Won't work without the tool
           with CaptureStdout() as out:
                 lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           assert result is None
           assert "tried to execute add_two" in out.out







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"x = 3"
           lowerCamelCase								=		{}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           assert result == 3
           self.assertDictEqual(__a				,			{"x": 3}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"test_dict = {'x': x, 'y': add_two(x)}"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           self.assertDictEqual(__a				,			{"x": 3, "y": 5}    )
           self.assertDictEqual(__a				,			{"x": 3, "test_dict": {"x": 3, "y": 5}}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"x = 3\ny = 5"
           lowerCamelCase								=		{}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 3, "y": 5}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"text = f'This is x: {x}.'"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == "This is x: 3."
           self.assertDictEqual(__a				,			{"x": 3, "text": "This is x: 3."}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"if x <= 3:\n    y = 2\nelse:\n    y = 5"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == 2
           self.assertDictEqual(__a				,			{"x": 3, "y": 2}    )

           lowerCamelCase								=		{"x": 8}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           # evaluate returns the value of the last assignment.
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 8, "y": 5}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"test_list = [x, add_two(x)]"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           self.assertListEqual(__a				,			[3, 5]    )
           self.assertDictEqual(__a				,			{"x": 3, "test_list": [3, 5]}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"y = x"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{}				,			state=__a    )
           assert result == 3
           self.assertDictEqual(__a				,			{"x": 3, "y": 3}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"test_list = [x, add_two(x)]\ntest_list[1]"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 3, "test_list": [3, 5]}    )

           lowerCamelCase								=		"test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"
           lowerCamelCase								=		{"x": 3}
           lowerCamelCase								=		evaluate(__a				,			{"add_two": add_two}				,			state=__a    )
           assert result == 5
           self.assertDictEqual(__a				,			{"x": 3, "test_dict": {"x": 3, "y": 5}}    )







     def 						_a      (self    ):






           '''simple docstring'''



           lowerCamelCase								=		"x = 0\nfor i in range(3):\n    x = i"
           lowerCamelCase								=		{}
           lowerCamelCase								=		evaluate(__a				,			{"range": range}				,			state=__a    )
           assert result == 2
           self.assertDictEqual(__a				,			{"x": 2, "i": 2}    )