

"""simple docstring"""





import functools
from math import sqrt
from time import time

def 						__SCREAMING_SNAKE_CASE						(   A_		,  *A_		,  **A_				):
	lowerCAmelCase__			:		str						       =			time()
	lowerCAmelCase__			:		List[str]						       =			func(*A_		,  **A_				)
	lowerCAmelCase__			:		Optional[Any]						       =			time()
	if int(end - start				) > 0:
		print(f'{func.__name__} runtime: {(end - start):0.4f} s'				)
	else:
		print(f'{func.__name__} runtime: {(end - start) * 10_00:0.4f} ms'				)
	return output

def 						__SCREAMING_SNAKE_CASE						(   A_				):
	if n < 0:
		raise Exception('''n is negative'''				)
	if n == 0:
		return [0]
	lowerCAmelCase__			:		int						       =			[0, 1]
	for _ in range(n - 1				):
		fib.append(fib[-1] + fib[-2]				)
	return fib

def 						__SCREAMING_SNAKE_CASE						(   A_				):

	def fib_recursive_term(A_				) -> int:
		if i < 0:
			raise Exception('''n is negative'''				)
		if i < 2:
			return i
		return fib_recursive_term(i - 1				) + fib_recursive_term(i - 2				)

	if n < 0:
		raise Exception('''n is negative'''				)
	return [fib_recursive_term(A_				) for i in range(n + 1				)]

def 						__SCREAMING_SNAKE_CASE						(   A_				):

	@functools.cache
	def fib_recursive_term(A_				) -> int:
		if i < 0:
			raise Exception('''n is negative'''				)
		if i < 2:
			return i
		return fib_recursive_term(i - 1				) + fib_recursive_term(i - 2				)

	if n < 0:
		raise Exception('''n is negative'''				)
	return [fib_recursive_term(A_				) for i in range(n + 1				)]

def 						__SCREAMING_SNAKE_CASE						(   A_				):
	if n < 0:
		raise Exception('''n is negative'''				)
	# Cache must be outside recursuive function
	# other it will reset every time it calls itself.
	lowerCAmelCase__			:		dict[int, int]						       =			{0: 0, 1: 1, 2: 1}  # Prefilled cache

	def rec_fn_memoized(A_				) -> int:
		if num in cache:
			return cache[num]

		lowerCAmelCase__			:		Optional[int]						       =			rec_fn_memoized(num - 1				) + rec_fn_memoized(num - 2				)
		lowerCAmelCase__			:		Dict						       =			value
		return value

	return [rec_fn_memoized(A_				) for i in range(n + 1				)]

def 						__SCREAMING_SNAKE_CASE						(   A_				):
	if n < 0:
		raise Exception('''n is negative'''				)
	if n >= 14_75:
		raise Exception('''n is too large'''				)
	lowerCAmelCase__			:		str						       =			sqrt(5				)
	lowerCAmelCase__			:		Union[str, Any]						       =			(1 + sqrt_a) / 2
	return [round(phi**i / sqrt_a				) for i in range(n + 1				)]


if __name__ == "__main__":
							__UpperCamelCase						:   int							   =	3_0
							time_func(fib_iterative, num)
							time_func(fib_recursive, num)  # Around 3s runtime
							time_func(fib_recursive_cached, num)  # Around 0ms runtime
							time_func(fib_memoization, num)
							time_func(fib_binet, num)







"""simple docstring"""





from cva import COLOR_BGR2GRAY, cvtColor, imread, imshow, waitKey
from numpy import divide, inta, multiply, ravel, sort, zeros_like

def 						__SCREAMING_SNAKE_CASE						(   A_		,  A_=3				):
	lowerCAmelCase__			:		Union[str, Any]						       =			int(mask / 2				)
	# copy image size
	lowerCAmelCase__			:		Dict						       =			zeros_like(A_				)
	for i in range(A_		,  gray_img.shape[0] - bd				):
		for j in range(A_		,  gray_img.shape[1] - bd				):
			# get mask according with mask
			lowerCAmelCase__			:		str						       =			ravel(gray_img[i - bd : i + bd + 1, j - bd : j + bd + 1]				)
			# calculate mask median
			lowerCAmelCase__			:		str						       =			sort(A_				)[inta(divide((multiply(A_		,  A_				))		,  2				) + 1				)]
			lowerCAmelCase__			:		List[str]						       =			median
	return median_img


if __name__ == "__main__":
							# read original image
							__UpperCamelCase						:   Dict							   =	imread('''../image_data/lena.jpg''')
							# turn image in gray scale value
							__UpperCamelCase						:   Optional[Any]							   =	cvtColor(img, COLOR_BGR2GRAY)

							# get values with two different mask size
							__UpperCamelCase						:   int							   =	median_filter(gray, 3)
							__UpperCamelCase						:   Tuple							   =	median_filter(gray, 5)

							# show result images
							imshow('''median filter with 3x3 mask''', medianaxa)
							imshow('''median filter with 5x5 mask''', medianaxa)
							waitKey(0)




