





import math

import tensorflow as tf
from packaging import version




def    A_(			A   ):
	UpperCAmelCase_								=     tf.convert_to_tensor(__UpperCamelCase   )
	UpperCAmelCase_								=     0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0   )				,      x.dtype   )   ))

	return x * cdf




def    A_(			A   ):
	UpperCAmelCase_								=     tf.convert_to_tensor(__UpperCamelCase   )
	UpperCAmelCase_								=     tf.cast(math.pi				,      x.dtype   )
	UpperCAmelCase_								=     tf.cast(0.044_715				,      x.dtype   )
	UpperCAmelCase_								=     0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi   ) * (x + coeff * tf.pow(__UpperCamelCase				,      3   ))   ))

	return x * cdf




def    A_(			A   ):
	UpperCAmelCase_								=     tf.convert_to_tensor(__UpperCamelCase   )

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




def    A_(			A   ):
	UpperCAmelCase_								=     tf.convert_to_tensor(__UpperCamelCase   )
	UpperCAmelCase_								=     tf.cast(0.044_715				,      x.dtype   )
	UpperCAmelCase_								=     tf.cast(0.7_978_845_608				,      x.dtype   )

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




def    A_(			A   ):
	UpperCAmelCase_								=     tf.convert_to_tensor(__UpperCamelCase   )
	UpperCAmelCase_								=     tf.cast(1.702				,      x.dtype   )
	return x * tf.math.sigmoid(coeff * x   )




def    A_(			A   ):
	return tf.clip_by_value(_gelu(__UpperCamelCase   )				,      -10				,      10   )




def    A_(			A				,      A=-1   ):
	UpperCAmelCase_								=     tf.split(__UpperCamelCase				,      2				,      axis=__UpperCamelCase   )
	return a * tf.math.sigmoid(__UpperCamelCase   )


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




				def    A_(			A   ):
					return tf.keras.activations.gelu(__UpperCamelCase				,      approximate=__UpperCamelCase   )

				UpperCamelCase__   : int					  = tf.keras.activations.gelu
				UpperCamelCase__   : Optional[Any]					  = approximate_gelu_wrap
else:
				UpperCamelCase__   : List[Any]					  = _gelu
				UpperCamelCase__   : Any					  = _gelu_new


UpperCamelCase__   : Dict					  = {
    '''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    A_(			A   ):






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









from __future__ import annotations




def    A_(			A   ):
	if not nums:
		raise ValueError("""List is empty"""   )
	return sum(A   ) / len(A   )


if __name__ == "__main__":
				import doctest

				doctest.testmod()


