

'''simple docstring'''





from timeit import timeit

UpperCamelCase_    						=       {
    """MALAYALAM""": True,
    """String""": False,
    """rotor""": True,
    """level""": True,
    """A""": True,
    """BB""": True,
    """ABC""": False,
    """amanaplanacanalpanama""": True,  # "a man a plan a canal panama"
}
# Ensure our test data is valid
assert all((key == key[::-1]) is value for key, value in test_data.items())






def 				_lowerCAmelCase			(   __magic_name__						:     str						)				->  bool:
						lowercase :							Tuple    		=0
						lowercase :							Union[str, Any]    		=len(__magic_name__						) - 1
						while start_i < end_i:
												if s[start_i] == s[end_i]:
																		start_i += 1
																		end_i -= 1
												else:
																		return False
						return True






def 				_lowerCAmelCase			(   __magic_name__						:     str						)				->  bool:
						lowercase :							List[str]    		=len(__magic_name__						) // 2
						lowercase :							List[str]    		=len(__magic_name__						)

						# We need to traverse till half of the length of string
						# as we can get access of the i'th last element from
						# i'th index.
						# eg: [0,1,2,3,4,5] => 4th index can be accessed
						# with the help of 1st index (i==n-i-1)
						# where n is length of string
						return all(s[i] == s[n - i - 1] for i in range(__magic_name__						)						)






def 				_lowerCAmelCase			(   __magic_name__						:     str						)				->  bool:
						if len(__magic_name__						) <= 2:
												return True
						if s[0] == s[len(__magic_name__						) - 1]:
												return is_palindrome_recursive(s[1:-1]						)
						else:
												return False






def 				_lowerCAmelCase			(   __magic_name__						:     str						)				->  bool:
						return s == s[::-1]






def 				_lowerCAmelCase			(   __magic_name__						:     str						)				->  None:
						lowercase :							int    		=f'''all({name}(key) is value for key, value in test_data.items())'''
						lowercase :							Optional[Any]    		=f'''from __main__ import test_data, {name}'''
						lowercase :							int    		=500000
						lowercase :							List[str]    		=timeit(stmt=__magic_name__   , setup=__magic_name__   , number=__magic_name__						)
						print(f'''{name:<35} finished {number:,} runs in {result:.5f} seconds'''						)


if __name__ == "__main__":
							for key, value in test_data.items():
														assert is_palindrome(key) is is_palindrome_recursive(key)
														assert is_palindrome(key) is is_palindrome_slice(key)
														print(f'''{key:21} {value}''')
							print("""a man a plan a canal panama""")

							# finished 500,000 runs in 0.46793 seconds
							benchmark_function("""is_palindrome_slice""")
							# finished 500,000 runs in 0.85234 seconds
							benchmark_function("""is_palindrome""")
							# finished 500,000 runs in 1.32028 seconds
							benchmark_function("""is_palindrome_recursive""")
							# finished 500,000 runs in 2.08679 seconds
							benchmark_function("""is_palindrome_traversal""")








'''simple docstring'''





import re

from flax.core.frozen_dict import freeze
from flax.traverse_util import flatten_dict, unflatten_dict
from jax.experimental import PartitionSpec as P


# Sentinels
UpperCamelCase_    						=       object()

# For specifying empty leaf dict `{}`
UpperCamelCase_    						=       object()






def 				_lowerCAmelCase			(   __magic_name__						:     int   , __magic_name__						:     int						)				->  Optional[int]:
						lowercase :							Optional[Any]    		=tuple((re.compile(x + '''$'''						) for x in qs)						)
						for i in range(len(__magic_name__						) - len(__magic_name__						) + 1						):
												lowercase :							Union[str, Any]    		=[x.match(__magic_name__						) for x, y in zip(__magic_name__   , ks[i:]						)]
												if matches and all(__magic_name__						):
																		return True
						return False






def 				_lowerCAmelCase			(   __magic_name__						:     Dict						)				->  List[str]:
						def replace(__magic_name__						:     Optional[int]   , __magic_name__						:     Optional[Any]						):
												for rule, replacement in rules:
																		if _match(__magic_name__   , __magic_name__						):
																								return replacement
												return val

						return replace






def 				_lowerCAmelCase			(   )				->  int:
						return [
						    # embeddings
						    (("transformer", "wpe", "embedding"), P('''mp'''   , __magic_name__						)),
						    (("transformer", "wte", "embedding"), P('''mp'''   , __magic_name__						)),
						    # atention
						    (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(__magic_name__   , '''mp'''						)),
						    (("attention", "out_proj", "kernel"), P('''mp'''   , __magic_name__						)),
						    (("attention", "out_proj", "bias"), None),
						    # mlp
						    (("mlp", "c_fc", "kernel"), P(__magic_name__   , '''mp'''						)),
						    (("mlp", "c_fc", "bias"), P('''mp'''						)),
						    (("mlp", "c_proj", "kernel"), P('''mp'''   , __magic_name__						)),
						    (("mlp", "c_proj", "bias"), None),
						    # layer norms
						    ((r"ln_\d+", "bias"), None),
						    ((r"\d+", r"ln_\d+", "scale"), None),
						    (("ln_f", "bias"), None),
						    (("ln_f", "scale"), None),
						]







def 				_lowerCAmelCase			(   __magic_name__						:     str						)				->  int:
						lowercase :							int    		=_get_partition_rules()
						lowercase :							Tuple    		=_replacement_rules(__magic_name__						)
						lowercase :							Any    		={k: _unmatched for k in flatten_dict(__magic_name__						)}
						lowercase :							Any    		={k: replace(__magic_name__   , __magic_name__						) for k, v in initd.items()}
						assert _unmatched not in result.values(), "Incomplete partition spec."
						return freeze(unflatten_dict(__magic_name__						)						)





