






'''simple docstring'''




from typing import List, Optional, Tuple

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_herbert import HerbertTokenizer


lowerCAmelCase__          =						logging.get_logger(__name__)

lowerCAmelCase__          =						{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

lowerCAmelCase__          =						{
    '''vocab_file''': {
        '''allegro/herbert-base-cased''': '''https://huggingface.co/allegro/herbert-base-cased/resolve/main/vocab.json'''
    },
    '''merges_file''': {
        '''allegro/herbert-base-cased''': '''https://huggingface.co/allegro/herbert-base-cased/resolve/main/merges.txt'''
    },
}

lowerCAmelCase__          =						{'''allegro/herbert-base-cased''': 514}
lowerCAmelCase__          =						{}







class       __lowercase					(UpperCAmelCase__    ):
	_lowerCamelCase       			=  VOCAB_FILES_NAMES
	_lowerCamelCase       			=  PRETRAINED_VOCAB_FILES_MAP
	_lowerCamelCase       			=  PRETRAINED_INIT_CONFIGURATION
	_lowerCamelCase       			=  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	_lowerCamelCase       			=  HerbertTokenizer

	def __init__(      self   :						Any  ,					UpperCAmelCase_   :						Union[str, Any]=None  ,					UpperCAmelCase_   :						Optional[Any]=None  ,					UpperCAmelCase_   :						Any=None  ,					UpperCAmelCase_   :						Optional[Any]="<s>"  ,					UpperCAmelCase_   :						Optional[Any]="<unk>"  ,					UpperCAmelCase_   :						Union[str, Any]="<pad>"  ,					UpperCAmelCase_   :						Union[str, Any]="<mask>"  ,					UpperCAmelCase_   :						str="</s>"  ,					**UpperCAmelCase_   :						List[Any]  ,					):
			super().__init__(
			    __lowerCAmelCase  ,					__lowerCAmelCase  ,					tokenizer_file=__lowerCAmelCase  ,					cls_token=__lowerCAmelCase  ,					unk_token=__lowerCAmelCase  ,					pad_token=__lowerCAmelCase  ,					mask_token=__lowerCAmelCase  ,					sep_token=__lowerCAmelCase  ,					**__lowerCAmelCase  ,					)

	def      __UpperCamelCase							(      self   :						str  ,					UpperCAmelCase_   :						List[int]  ,					UpperCAmelCase_   :						Optional[List[int]] = None):
			UpperCamelCase__				:					Dict					=					[self.cls_token_id]
			UpperCamelCase__				:					Tuple					=					[self.sep_token_id]
			if token_ids_a is None:
					return cls + token_ids_a + sep

			return cls + token_ids_a + sep + token_ids_a + sep

	def      __UpperCamelCase							(      self   :						Any  ,					UpperCAmelCase_   :						List[int]  ,					UpperCAmelCase_   :						Optional[List[int]] = None  ,					UpperCAmelCase_   :						bool = False):






			if already_has_special_tokens:
					return super().get_special_tokens_mask(
					    token_ids_a=__lowerCAmelCase  ,					token_ids_a=__lowerCAmelCase  ,					already_has_special_tokens=__lowerCAmelCase)

			if token_ids_a is None:
					return [1] + ([0] * len(__lowerCAmelCase)) + [1]
			return [1] + ([0] * len(__lowerCAmelCase)) + [1] + ([0] * len(__lowerCAmelCase)) + [1]

	def      __UpperCamelCase							(      self   :						List[str]  ,					UpperCAmelCase_   :						List[int]  ,					UpperCAmelCase_   :						Optional[List[int]] = None):
			UpperCamelCase__				:					int					=					[self.sep_token_id]
			UpperCamelCase__				:					List[str]					=					[self.cls_token_id]

			if token_ids_a is None:
					return len(cls + token_ids_a + sep) * [0]
			return len(cls + token_ids_a + sep) * [0] + len(token_ids_a + sep) * [1]





	def      __UpperCamelCase							(      self   :						List[str]  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						Optional[str] = None):
			UpperCamelCase__				:					Union[str, Any]					=					self._tokenizer.model.save(__lowerCAmelCase  ,					name=__lowerCAmelCase)
			return tuple(__lowerCAmelCase)












'''simple docstring'''




import numpy as np
from PIL import Image







def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_     ,      lowerCamelCase_)							->     np.ndarray:
		UpperCamelCase__				:					List[Any]					=					np.array(lowerCamelCase_)
		if arr.shape[0] != arr.shape[1]:
				raise ValueError('The input array is not a square matrix')
		UpperCamelCase__				:					Tuple					=					0
		UpperCamelCase__				:					int					=					0
		UpperCamelCase__				:					Optional[int]					=					0
		UpperCamelCase__				:					str					=					0

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

		return updated_arr







def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_     ,      lowerCamelCase_)							->     np.ndarray:
		UpperCamelCase__				:					Tuple					=					np.array(lowerCamelCase_)
		if arr.shape[0] != arr.shape[1]:
				raise ValueError('The input array is not a square matrix')
		UpperCamelCase__				:					Optional[int]					=					0
		UpperCamelCase__				:					int					=					0
		UpperCamelCase__				:					List[str]					=					0
		UpperCamelCase__				:					List[Any]					=					0

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




