





import numpy as np
from PIL import Image





def 					lowerCAmelCase_			(	__a     ,   __a     ,   __a		)					->		np.ndarray:







  """simple docstring"""





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

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

  return updated_arr





def 					lowerCAmelCase_			(	__a     ,   __a     ,   __a		)					->		np.ndarray:







  """simple docstring"""





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

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








import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ,							unittest.TestCase   ):







 '''simple docstring'''
 lowercase_		=      CTRLTokenizer
 lowercase_		=      False
 lowercase_		=      False

 def 							SCREAMING_SNAKE_CASE_ (self    :       str)	->Union[str, Any]:



   '''simple docstring'''



   super().setUp()

   # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
   lowerCamelCase__:				Optional[Any]        =["adapt", "re@@", "a@@", "apt", "c@@", "t", "<unk>"]
   lowerCamelCase__:				Optional[Any]        =dict(zip(UpperCAmelCase_	,			range(len(UpperCAmelCase_))))
   lowerCamelCase__:				Union[str, Any]        =["#version: 0.2", "a p", "ap t</w>", "r e", "a d", "ad apt</w>", ""]
   lowerCamelCase__:				Union[str, Any]        ={"unk_token": "<unk>"}

   lowerCamelCase__:				Union[str, Any]        =os.path.join(self.tmpdirname	,			VOCAB_FILES_NAMES["vocab_file"])
   lowerCamelCase__:				Optional[Any]        =os.path.join(self.tmpdirname	,			VOCAB_FILES_NAMES["merges_file"])
   with open(self.vocab_file	,			"w"	,			encoding="utf-8") as fp:
     fp.write(json.dumps(UpperCAmelCase_) + "\n")
   with open(self.merges_file	,			"w"	,			encoding="utf-8") as fp:
     fp.write("\n".join(UpperCAmelCase_))

 def 							SCREAMING_SNAKE_CASE_ (self    :       List[str]	,			**UpperCAmelCase_    :       str)	->List[Any]:



   '''simple docstring'''



   kwargs.update(self.special_tokens_map)
   return CTRLTokenizer.from_pretrained(self.tmpdirname	,			**UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_ (self    :       List[Any]	,			UpperCAmelCase_    :       Optional[int])	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				int        ="adapt react readapt apt"
   lowerCamelCase__:				int        ="adapt react readapt apt"
   return input_text, output_text







 def 							SCREAMING_SNAKE_CASE_ (self    :       str)	->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:				List[str]        =CTRLTokenizer(self.vocab_file	,			self.merges_file	,			**self.special_tokens_map)
   lowerCamelCase__:				Union[str, Any]        ="adapt react readapt apt"
   lowerCamelCase__:				Tuple        ="adapt re@@ a@@ c@@ t re@@ adapt apt".split()
   lowerCamelCase__:				Dict        =tokenizer.tokenize(UpperCAmelCase_)
   self.assertListEqual(UpperCAmelCase_	,			UpperCAmelCase_)

   lowerCamelCase__:				Optional[int]        =tokens + [tokenizer.unk_token]

   lowerCamelCase__:				List[str]        =[0, 1, 2, 4, 5, 1, 0, 3, 6]
   self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCAmelCase_)	,			UpperCAmelCase_)

