

import math

import tensorflow as tf
from packaging import version






def 			UpperCamelCase_(				_snake_case  :    str      ):




			"""simple docstring"""






			__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 			UpperCamelCase_(				_snake_case  :    int      ):




			"""simple docstring"""






			__a     =tf.convert_to_tensor(__lowerCAmelCase      )
			__a     =tf.cast(math.pi			,	x.dtype      )
			__a     =tf.cast(0.044_715			,	x.dtype      )
			__a     =0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi      ) * (x + coeff * tf.pow(__lowerCAmelCase			,	3      ))      ))

			return x * cdf






def 			UpperCamelCase_(				_snake_case  :    Tuple      ):




			"""simple docstring"""






			__a     =tf.convert_to_tensor(__lowerCAmelCase      )

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






def 			UpperCamelCase_(				_snake_case  :    Optional[int]      ):




			"""simple docstring"""






			__a     =tf.convert_to_tensor(__lowerCAmelCase      )
			__a     =tf.cast(0.044_715			,	x.dtype      )
			__a     =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 			UpperCamelCase_(				_snake_case  :    str      ):




			"""simple docstring"""






			__a     =tf.convert_to_tensor(__lowerCAmelCase      )
			__a     =tf.cast(1.702			,	x.dtype      )
			return x * tf.math.sigmoid(coeff * x      )






def 			UpperCamelCase_(				_snake_case  :    List[Any]      ):




			"""simple docstring"""






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






def 			UpperCamelCase_(				_snake_case  :    List[str]			,	_snake_case  :    Optional[Any]=-1      ):




			"""simple docstring"""






			__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 			UpperCamelCase_(				_snake_case  :    Any      ):




									"""simple docstring"""






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

						_lowerCAmelCase   :     Optional[Any]    							=     tf.keras.activations.gelu


						_lowerCAmelCase   :     Optional[Any]    							=     approximate_gelu_wrap
else:
						_lowerCAmelCase   :     Any    							=     _gelu
						_lowerCAmelCase   :     Any    							=     _gelu_new


_lowerCAmelCase   :     str    							=     {
    "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 			UpperCamelCase_(				_snake_case  :    List[Any]      ):




			"""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()      )}'      )








def 						SCREAMING_SNAKE_CASE__     (   __lowerCAmelCase				):
    if any(not isinstance(__lowerCAmelCase     ,		__lowerCAmelCase				) or x < 0 for x in sequence				):
        raise TypeError("Sequence must be list of non-negative integers"				)
    for _ in range(len(__lowerCAmelCase				)				):
        for i, (rod_upper, rod_lower) in enumerate(zip(__lowerCAmelCase     ,		sequence[1:]				)				):
            if rod_upper > rod_lower:
                sequence[i] -= rod_upper - rod_lower
                sequence[i + 1] += rod_upper - rod_lower
    return sequence


if __name__ == "__main__":
     assert bead_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
     assert bead_sort([7, 9, 4, 3, 5]) == [3, 4, 5, 7, 9]



