






'''simple docstring'''
import numpy as np
from PIL import Image





def  _a(  UpperCamelCase__				:						str,	UpperCamelCase__				:						Optional[int],	UpperCamelCase__				:						int							):




      '''simple docstring'''






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

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

      return updated_arr





def  _a(  UpperCamelCase__				:						Dict,	UpperCamelCase__				:						List[str],	UpperCamelCase__				:						Dict							):




      '''simple docstring'''






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

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







'''simple docstring'''
from __future__ import annotations

import sys
from collections import deque
from typing import Generic, TypeVar

a_					= TypeVar('T')






class      __SCREAMING_SNAKE_CASE      (			Generic[T]				):
 snake_case_  							=							42  # Cache store of keys
 snake_case_  							=							42  # References of the keys in cache
 snake_case_  							=							10  # Maximum capacity of cache




 def __init__(      self	:							Dict					,      __lowercase	:							int      )	->						None:
       SCREAMING_SNAKE_CASE__     :				Any									=deque()
       SCREAMING_SNAKE_CASE__     :				str									=set()
       if not n:
             SCREAMING_SNAKE_CASE__     :				Optional[Any]									=sys.maxsize
       elif n < 0:
             raise ValueError('''n should be an integer greater than 0.'''      )
       else:
             SCREAMING_SNAKE_CASE__     :				Optional[Any]									=n




 def      __magic_name__	(      self	:							List[str]					,      __lowercase	:							T      )	->						None:
       if x not in self.key_reference:
             if len(self.dq_store      ) == LRUCache._MAX_CAPACITY:
                   SCREAMING_SNAKE_CASE__     :				int									=self.dq_store.pop()
                   self.key_reference.remove(__lowercase      )
       else:
             self.dq_store.remove(__lowercase      )

       self.dq_store.appendleft(__lowercase      )
       self.key_reference.add(__lowercase      )




 def      __magic_name__	(      self	:							Union[str, Any]      )	->						None:
       for k in self.dq_store:
             print(__lowercase      )




 def __repr__(      self	:							List[Any]      )	->						str:
       return F"LRUCache({self._MAX_CAPACITY}) => {list(self.dq_store      )}"


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  a_					= LRUCache(4)
  lru_cache.refer('A')
  lru_cache.refer(2)
  lru_cache.refer(3)
  lru_cache.refer('A')
  lru_cache.refer(4)
  lru_cache.refer(5)
  lru_cache.display()

  print(lru_cache)
  assert str(lru_cache) == "LRUCache(4) => [5, 4, 'A', 3]"