



import numpy as np
from PIL import Image

def      lowerCAmelCase_					(  _lowercase    :       Union[str, Any]						,       _lowercase    :       Optional[int]						,       _lowercase    :       int)							->	Union[str, Any]:







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

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

			return updated_arr

def      lowerCAmelCase_					(  _lowercase    :       List[Any]						,       _lowercase    :       Optional[Any]						,       _lowercase    :       str)							->	int:







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

			# compute the shape of the output matrix
			a__       :						Union[str, Any]							=  (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__       :						List[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__       :						Dict							=  0
						a__       :						Optional[Any]							=  0

			return updated_arr


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

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

	# Loading the image
	_lowercase		:				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()









import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin

class        snake_case__    (A__ ,     unittest.TestCase		):







						"""simple docstring"""




						__lowerCAmelCase					:Union[str, Any]      =					ProphetNetTokenizer
						__lowerCAmelCase					:Any      =					False

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Union[str, Any]:
									"""simple docstring"""




									super().setUp()

									a__       :						Optional[Any]							=  [
									    """[UNK]""",
									    """[CLS]""",
									    """[SEP]""",
									    """[PAD]""",
									    """[MASK]""",
									    """want""",
									    """##want""",
									    """##ed""",
									    """wa""",
									    """un""",
									    """runn""",
									    """##ing""",
									    """,""",
									    """low""",
									    """lowest""",
									]
									a__       :						List[str]							=  os.path.join(self.tmpdirname ,       VOCAB_FILES_NAMES["""vocab_file"""]  )
									with open(self.vocab_file ,       """w""" ,       encoding="""utf-8"""  ) as vocab_writer:
												vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]  )  )

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase  ) ->				str:
									"""simple docstring"""




									a__       :						Any							=  """UNwant\u00E9d,running"""
									a__       :						Dict							=  """unwanted, running"""
									return input_text, output_text

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Dict:
									"""simple docstring"""




									a__       :						Tuple							=  self.tokenizer_class(self.vocab_file  )

									a__       :						int							=  tokenizer.tokenize("""UNwant\u00E9d,running"""  )
									self.assertListEqual(__lowercase ,       ["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]  )
									self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowercase  ) ,       [9, 6, 7, 1_2, 1_0, 1_1]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Union[str, Any]:
									"""simple docstring"""




									a__       :						str							=  BasicTokenizer()

									self.assertListEqual(tokenizer.tokenize("""ah\u535A\u63A8zz"""  ) ,       ["""ah""", """\u535A""", """\u63A8""", """zz"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				int:
									"""simple docstring"""




									a__       :						int							=  BasicTokenizer(do_lower_case=__lowercase  )

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """  ) ,       ["""hello""", """!""", """how""", """are""", """you""", """?"""]  )
									self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""  ) ,       ["""hello"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[Any]:
									"""simple docstring"""




									a__       :						str							=  BasicTokenizer(do_lower_case=__lowercase ,       strip_accents=__lowercase  )

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """  ) ,       ["""hällo""", """!""", """how""", """are""", """you""", """?"""]  )
									self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""  ) ,       ["""h\u00E9llo"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				str:
									"""simple docstring"""




									a__       :						List[str]							=  BasicTokenizer(do_lower_case=__lowercase ,       strip_accents=__lowercase  )

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """  ) ,       ["""hallo""", """!""", """how""", """are""", """you""", """?"""]  )
									self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""  ) ,       ["""hello"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[Any]:
									"""simple docstring"""




									a__       :						Optional[Any]							=  BasicTokenizer(do_lower_case=__lowercase  )

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """  ) ,       ["""hallo""", """!""", """how""", """are""", """you""", """?"""]  )
									self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""  ) ,       ["""hello"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[int]:
									"""simple docstring"""




									a__       :						List[str]							=  BasicTokenizer(do_lower_case=__lowercase  )

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """  ) ,       ["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[str]:
									"""simple docstring"""




									a__       :						str							=  BasicTokenizer(do_lower_case=__lowercase ,       strip_accents=__lowercase  )

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """  ) ,       ["""HäLLo""", """!""", """how""", """Are""", """yoU""", """?"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[Any]:
									"""simple docstring"""




									a__       :						List[str]							=  BasicTokenizer(do_lower_case=__lowercase ,       strip_accents=__lowercase  )

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """  ) ,       ["""HaLLo""", """!""", """how""", """Are""", """yoU""", """?"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[Any]:
									"""simple docstring"""




									a__       :						Union[str, Any]							=  BasicTokenizer(do_lower_case=__lowercase ,       never_split=["""[UNK]"""]  )

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU? [UNK]"""  ) ,       ["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?""", """[UNK]"""]  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[Any]:
									"""simple docstring"""




									a__       :						Optional[Any]							=  ["""[UNK]""", """[CLS]""", """[SEP]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing"""]

									a__       :						Dict							=  {}
									for i, token in enumerate(__lowercase  ):
												a__       :						Optional[Any]							=  i
									a__       :						str							=  WordpieceTokenizer(vocab=__lowercase ,       unk_token="""[UNK]"""  )

									self.assertListEqual(tokenizer.tokenize(""""""  ) ,       []  )

									self.assertListEqual(tokenizer.tokenize("""unwanted running"""  ) ,       ["""un""", """##want""", """##ed""", """runn""", """##ing"""]  )

									self.assertListEqual(tokenizer.tokenize("""unwantedX running"""  ) ,       ["""[UNK]""", """runn""", """##ing"""]  )

						@require_torch
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[Any]:
									"""simple docstring"""




									a__       :						List[Any]							=  self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""  )

									a__       :						List[Any]							=  ["""A long paragraph for summarization.""", """Another paragraph for summarization."""]
									a__       :						Optional[Any]							=  [1_0_3_7, 2_1_4_6, 2_0_4_2_3, 2_0_0_5, 7_6_8_0, 7_8_4_9, 3_9_8_9, 1_0_1_2, 1_0_2]
									a__       :						List[Any]							=  tokenizer(__lowercase ,       padding=__lowercase ,       return_tensors="""pt"""  )
									self.assertIsInstance(__lowercase ,       __lowercase  )
									a__       :						Optional[int]							=  list(batch.input_ids.numpy()[0]  )
									self.assertListEqual(__lowercase ,       __lowercase  )

									self.assertEqual((2, 9) ,       batch.input_ids.shape  )
									self.assertEqual((2, 9) ,       batch.attention_mask.shape  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[str]:
									"""simple docstring"""




									self.assertTrue(_is_whitespace(""" """  )  )
									self.assertTrue(_is_whitespace("""\t"""  )  )
									self.assertTrue(_is_whitespace("""\r"""  )  )
									self.assertTrue(_is_whitespace("""\n"""  )  )
									self.assertTrue(_is_whitespace("""\u00A0"""  )  )

									self.assertFalse(_is_whitespace("""A"""  )  )
									self.assertFalse(_is_whitespace("""-"""  )  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[Any]:
									"""simple docstring"""




									self.assertTrue(_is_control("""\u0005"""  )  )

									self.assertFalse(_is_control("""A"""  )  )
									self.assertFalse(_is_control(""" """  )  )
									self.assertFalse(_is_control("""\t"""  )  )
									self.assertFalse(_is_control("""\r"""  )  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[Any]:
									"""simple docstring"""




									self.assertTrue(_is_punctuation("""-"""  )  )
									self.assertTrue(_is_punctuation("""$"""  )  )
									self.assertTrue(_is_punctuation("""`"""  )  )
									self.assertTrue(_is_punctuation("""."""  )  )

									self.assertFalse(_is_punctuation("""A"""  )  )
									self.assertFalse(_is_punctuation(""" """  )  )

						@slow
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[int]:
									"""simple docstring"""




									a__       :						Optional[Any]							=  self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""  )

									a__       :						Dict							=  tokenizer.encode("""sequence builders""" ,       add_special_tokens=__lowercase  )
									a__       :						str							=  tokenizer.encode("""multi-sequence build""" ,       add_special_tokens=__lowercase  )

									a__       :						Optional[Any]							=  tokenizer.build_inputs_with_special_tokens(__lowercase  )
									a__       :						Optional[int]							=  tokenizer.build_inputs_with_special_tokens(__lowercase ,       __lowercase  )

									assert encoded_sentence == text + [1_0_2]
									assert encoded_pair == text + [1_0_2] + text_a + [1_0_2]




