import argparse
import os
import re

import packaging.version


_UpperCAmelCase          =						"""examples/"""
_UpperCAmelCase          =						{
    """examples""": (re.compile(r"""^check_min_version\(\"[^\"]+\"\)\s*$""", re.MULTILINE), """check_min_version(\"VERSION\")\n"""),
    """init""": (re.compile(r"""^__version__\s+=\s+\"([^\"]+)\"\s*$""", re.MULTILINE), """__version__ = \"VERSION\"\n"""),
    """setup""": (re.compile(r"""^(\s*)version\s*=\s*\"[^\"]+\",""", re.MULTILINE), r"""\1version=\"VERSION\","""),
    """doc""": (re.compile(r"""^(\s*)release\s*=\s*\"[^\"]+\"$""", re.MULTILINE), """release = \"VERSION\"\n"""),
}
_UpperCAmelCase          =						{
    """init""": """src/transformers/__init__.py""",
    """setup""": """setup.py""",
}
_UpperCAmelCase          =						"""README.md"""




def 							UpperCamelCase		(			__lowercase		:					Dict		,__lowercase		:					Any		,__lowercase		:					Tuple      ):
		'''simple docstring'''




		with open(__lowercase		,'r'		,encoding='utf-8'		,newline='\n'      ) as f:
				A_						:							Dict      = f.read()
		A_  ,     A_						:							Dict      = REPLACE_PATTERNS[pattern]
		A_						:							List[str]      = replace.replace('VERSION'		,__lowercase      )
		A_						:							int      = re_pattern.sub(__lowercase		,__lowercase      )
		with open(__lowercase		,'w'		,encoding='utf-8'		,newline='\n'      ) as f:
				f.write(__lowercase      )




def 							UpperCamelCase		(			__lowercase		:					Union[str, Any]      ):
		'''simple docstring'''




		for folder, directories, fnames in os.walk(__lowercase      ):
				# Removing some of the folders with non-actively maintained examples from the walk
				if "research_projects" in directories:
						directories.remove('research_projects'      )
				if "legacy" in directories:
						directories.remove('legacy'      )
				for fname in fnames:
						if fname.endswith('.py'      ):
								update_version_in_file(os.path.join(__lowercase		,__lowercase      )		,__lowercase		,pattern='examples'      )




def 							UpperCamelCase		(			__lowercase		:					Tuple		,__lowercase		:					Tuple=False      ):
		'''simple docstring'''




		for pattern, fname in REPLACE_FILES.items():
				update_version_in_file(__lowercase		,__lowercase		,__lowercase      )
		if not patch:
				update_version_in_examples(__lowercase      )




def 							UpperCamelCase		(			):
		'''simple docstring'''




		A_						:							Optional[int]      = '🤗 Transformers currently provides the following architectures'
		A_						:							str      = '1. Want to contribute a new model?'
		with open(__lowercase		,'r'		,encoding='utf-8'		,newline='\n'      ) as f:
				A_						:							int      = f.readlines()

		# Find the start of the list.
		A_						:							List[str]      = 0
		while not lines[start_index].startswith(_start_prompt      ):
				start_index += 1
		start_index += 1

		A_						:							List[str]      = start_index
		# Update the lines in the model list.
		while not lines[index].startswith(_end_prompt      ):
				if lines[index].startswith('1.'      ):
						A_						:							str      = lines[index].replace(
						    'https://huggingface.co/docs/transformers/main/model_doc'		,'https://huggingface.co/docs/transformers/model_doc'		,)
				index += 1

		with open(__lowercase		,'w'		,encoding='utf-8'		,newline='\n'      ) as f:
				f.writelines(__lowercase      )




def 							UpperCamelCase		(			):
		'''simple docstring'''




		with open(REPLACE_FILES['init']		,'r'      ) as f:
				A_						:							Any      = f.read()
		A_						:							Union[str, Any]      = REPLACE_PATTERNS['init'][0].search(__lowercase      ).groups()[0]
		return packaging.version.parse(__lowercase      )




