

import numpy as np
from PIL import Image






def        UpperCamelCase_(							_snake_case   :  np.ndarray       ,     _snake_case   :  int       ,     _snake_case   :  int	):




			"""simple docstring"""






			__a        =np.array(_snake_case	)
			if arr.shape[0] != arr.shape[1]:
						raise ValueError('The input array is not a square matrix'	)
			__a        =0
			__a        =0
			__a        =0
			__a        =0

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

			return updated_arr






def        UpperCamelCase_(							_snake_case   :  np.ndarray       ,     _snake_case   :  int       ,     _snake_case   :  int	):




			"""simple docstring"""






			__a        =np.array(_snake_case	)
			if arr.shape[0] != arr.shape[1]:
						raise ValueError('The input array is not a square matrix'	)
			__a        =0
			__a        =0
			__a        =0
			__a        =0

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

			return updated_arr


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

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

						# Loading the image
						_lowerCAmelCase					:			Optional[Any]  				=			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()









from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType






class 	__magic_name__    (			lowerCAmelCase_      ):
			SCREAMING_SNAKE_CASE							   =						['image_processor', 'tokenizer']
			SCREAMING_SNAKE_CASE							   =						'BridgeTowerImageProcessor'
			SCREAMING_SNAKE_CASE							   =						('RobertaTokenizer', 'RobertaTokenizerFast')





			def __init__(		self					,  __snake_case					,  __snake_case					)   -> Optional[int]:




						'''simple docstring'''
						super().__init__(__snake_case					,  __snake_case					)





			def __call__(		self					,  __snake_case					,  __snake_case = None					,  __snake_case = True					,  __snake_case = False					,  __snake_case = None					,  __snake_case = None					,  __snake_case = 0					,  __snake_case = None					,  __snake_case = None					,  __snake_case = None					,  __snake_case = False					,  __snake_case = False					,  __snake_case = False					,  __snake_case = False					,  __snake_case = True					,  __snake_case = None					,  **__snake_case					,  )   -> BatchEncoding:




						'''simple docstring'''
						__a        =self.tokenizer(
						    text=__snake_case					,  add_special_tokens=__snake_case					,  padding=__snake_case					,  truncation=__snake_case					,  max_length=__snake_case					,  stride=__snake_case					,  pad_to_multiple_of=__snake_case					,  return_token_type_ids=__snake_case					,  return_attention_mask=__snake_case					,  return_overflowing_tokens=__snake_case					,  return_special_tokens_mask=__snake_case					,  return_offsets_mapping=__snake_case					,  return_length=__snake_case					,  verbose=__snake_case					,  return_tensors=__snake_case					,  **__snake_case					,  )
						# add pixel_values + pixel_mask
						__a        =self.image_processor(
						    __snake_case					,  return_tensors=__snake_case					,  do_normalize=__snake_case					,  do_center_crop=__snake_case					,  **__snake_case					)
						encoding.update(__snake_case					)

						return encoding





			def 		__magic_name__    (		self					,  *__snake_case					,  **__snake_case					)   -> str:




						'''simple docstring'''
						return self.tokenizer.batch_decode(*__snake_case					,  **__snake_case					)





			def 		__magic_name__    (		self					,  *__snake_case					,  **__snake_case					)   -> Optional[Any]:




						'''simple docstring'''
						return self.tokenizer.decode(*__snake_case					,  **__snake_case					)





			@property
			def 		__magic_name__    (		self					)   -> Union[str, Any]:




						'''simple docstring'''
						__a        =self.tokenizer.model_input_names
						__a        =self.image_processor.model_input_names
						return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names					)					)






