
'''simple docstring'''

import numpy as np
from PIL import Image


def 		_UpperCAmelCase (     _lowerCamelCase  :				np.ndarray     ,					_lowerCamelCase  :				int     ,					_lowerCamelCase  :				int						)			->  Optional[int]:
  _lowerCAmelCase				:     str       =    np.array(_snake_case						)
  if arr.shape[0] != arr.shape[1]:
    raise ValueError("""The input array is not a square matrix"""						)
  _lowerCAmelCase				:     str       =    0
  _lowerCAmelCase				:     List[str]       =    0
  _lowerCAmelCase				:     Optional[int]       =    0
  _lowerCAmelCase				:     Dict       =    0

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

  return updated_arr


def 		_UpperCAmelCase (     _lowerCamelCase  :				np.ndarray     ,					_lowerCamelCase  :				int     ,					_lowerCamelCase  :				int						)			->  str:
  _lowerCAmelCase				:     Dict       =    np.array(_snake_case						)
  if arr.shape[0] != arr.shape[1]:
    raise ValueError("""The input array is not a square matrix"""						)
  _lowerCAmelCase				:     Optional[Any]       =    0
  _lowerCAmelCase				:     Optional[int]       =    0
  _lowerCAmelCase				:     str       =    0
  _lowerCAmelCase				:     Any       =    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 avgpool_shape
  _lowerCAmelCase				:     Optional[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
      _lowerCAmelCase				:     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
    _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
     UpperCamelCase_   	=				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 argparse

import torch

from transformers import OpenAIGPTConfig, OpenAIGPTModel, load_tf_weights_in_openai_gpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()






def        UpperCamelCase_(							_snake_case   :  Dict       ,     _snake_case   :  Optional[int]       ,     _snake_case   :  str	):




			"""simple docstring"""






			if openai_config_file == "":
						__a        =OpenAIGPTConfig()
			else:
						__a        =OpenAIGPTConfig.from_json_file(_snake_case	)
			__a        =OpenAIGPTModel(_snake_case	)

			# Load weights from numpy
			load_tf_weights_in_openai_gpt(_snake_case       ,     _snake_case       ,     _snake_case	)

			# Save pytorch-model
			__a        =pytorch_dump_folder_path + '/' + WEIGHTS_NAME
			__a        =pytorch_dump_folder_path + '/' + CONFIG_NAME
			print(F'Save PyTorch model to {pytorch_weights_dump_path}'	)
			torch.save(model.state_dict()       ,     _snake_case	)
			print(F'Save configuration file to {pytorch_config_dump_path}'	)
			with open(_snake_case       ,     'w'       ,     encoding='utf-8'	) as f:
						f.write(config.to_json_string()	)


if __name__ == "__main__":
						_lowerCAmelCase					:			Tuple  				=			argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    "--openai_checkpoint_folder_path",
						    default=None,
						    type=str,
						    required=True,
						    help="Path to the TensorFlow checkpoint path.",
						)
						parser.add_argument(
						    "--pytorch_dump_folder_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
						)
						parser.add_argument(
						    "--openai_config_file",
						    default="",
						    type=str,
						    help=(
						        "An optional config json file corresponding to the pre-trained OpenAI model. \n"
						        "This specifies the model architecture."
						    ),
						)
						_lowerCAmelCase					:			int  				=			parser.parse_args()
						convert_openai_checkpoint_to_pytorch(
						    args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
						)