def 							UpperCamelCase		(			__lowercase		:					Tuple=False      ):
		'''simple docstring'''




		A_						:							List[Any]      = get_version()
		if patch and default_version.is_devrelease:
				raise ValueError('Can\'t create a patch version from the dev branch, checkout a released version!'      )
		if default_version.is_devrelease:
				A_						:							Any      = default_version.base_version
		elif patch:
				A_						:							str      = f'''{default_version.major}.{default_version.minor}.{default_version.micro + 1}'''
		else:
				A_						:							List[Any]      = f'''{default_version.major}.{default_version.minor + 1}.0'''

		# Now let's ask nicely if that's the right one.
		A_						:							Dict      = input(f'''Which version are you releasing? [{default_version}]'''      )
		if len(__lowercase      ) == 0:
				A_						:							Union[str, Any]      = default_version

		print(f'''Updating version to {version}.'''      )
		global_version_update(__lowercase		,patch=__lowercase      )
		if not patch:
				print('Cleaning main README, don\'t forget to run `make fix-copies`.'      )
				clean_main_ref_in_model_list()




def 							UpperCamelCase		(			):
		'''simple docstring'''




		A_						:							Union[str, Any]      = get_version()
		A_						:							List[str]      = f'''{current_version.major}.{current_version.minor + 1}.0.dev0'''
		A_						:							List[str]      = current_version.base_version

		# Check with the user we got that right.
		A_						:							str      = input(f'''Which version are we developing now? [{dev_version}]'''      )
		if len(__lowercase      ) == 0:
				A_						:							Dict      = dev_version

		print(f'''Updating version to {version}.'''      )
		global_version_update(__lowercase      )
		print('Cleaning main README, don\'t forget to run `make fix-copies`.'      )
		clean_main_ref_in_model_list()


if __name__ == "__main__":
	_UpperCAmelCase          =						argparse.ArgumentParser()
	parser.add_argument("""--post_release""", action="""store_true""", help="""Whether this is pre or post release.""")
	parser.add_argument("""--patch""", action="""store_true""", help="""Whether or not this is a patch release.""")
	_UpperCAmelCase          =						parser.parse_args()
	if not args.post_release:
		pre_release_work(patch=args.patch)
	elif args.patch:
		print("""Nothing to do after a patch :-)""")
	else:
		post_release_work()







import numpy as np
from PIL import Image




def 							UpperCamelCase		(			__lowercase		:					np.ndarray		,__lowercase		:					int		,__lowercase		:					int      ):
		'''simple docstring'''




		A_						:							List[Any]      = np.array(__lowercase      )
		if arr.shape[0] != arr.shape[1]:
				raise ValueError('The input array is not a square matrix'      )
		A_						:							str      = 0
		A_						:							Any      = 0
		A_						:							Optional[int]      = 0
		A_						:							Optional[Any]      = 0

		# compute the shape of the output matrix
		A_						:							str      = (arr.shape[0] - size) // stride + 1
		# initialize the output matrix with zeros of shape maxpool_shape
		A_						:							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
						A_						:							Any      = 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
				A_						:							Tuple      = 0
				A_						:							Optional[int]      = 0

		return updated_arr




def 							UpperCamelCase		(			__lowercase		:					np.ndarray		,__lowercase		:					int		,__lowercase		:					int      ):
		'''simple docstring'''




		A_						:							int      = np.array(__lowercase      )
		if arr.shape[0] != arr.shape[1]:
				raise ValueError('The input array is not a square matrix'      )
		A_						:							Any      = 0
		A_						:							Optional[int]      = 0
		A_						:							List[str]      = 0
		A_						:							Union[str, Any]      = 0

		# compute the shape of the output matrix
		A_						:							int      = (arr.shape[0] - size) // stride + 1
		# initialize the output matrix with zeros of shape avgpool_shape
		A_						:							int      = 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
						A_						:							str      = 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
				A_						:							List[Any]      = 0
				A_						:							int      = 0

		return updated_arr


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

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

	# Loading the image
	_UpperCAmelCase          =						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()






