
'''simple docstring'''



import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import PoolFormerImageProcessor




class   UpperCAmelCase_					(		unittest.TestCase			):






	'''simple docstring'''






	def __init__( self   ,       _lowercase   ,       _lowercase=7   ,       _lowercase=3   ,       _lowercase=30   ,       _lowercase=400   ,       _lowercase=True   ,       _lowercase=None   ,       _lowercase=0.9   ,       _lowercase=None   ,       _lowercase=True   ,       _lowercase=[0.5, 0.5, 0.5]   ,       _lowercase=[0.5, 0.5, 0.5]   ,       ):

							"""simple docstring"""



							_lowerCAmelCase  						=			size if size is not None else {"""shortest_edge""": 30}
							_lowerCAmelCase  						=			crop_size if crop_size is not None else {"""height""": 30, """width""": 30}
							_lowerCAmelCase  						=			parent
							_lowerCAmelCase  						=			batch_size
							_lowerCAmelCase  						=			num_channels
							_lowerCAmelCase  						=			min_resolution
							_lowerCAmelCase  						=			max_resolution
							_lowerCAmelCase  						=			do_resize_and_center_crop
							_lowerCAmelCase  						=			size
							_lowerCAmelCase  						=			crop_pct
							_lowerCAmelCase  						=			crop_size
							_lowerCAmelCase  						=			do_normalize
							_lowerCAmelCase  						=			image_mean
							_lowerCAmelCase  						=			image_std




	def  _lowercase     ( self				):

							"""simple docstring"""



							return {
							    "size": self.size,
							    "do_resize_and_center_crop": self.do_resize_and_center_crop,
							    "crop_pct": self.crop_pct,
							    "crop_size": self.crop_size,
							    "do_normalize": self.do_normalize,
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							}






@require_torch
@require_vision
class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE	,							unittest.TestCase			):






	'''simple docstring'''






	_lowercase		:				Union[str, Any]									=       PoolFormerImageProcessor if is_vision_available() else None




	def  _lowercase     ( self				):

							"""simple docstring"""



							_lowerCAmelCase  						=			PoolFormerImageProcessingTester(self				)




	@property
	def  _lowercase     ( self				):

							"""simple docstring"""



							return self.image_processor_tester.prepare_image_processor_dict()




	def  _lowercase     ( self				):

							"""simple docstring"""



							_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
							self.assertTrue(hasattr(_lowercase   ,       """do_resize_and_center_crop"""				)				)
							self.assertTrue(hasattr(_lowercase   ,       """size"""				)				)
							self.assertTrue(hasattr(_lowercase   ,       """crop_pct"""				)				)
							self.assertTrue(hasattr(_lowercase   ,       """do_normalize"""				)				)
							self.assertTrue(hasattr(_lowercase   ,       """image_mean"""				)				)
							self.assertTrue(hasattr(_lowercase   ,       """image_std"""				)				)




	def  _lowercase     ( self				):

							"""simple docstring"""



							_lowerCAmelCase  						=			self.image_processing_class.from_dict(self.image_processor_dict				)
							self.assertEqual(image_processor.size   ,       {"""shortest_edge""": 30}				)
							self.assertEqual(image_processor.crop_size   ,       {"""height""": 30, """width""": 30}				)

							_lowerCAmelCase  						=			self.image_processing_class.from_dict(self.image_processor_dict   ,       size=42   ,       crop_size=84				)
							self.assertEqual(image_processor.size   ,       {"""shortest_edge""": 42}				)
							self.assertEqual(image_processor.crop_size   ,       {"""height""": 84, """width""": 84}				)




	def  _lowercase     ( self				):

							"""simple docstring"""



							pass




	def  _lowercase     ( self				):

							"""simple docstring"""



							_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
							# create random PIL images
							_lowerCAmelCase  						=			prepare_image_inputs(self.image_processor_tester   ,       equal_resolution=_lowercase				)
							for image in image_inputs:
													self.assertIsInstance(_lowercase   ,       Image.Image				)

							# Test not batched input
							_lowerCAmelCase  						=			image_processing(image_inputs[0]   ,       return_tensors="""pt"""				).pixel_values

							self.assertEqual(
							    encoded_images.shape   ,       (
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )   ,       )

							# Test batched
							_lowerCAmelCase  						=			image_processing(_lowercase   ,       return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,       (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )   ,       )




	def  _lowercase     ( self				):

							"""simple docstring"""



							_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
							# create random numpy tensors
							_lowerCAmelCase  						=			prepare_image_inputs(self.image_processor_tester   ,       equal_resolution=_lowercase   ,       numpify=_lowercase				)
							for image in image_inputs:
													self.assertIsInstance(_lowercase   ,       np.ndarray				)

							# Test not batched input
							_lowerCAmelCase  						=			image_processing(image_inputs[0]   ,       return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,       (
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )   ,       )

							# Test batched
							_lowerCAmelCase  						=			image_processing(_lowercase   ,       return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,       (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )   ,       )




	def  _lowercase     ( self				):

							"""simple docstring"""



							_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
							# create random PyTorch tensors
							_lowerCAmelCase  						=			prepare_image_inputs(self.image_processor_tester   ,       equal_resolution=_lowercase   ,       torchify=_lowercase				)
							for image in image_inputs:
													self.assertIsInstance(_lowercase   ,       torch.Tensor				)

							# Test not batched input
							_lowerCAmelCase  						=			image_processing(image_inputs[0]   ,       return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,       (
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )   ,       )

							# Test batched
							_lowerCAmelCase  						=			image_processing(_lowercase   ,       return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_images.shape   ,       (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )   ,       )


