


"""simple docstring"""




import math

import tensorflow as tf
from packaging import version

def        lowercase							(		lowerCAmelCase__ :     Tuple			) ->      Union[str, Any]:
		__a           =			tf.convert_to_tensor(lowerCAmelCase__			)
		__a           =			0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0			)    ,					x.dtype			)			))

		return x * cdf

def        lowercase							(		lowerCAmelCase__ :     Dict			) ->      str:
		__a           =			tf.convert_to_tensor(lowerCAmelCase__			)
		__a           =			tf.cast(math.pi    ,					x.dtype			)
		__a           =			tf.cast(0.04_47_15    ,					x.dtype			)
		__a           =			0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi			) * (x + coeff * tf.pow(lowerCAmelCase__    ,					3			))			))

		return x * cdf

def        lowercase							(		lowerCAmelCase__ :     Dict			) ->      Optional[int]:
		__a           =			tf.convert_to_tensor(lowerCAmelCase__			)

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

def        lowercase							(		lowerCAmelCase__ :     str			) ->      Optional[Any]:
		__a           =			tf.convert_to_tensor(lowerCAmelCase__			)
		__a           =			tf.cast(0.04_47_15    ,					x.dtype			)
		__a           =			tf.cast(0.79_78_84_56_08    ,					x.dtype			)

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

def        lowercase							(		lowerCAmelCase__ :     Optional[Any]			) ->      Union[str, Any]:
		__a           =			tf.convert_to_tensor(lowerCAmelCase__			)
		__a           =			tf.cast(1.7_02    ,					x.dtype			)
		return x * tf.math.sigmoid(coeff * x			)

def        lowercase							(		lowerCAmelCase__ :     Optional[Any]			) ->      Union[str, Any]:
		return tf.clip_by_value(_gelu(lowerCAmelCase__			)    ,					-10    ,					10			)

def        lowercase							(		lowerCAmelCase__ :     Union[str, Any]    ,					lowerCAmelCase__ :     Any=-1			) ->      str:
		__a      ,     __a           =			tf.split(lowerCAmelCase__    ,					2    ,					axis=lowerCAmelCase__			)
		return a * tf.math.sigmoid(lowerCAmelCase__			)


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

				def        lowercase							(		lowerCAmelCase__ :     Optional[int]			) ->      List[str]:
						return tf.keras.activations.gelu(lowerCAmelCase__    ,					approximate=lowerCAmelCase__			)

				lowercase_			     =  tf.keras.activations.gelu




				lowercase_			     =  approximate_gelu_wrap
else:
				lowercase_			     =  _gelu
				lowercase_			     =  _gelu_new


lowercase_			     =  {
    "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							(		lowerCAmelCase__ :     Union[str, Any]			) ->      int:
		if activation_string in ACTaFN:
				return ACTaFN[activation_string]
		else:
				raise KeyError(f'''function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()			)}'''			)










"""simple docstring"""




import numpy as np

def        lowercase							(		lowerCAmelCase__ :     np.ndarray    ,					lowerCAmelCase__ :     float			) ->      np.ndarray:
		return np.where(vector > 0    ,					lowerCAmelCase__    ,					(alpha * (np.exp(lowerCAmelCase__			) - 1))			)


if __name__ == "__main__":
				import doctest

				doctest.testmod()






