




import math

import tensorflow as tf
from packaging import version





def        __UpperCAmelCase						(							lowerCamelCase_ :     Any  )       ->  Tuple:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : int					  =      tf.convert_to_tensor(lowerCamelCase_  )
			SCREAMING_SNAKE_CASE_   : Any					  =      0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0  )  ,							x.dtype  )  ))

			return x * cdf





def        __UpperCAmelCase						(							lowerCamelCase_ :     Union[str, Any]  )       ->  List[Any]:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      tf.convert_to_tensor(lowerCamelCase_  )
			SCREAMING_SNAKE_CASE_   : Tuple					  =      tf.cast(math.pi  ,							x.dtype  )
			SCREAMING_SNAKE_CASE_   : Dict					  =      tf.cast(0.0_4_4_7_1_5  ,							x.dtype  )
			SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi  ) * (x + coeff * tf.pow(lowerCamelCase_  ,							3  ))  ))

			return x * cdf





def        __UpperCAmelCase						(							lowerCamelCase_ :     Any  )       ->  List[Any]:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Tuple					  =      tf.convert_to_tensor(lowerCamelCase_  )

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





def        __UpperCAmelCase						(							lowerCamelCase_ :     Optional[Any]  )       ->  int:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Optional[int]					  =      tf.convert_to_tensor(lowerCamelCase_  )
			SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      tf.cast(0.0_4_4_7_1_5  ,							x.dtype  )
			SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      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        __UpperCAmelCase						(							lowerCamelCase_ :     int  )       ->  int:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      tf.convert_to_tensor(lowerCamelCase_  )
			SCREAMING_SNAKE_CASE_   : Any					  =      tf.cast(1.7_0_2  ,							x.dtype  )
			return x * tf.math.sigmoid(coeff * x  )





def        __UpperCAmelCase						(							lowerCamelCase_ :     Dict  )       ->  Dict:







			"""simple docstring"""





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





def        __UpperCAmelCase						(							lowerCamelCase_ :     Tuple  ,							lowerCamelCase_ :     Optional[Any]=-1  )       ->  Any:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_  ,    SCREAMING_SNAKE_CASE_   : Dict					  =      tf.split(lowerCamelCase_  ,							2  ,							axis=lowerCamelCase_  )
			return a * tf.math.sigmoid(lowerCamelCase_  )


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





						def        __UpperCAmelCase						(							lowerCamelCase_ :     Optional[Any]  )       ->  Optional[Any]:







									"""simple docstring"""





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

						UpperCamelCase__ :   Any						=							tf.keras.activations.gelu




						UpperCamelCase__ :   Optional[Any]						=							approximate_gelu_wrap
else:
						UpperCamelCase__ :   str						=							_gelu
						UpperCamelCase__ :   Tuple						=							_gelu_new


UpperCamelCase__ :   Any						=							{
    '''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						(							lowerCamelCase_ :     List[str]  )       ->  Optional[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()  )}'  )









from __future__ import annotations

from scipy.special import comb  # type: ignore







class 				lowerCAmelCase_       :






				def __init__(			self      ,snake_case__ ):
							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      list_of_points
							# Degree determines the flexibility of the curve.
							# Degree = 1 will produce a straight line.
							SCREAMING_SNAKE_CASE_   : Tuple					  =      len(snake_case__ ) - 1






				def 		snake_case	(			self      ,snake_case__ ):
							assert 0 <= t <= 1, "Time t must be between 0 and 1."
							SCREAMING_SNAKE_CASE_   : list[float]					  =      []
							for i in range(len(self.list_of_points ) ):
										# basis function for each i
										output_values.append(
										    comb(self.degree      ,snake_case__ ) * ((1 - t) ** (self.degree - i)) * (t**i) )
							# the basis must sum up to 1 for it to produce a valid Bezier curve.
							assert round(sum(snake_case__ )      ,5 ) == 1
							return output_values






				def 		snake_case	(			self      ,snake_case__ ):
							assert 0 <= t <= 1, "Time t must be between 0 and 1."

							SCREAMING_SNAKE_CASE_   : int					  =      self.basis_function(snake_case__ )
							SCREAMING_SNAKE_CASE_   : List[Any]					  =      0.0
							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      0.0
							for i in range(len(self.list_of_points ) ):
										# For all points, sum up the product of i-th basis function and i-th point.
										x += basis_function[i] * self.list_of_points[i][0]
										y += basis_function[i] * self.list_of_points[i][1]
							return (x, y)






				def 		snake_case	(			self      ,snake_case__ = 0.01 ):
							from matplotlib import pyplot as plt  # type: ignore

							SCREAMING_SNAKE_CASE_   : list[float]					  =      []  # x coordinates of points to plot
							SCREAMING_SNAKE_CASE_   : list[float]					  =      []  # y coordinates of points to plot

							SCREAMING_SNAKE_CASE_   : List[str]					  =      0.0
							while t <= 1:
										SCREAMING_SNAKE_CASE_   : int					  =      self.bezier_curve_function(snake_case__ )
										to_plot_x.append(value[0] )
										to_plot_y.append(value[1] )
										t += step_size

							SCREAMING_SNAKE_CASE_   : Dict					  =      [i[0] for i in self.list_of_points]
							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      [i[1] for i in self.list_of_points]

							plt.plot(
							    snake_case__      ,snake_case__      ,color='blue'      ,label='Curve of Degree ' + str(self.degree )      ,)
							plt.scatter(snake_case__      ,snake_case__      ,color='red'      ,label='Control Points' )
							plt.legend()
							plt.show()


if __name__ == "__main__":
						import doctest

						doctest.testmod()

						BezierCurve([(1, 2), (3, 5)]).plot_curve()  # degree 1
						BezierCurve([(0, 0), (5, 5), (5, 0)]).plot_curve()  # degree 2
						BezierCurve([(0, 0), (5, 5), (5, 0), (2.5, -2.5)]).plot_curve()  # degree 3