'''simple docstring'''



from __future__ import annotations

import math


def A				(__lowerCamelCase				:list			,     __lowerCamelCase				:list		):
						if len(__lowerCamelCase		) != 2 or len(a[0]		) != 2 or len(__lowerCamelCase		) != 2 or len(b[0]		) != 2:
												raise Exception("""Matrices are not 2x2"""		)
						_lowerCAmelCase  						=			[
						    [a[0][0] * b[0][0] + a[0][1] * b[1][0], a[0][0] * b[0][1] + a[0][1] * b[1][1]],
						    [a[1][0] * b[0][0] + a[1][1] * b[1][0], a[1][0] * b[0][1] + a[1][1] * b[1][1]],
						]
						return new_matrix


def A				(__lowerCamelCase				:list			,     __lowerCamelCase				:list		):
						return [
						    [matrix_a[row][col] + matrix_b[row][col] for col in range(len(matrix_a[row]		)		)]
						    for row in range(len(__lowerCamelCase		)		)
						]


def A				(__lowerCamelCase				:list			,     __lowerCamelCase				:list		):
						return [
						    [matrix_a[row][col] - matrix_b[row][col] for col in range(len(matrix_a[row]		)		)]
						    for row in range(len(__lowerCamelCase		)		)
						]


def A				(__lowerCamelCase				:list		):
						if len(__lowerCamelCase		) % 2 != 0 or len(a[0]		) % 2 != 0:
												raise Exception("""Odd matrices are not supported!"""		)

						_lowerCAmelCase  						=			len(__lowerCamelCase		)
						_lowerCAmelCase  						=			matrix_length // 2

						_lowerCAmelCase  						=			[[a[i][j] for j in range(__lowerCamelCase			,     __lowerCamelCase		)] for i in range(__lowerCamelCase		)]
						_lowerCAmelCase  						=			[
						    [a[i][j] for j in range(__lowerCamelCase			,     __lowerCamelCase		)] for i in range(__lowerCamelCase			,     __lowerCamelCase		)
						]

						_lowerCAmelCase  						=			[[a[i][j] for j in range(__lowerCamelCase		)] for i in range(__lowerCamelCase		)]
						_lowerCAmelCase  						=			[[a[i][j] for j in range(__lowerCamelCase		)] for i in range(__lowerCamelCase			,     __lowerCamelCase		)]

						return top_left, top_right, bot_left, bot_right


def A				(__lowerCamelCase				:list		):
						return len(__lowerCamelCase		), len(matrix[0]		)


def A				(__lowerCamelCase				:list		):
						print("""\n""".join(str(__lowerCamelCase		) for line in matrix		)		)


