




"""simple docstring"""





import numpy as np
from PIL import Image

def        _UpperCamelCase     (      UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)      ->      np.ndarray:


			"""simple docstring"""
			__UpperCAmelCase						:			str												=       np.array(UpperCamelCase				)
			if arr.shape[0] != arr.shape[1]:
						raise ValueError("The input array is not a square matrix"				)
			__UpperCAmelCase						:			Any												=       0
			__UpperCAmelCase						:			Dict												=       0
			__UpperCAmelCase						:			Tuple												=       0
			__UpperCAmelCase						:			Tuple												=       0

			# compute the shape of the output matrix
			__UpperCAmelCase						:			Optional[int]												=       (arr.shape[0] - size) // stride + 1
			# initialize the output matrix with zeros of shape maxpool_shape
			__UpperCAmelCase						:			List[str]												=       np.zeros((maxpool_shape, maxpool_shape)				)

			while i < arr.shape[0]:
						if i + size > arr.shape[0]:
									# if the end of the matrix is reached, break
									break
						while j < arr.shape[1]:
									# if the end of the matrix is reached, break
									if j + size > arr.shape[1]:
												break
									# compute the maximum of the pooling matrix
									__UpperCAmelCase						:			str												=       np.max(arr[i : i + size, j : j + size]				)
									# shift the pooling matrix by stride of column pixels
									j += stride
									mat_j += 1

						# shift the pooling matrix by stride of row pixels
						i += stride
						mat_i += 1

						# reset the column index to 0
						__UpperCAmelCase						:			int												=       0
						__UpperCAmelCase						:			int												=       0

			return updated_arr

def        _UpperCamelCase     (      UpperCamelCase					,							UpperCamelCase					,							UpperCamelCase				)      ->      np.ndarray:


			"""simple docstring"""
			__UpperCAmelCase						:			List[str]												=       np.array(UpperCamelCase				)
			if arr.shape[0] != arr.shape[1]:
						raise ValueError("The input array is not a square matrix"				)
			__UpperCAmelCase						:			Tuple												=       0
			__UpperCAmelCase						:			List[str]												=       0
			__UpperCAmelCase						:			Tuple												=       0
			__UpperCAmelCase						:			Any												=       0

			# compute the shape of the output matrix
			__UpperCAmelCase						:			Tuple												=       (arr.shape[0] - size) // stride + 1
			# initialize the output matrix with zeros of shape avgpool_shape
			__UpperCAmelCase						:			str												=       np.zeros((avgpool_shape, avgpool_shape)				)

			while i < arr.shape[0]:
						# if the end of the matrix is reached, break
						if i + size > arr.shape[0]:
									break
						while j < arr.shape[1]:
									# if the end of the matrix is reached, break
									if j + size > arr.shape[1]:
												break
									# compute the average of the pooling matrix
									__UpperCAmelCase						:			Tuple												=       int(np.average(arr[i : i + size, j : j + size]				)				)
									# shift the pooling matrix by stride of column pixels
									j += stride
									mat_j += 1

						# shift the pooling matrix by stride of row pixels
						i += stride
						mat_i += 1
						# reset the column index to 0
						__UpperCAmelCase						:			Tuple												=       0
						__UpperCAmelCase						:			Optional[Any]												=       0

			return updated_arr


# Main Function
if __name__ == "__main__":
					from doctest import testmod

					testmod(name="""avgpooling""", verbose=True)

					# Loading the image
					A				=							Image.open("""path_to_image""")

					# Converting the image to numpy array and maxpooling, displaying the result
					# Ensure that the image is a square matrix

					Image.fromarray(maxpooling(np.array(image), size=3, stride=2)).show()

					# Converting the image to numpy array and averagepooling, displaying the result
					# Ensure that the image is a square matrix

					Image.fromarray(avgpooling(np.array(image), size=3, stride=2)).show()










def  a__ (__lowercase							:int					,  __lowercase							:int   )		-> int:
				return abs(__lowercase   ) if a == 0 else greatest_common_divisor(b % a					,  __lowercase   )



def  a__ (__lowercase							:int					,  __lowercase							:int   )		-> int:
				while y:  # --> when y=0 then loop will terminate and return x as final GCD.
								_A  ,				_A	:				Union[str, Any]   =      y, x % y
				return abs(__lowercase   )



def  a__ ()		-> Optional[Any]:
				try:
								_A	:				Optional[Any]   =      input('''Enter two integers separated by comma (,): '''   ).split(''','''   )
								_A	:				List[Any]   =      int(nums[0]   )
								_A	:				Optional[int]   =      int(nums[1]   )
								print(
								    f"""greatest_common_divisor({num_a}, {num_a}) = """
								    f"""{greatest_common_divisor(__lowercase					,  __lowercase   )}"""   )
								print(f"""By iterative gcd({num_a}, {num_a}) = {gcd_by_iterative(__lowercase					,  __lowercase   )}"""   )
				except (IndexError, UnboundLocalError, ValueError):
								print('''Wrong input'''   )


if __name__ == "__main__":
	main()



