






'''simple docstring'''




import os

import pytest

from datasets import (
    get_dataset_config_info,
    get_dataset_config_names,
    get_dataset_infos,
    get_dataset_split_names,
    inspect_dataset,
    inspect_metric,
)


lowerCAmelCase__          =						pytest.mark.integration







@pytest.mark.parametrize('path'     ,      ['paws', 'csv'])
def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_)							->     List[str]:
		inspect_dataset(lowerCamelCase_     ,      lowerCamelCase_)
		UpperCamelCase__				:					str					=					path + '.py'
		assert script_name in os.listdir(lowerCamelCase_)
		assert "__pycache__" not in os.listdir(lowerCamelCase_)







@pytest.mark.filterwarnings('ignore:inspect_metric is deprecated:FutureWarning')
@pytest.mark.filterwarnings('ignore:metric_module_factory is deprecated:FutureWarning')
@pytest.mark.parametrize('path'     ,      ['accuracy'])
def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_)							->     Optional[Any]:
		inspect_metric(lowerCamelCase_     ,      lowerCamelCase_)
		UpperCamelCase__				:					int					=					path + '.py'
		assert script_name in os.listdir(lowerCamelCase_)
		assert "__pycache__" not in os.listdir(lowerCamelCase_)







@pytest.mark.parametrize(
    'path, config_name, expected_splits'     ,      [
        ('squad', 'plain_text', ['train', 'validation']),
        ('dalle-mini/wit', 'dalle-mini--wit', ['train']),
        ('paws', 'labeled_final', ['train', 'test', 'validation']),
    ]     ,      )
def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_     ,      lowerCamelCase_)							->     Union[str, Any]:
		UpperCamelCase__				:					Optional[Any]					=					get_dataset_config_info(lowerCamelCase_     ,      config_name=lowerCamelCase_)
		assert info.config_name == config_name
		assert list(info.splits.keys()) == expected_splits







@pytest.mark.parametrize(
    'path, config_name, expected_exception'     ,      [
        ('paws', None, ValueError),
    ]     ,      )
def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_     ,      lowerCamelCase_)							->     Optional[int]:
		with pytest.raises(lowerCamelCase_):
				get_dataset_config_info(lowerCamelCase_     ,      config_name=lowerCamelCase_)







@pytest.mark.parametrize(
    'path, expected'     ,      [
        ('squad', 'plain_text'),
        ('acronym_identification', 'default'),
        ('lhoestq/squad', 'plain_text'),
        ('lhoestq/test', 'default'),
        ('lhoestq/demo1', 'lhoestq--demo1'),
        ('dalle-mini/wit', 'dalle-mini--wit'),
    ]     ,      )
def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_)							->     Tuple:
		UpperCamelCase__				:					Any					=					get_dataset_config_names(lowerCamelCase_)
		assert expected in config_names







@pytest.mark.parametrize(
    'path, expected_configs, expected_splits_in_first_config'     ,      [
        ('squad', ['plain_text'], ['train', 'validation']),
        ('dalle-mini/wit', ['dalle-mini--wit'], ['train']),
        ('paws', ['labeled_final', 'labeled_swap', 'unlabeled_final'], ['train', 'test', 'validation']),
    ]     ,      )
def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_     ,      lowerCamelCase_)							->     Optional[Any]:
		UpperCamelCase__				:					Union[str, Any]					=					get_dataset_infos(lowerCamelCase_)
		assert list(infos.keys()) == expected_configs
		UpperCamelCase__				:					Tuple					=					expected_configs[0]
		assert expected_config in infos
		UpperCamelCase__				:					List[Any]					=					infos[expected_config]
		assert info.config_name == expected_config
		assert list(info.splits.keys()) == expected_splits_in_first_config







@pytest.mark.parametrize(
    'path, expected_config, expected_splits'     ,      [
        ('squad', 'plain_text', ['train', 'validation']),
        ('dalle-mini/wit', 'dalle-mini--wit', ['train']),
        ('paws', 'labeled_final', ['train', 'test', 'validation']),
    ]     ,      )
def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_     ,      lowerCamelCase_)							->     Optional[Any]:
		UpperCamelCase__				:					str					=					get_dataset_infos(lowerCamelCase_)
		assert expected_config in infos
		UpperCamelCase__				:					Union[str, Any]					=					infos[expected_config]
		assert info.config_name == expected_config
		assert list(info.splits.keys()) == expected_splits







@pytest.mark.parametrize(
    'path, config_name, expected_exception'     ,      [
        ('paws', None, ValueError),
    ]     ,      )
def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_     ,      lowerCamelCase_)							->     Tuple:
		with pytest.raises(lowerCamelCase_):
				get_dataset_split_names(lowerCamelCase_     ,      config_name=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()