def A				(__lowerCamelCase				:list			,     __lowerCamelCase				:list		):
						if matrix_dimensions(__lowerCamelCase		) == (2, 2):
												return default_matrix_multiplication(__lowerCamelCase			,     __lowerCamelCase		)

						_lowerCAmelCase						,   _lowerCAmelCase						,   _lowerCAmelCase						,   _lowerCAmelCase  						=			split_matrix(__lowerCamelCase		)
						_lowerCAmelCase						,   _lowerCAmelCase						,   _lowerCAmelCase						,   _lowerCAmelCase  						=			split_matrix(__lowerCamelCase		)

						_lowerCAmelCase  						=			actual_strassen(__lowerCamelCase			,     matrix_subtraction(__lowerCamelCase			,     __lowerCamelCase		)		)
						_lowerCAmelCase  						=			actual_strassen(matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)			,     __lowerCamelCase		)
						_lowerCAmelCase  						=			actual_strassen(matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)			,     __lowerCamelCase		)
						_lowerCAmelCase  						=			actual_strassen(__lowerCamelCase			,     matrix_subtraction(__lowerCamelCase			,     __lowerCamelCase		)		)
						_lowerCAmelCase  						=			actual_strassen(matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)			,     matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)		)
						_lowerCAmelCase  						=			actual_strassen(matrix_subtraction(__lowerCamelCase			,     __lowerCamelCase		)			,     matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)		)
						_lowerCAmelCase  						=			actual_strassen(matrix_subtraction(__lowerCamelCase			,     __lowerCamelCase		)			,     matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)		)

						_lowerCAmelCase  						=			matrix_addition(matrix_subtraction(matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)			,     __lowerCamelCase		)			,     __lowerCamelCase		)
						_lowerCAmelCase  						=			matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)
						_lowerCAmelCase  						=			matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)
						_lowerCAmelCase  						=			matrix_subtraction(matrix_subtraction(matrix_addition(__lowerCamelCase			,     __lowerCamelCase		)			,     __lowerCamelCase		)			,     __lowerCamelCase		)

						# construct the new matrix from our 4 quadrants
						_lowerCAmelCase  						=			[]
						for i in range(len(__lowerCamelCase		)		):
												new_matrix.append(top_left[i] + top_right[i]		)
						for i in range(len(__lowerCamelCase		)		):
												new_matrix.append(bot_left[i] + bot_right[i]		)
						return new_matrix


def A				(__lowerCamelCase				:list			,     __lowerCamelCase				:list		):
						if matrix_dimensions(__lowerCamelCase		)[1] != matrix_dimensions(__lowerCamelCase		)[0]:
												_lowerCAmelCase  						=			(
												    """Unable to multiply these matrices, please check the dimensions.\n"""
												    f'Matrix A: {matrixa}\n'
												    f'Matrix B: {matrixa}'
												)
												raise Exception(__lowerCamelCase		)
						_lowerCAmelCase  						=			matrix_dimensions(__lowerCamelCase		)
						_lowerCAmelCase  						=			matrix_dimensions(__lowerCamelCase		)

						if dimensiona[0] == dimensiona[1] and dimensiona[0] == dimensiona[1]:
												return [matrixa, matrixa]

						_lowerCAmelCase  						=			max(*__lowerCamelCase			,     *__lowerCamelCase		)
						_lowerCAmelCase  						=			int(math.pow(2			,     math.ceil(math.loga(__lowerCamelCase		)		)		)		)
						_lowerCAmelCase  						=			matrixa
						_lowerCAmelCase  						=			matrixa

						# Adding zeros to the matrices so that the arrays dimensions are the same and also
						# power of 2
						for i in range(0			,     __lowerCamelCase		):
												if i < dimensiona[0]:
																		for _ in range(dimensiona[1]			,     __lowerCamelCase		):
																								new_matrixa[i].append(0		)
												else:
																		new_matrixa.append([0] * maxim		)
												if i < dimensiona[0]:
																		for _ in range(dimensiona[1]			,     __lowerCamelCase		):
																								new_matrixa[i].append(0		)
												else:
																		new_matrixa.append([0] * maxim		)

						_lowerCAmelCase  						=			actual_strassen(__lowerCamelCase			,     __lowerCamelCase		)

						# Removing the additional zeros
						for i in range(0			,     __lowerCamelCase		):
												if i < dimensiona[0]:
																		for _ in range(dimensiona[1]			,     __lowerCamelCase		):
																								final_matrix[i].pop()
												else:
																		final_matrix.pop()
						return final_matrix


if __name__ == "__main__":
						_lowercase    =		[
						    [2, 3, 4, 5],
						    [6, 4, 3, 1],
						    [2, 3, 6, 7],
						    [3, 1, 2, 4],
						    [2, 3, 4, 5],
						    [6, 4, 3, 1],
						    [2, 3, 6, 7],
						    [3, 1, 2, 4],
						    [2, 3, 4, 5],
						    [6, 2, 3, 1],
						]
						_lowercase    =		[[0, 2, 1, 1], [16, 2, 3, 3], [2, 2, 7, 7], [13, 11, 22, 4]]
						print(strassen(matrixa, matrixa))
