"""simple docstring"""







from multiprocessing import Lock, Pipe, Process

# lock used to ensure that two processes do not access a pipe at the same time
_a  :  int=				Lock()
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       str    ,							UpperCAmelCase_					:       int    ,							UpperCAmelCase_					:       int    ,							UpperCAmelCase_					:       str    ,							UpperCAmelCase_					:       str    ,							UpperCAmelCase_					:       Dict    ,							UpperCAmelCase_					:       Any						)							->    Optional[int]:

	'''simple docstring'''





	global process_lock

	# we perform n swaps since after n swaps we know we are sorted
	# we *could* stop early if we are sorted already, but it takes as long to
	# find out we are sorted as it does to sort the list with this algorithm
	for i in range(0    ,							10						):
		if (i + position) % 2 == 0 and r_send is not None:
			# send your value to your right neighbor
			process_lock.acquire()
			r_send[1].send(UpperCAmelCase_						)
			process_lock.release()

			# receive your right neighbor's value
			process_lock.acquire()
			__snake_case    :							int   	=				rr_cv[0].recv()
			process_lock.release()

			# take the lower value since you are on the left
			__snake_case    :							Any   	=				min(UpperCAmelCase_    ,							UpperCAmelCase_						)
		elif (i + position) % 2 != 0 and l_send is not None:
			# send your value to your left neighbor
			process_lock.acquire()
			l_send[1].send(UpperCAmelCase_						)
			process_lock.release()

			# receive your left neighbor's value
			process_lock.acquire()
			__snake_case    :							List[Any]   	=				lr_cv[0].recv()
			process_lock.release()

			# take the higher value since you are on the right
			__snake_case    :							Optional[Any]   	=				max(UpperCAmelCase_    ,							UpperCAmelCase_						)
    # after all swaps are performed, send the values back to main
	result_pipe[1].send(UpperCAmelCase_						)
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       str						)							->    str:

	'''simple docstring'''





	__snake_case    :							Union[str, Any]   	=				[]
	__snake_case    :							List[Any]   	=				[]
	# initialize the list of pipes where the values will be retrieved
	for _ in arr:
		result_pipe.append(Pipe()						)
	# creates the processes
	# the first and last process only have one neighbor so they are made outside
	# of the loop
	__snake_case    :							Tuple   	=				Pipe()
	__snake_case    :							List[Any]   	=				Pipe()
	process_array_.append(
	    Process(
	        target=UpperCAmelCase_    ,							args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0])    ,							)						)
	__snake_case    :							str   	=				temp_rs
	__snake_case    :							List[str]   	=				temp_rr

	for i in range(1    ,							len(UpperCAmelCase_						) - 1						):
		__snake_case    :							Dict   	=				Pipe()
		__snake_case    :							Optional[Any]   	=				Pipe()
		process_array_.append(
		    Process(
		        target=UpperCAmelCase_    ,							args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i])    ,							)						)
		__snake_case    :							Optional[Any]   	=				temp_rs
		__snake_case    :							Optional[Any]   	=				temp_rr

	process_array_.append(
	    Process(
	        target=UpperCAmelCase_    ,							args=(
	            len(UpperCAmelCase_						) - 1,
	            arr[len(UpperCAmelCase_						) - 1],
	            temp_ls,
	            None,
	            temp_lr,
	            None,
	            result_pipe[len(UpperCAmelCase_						) - 1],
	        )    ,							)						)

	# start the processes
	for p in process_array_:
		p.start()

	# wait for the processes to end and write their values to the list
	for p in range(0    ,							len(UpperCAmelCase_						)						):
		__snake_case    :							Union[str, Any]   	=				result_pipe[p][0].recv()
		process_array_[p].join()
	return arr
def 						__UpperCAmelCase       (					)							->    Optional[int]:

	'''simple docstring'''





	__snake_case    :							Union[str, Any]   	=				list(range(10    ,							0    ,							-1						)						)
	print('Initial List'						)
	print(*UpperCAmelCase_						)
	__snake_case    :							Tuple   	=				odd_even_transposition(UpperCAmelCase_						)
	print('Sorted List\n'						)
	print(*UpperCAmelCase_						)


if __name__ == "__main__":
	main()






"""simple docstring"""







import math

import tensorflow as tf
from packaging import version
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       Union[str, Any]						)							->    Any:

	'''simple docstring'''





	__snake_case    :							List[str]   	=				tf.convert_to_tensor(UpperCAmelCase_						)
	__snake_case    :							List[str]   	=				0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0						)    ,							x.dtype						)						))

	return x * cdf
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       Tuple						)							->    Optional[Any]:

	'''simple docstring'''





	__snake_case    :							Optional[int]   	=				tf.convert_to_tensor(UpperCAmelCase_						)
	__snake_case    :							Any   	=				tf.cast(math.pi    ,							x.dtype						)
	__snake_case    :							List[Any]   	=				tf.cast(0.044_715    ,							x.dtype						)
	__snake_case    :							Union[str, Any]   	=				0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi						) * (x + coeff * tf.pow(UpperCAmelCase_    ,							3						))						))

	return x * cdf
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       Tuple						)							->    List[Any]:

	'''simple docstring'''





	__snake_case    :							Optional[int]   	=				tf.convert_to_tensor(UpperCAmelCase_						)

	return x * tf.tanh(tf.math.softplus(UpperCAmelCase_						)						)
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       Tuple						)							->    List[str]:

	'''simple docstring'''





	__snake_case    :							Union[str, Any]   	=				tf.convert_to_tensor(UpperCAmelCase_						)
	__snake_case    :							Dict   	=				tf.cast(0.044_715    ,							x.dtype						)
	__snake_case    :							int   	=				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       (					UpperCAmelCase_					:       int						)							->    Dict:

	'''simple docstring'''





	__snake_case    :							Any   	=				tf.convert_to_tensor(UpperCAmelCase_						)
	__snake_case    :							Dict   	=				tf.cast(1.702    ,							x.dtype						)
	return x * tf.math.sigmoid(coeff * x						)
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       Union[str, Any]						)							->    List[Any]:

	'''simple docstring'''





	return tf.clip_by_value(_gelu(UpperCAmelCase_						)    ,							-10    ,							10						)
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       Union[str, Any]    ,							UpperCAmelCase_					:       Any=-1						)							->    int:

	'''simple docstring'''





	__snake_case	,       __snake_case    :							str   	=				tf.split(UpperCAmelCase_    ,							2    ,							axis=UpperCAmelCase_						)
	return a * tf.math.sigmoid(UpperCAmelCase_						)


if version.parse(tf.version.VERSION) >= version.parse("2.4"):
	def 						__UpperCAmelCase       (					UpperCAmelCase_					:       Tuple						)							->    int:

		'''simple docstring'''





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

	_a  :  Tuple=				tf.keras.activations.gelu

	_a  :  Tuple=				approximate_gelu_wrap
else:
	_a  :  Any=				_gelu
	_a  :  str=				_gelu_new


_a  :  List[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       (					UpperCAmelCase_					:       Optional[Any]						)							->    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()						)}"						)





