"""simple docstring"""






from __future__ import annotations

import math



def   a_						(					lowerCamelCase					,			lowerCamelCase       ):
				if len(lowerCamelCase       ) != 2 or len(a[0]       ) != 2 or len(lowerCamelCase       ) != 2 or len(b[0]       ) != 2:
								raise Exception('Matrices are not 2x2'       )
				UpperCAmelCase__             =							[
				    [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					,			lowerCamelCase       ):
				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					,			lowerCamelCase       ):
				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       ):
				if len(lowerCamelCase       ) % 2 != 0 or len(a[0]       ) % 2 != 0:
								raise Exception('Odd matrices are not supported!'       )

				UpperCAmelCase__             =							len(lowerCamelCase       )
				UpperCAmelCase__             =							matrix_length // 2

				UpperCAmelCase__             =							[[a[i][j] for j in range(lowerCamelCase					,			lowerCamelCase       )] for i in range(lowerCamelCase       )]
				UpperCAmelCase__             =							[
				    [a[i][j] for j in range(lowerCamelCase					,			lowerCamelCase       )] for i in range(lowerCamelCase					,			lowerCamelCase       )
				]

				UpperCAmelCase__             =							[[a[i][j] for j in range(lowerCamelCase       )] for i in range(lowerCamelCase       )]
				UpperCAmelCase__             =							[[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       ):
				return len(lowerCamelCase       ), len(matrix[0]       )



def   a_						(					lowerCamelCase       ):
				print('\n'.join(str(lowerCamelCase       ) for line in matrix       )       )



def   a_						(					lowerCamelCase					,			lowerCamelCase       ):
				if matrix_dimensions(lowerCamelCase       ) == (2, 2):
								return default_matrix_multiplication(lowerCamelCase					,			lowerCamelCase       )

				UpperCAmelCase__      ,	UpperCAmelCase__      ,	UpperCAmelCase__      ,	UpperCAmelCase__             =							split_matrix(lowerCamelCase       )
				UpperCAmelCase__      ,	UpperCAmelCase__      ,	UpperCAmelCase__      ,	UpperCAmelCase__             =							split_matrix(lowerCamelCase       )

				UpperCAmelCase__             =							actual_strassen(lowerCamelCase					,			matrix_subtraction(lowerCamelCase					,			lowerCamelCase       )       )
				UpperCAmelCase__             =							actual_strassen(matrix_addition(lowerCamelCase					,			lowerCamelCase       )					,			lowerCamelCase       )
				UpperCAmelCase__             =							actual_strassen(matrix_addition(lowerCamelCase					,			lowerCamelCase       )					,			lowerCamelCase       )
				UpperCAmelCase__             =							actual_strassen(lowerCamelCase					,			matrix_subtraction(lowerCamelCase					,			lowerCamelCase       )       )
				UpperCAmelCase__             =							actual_strassen(matrix_addition(lowerCamelCase					,			lowerCamelCase       )					,			matrix_addition(lowerCamelCase					,			lowerCamelCase       )       )
				UpperCAmelCase__             =							actual_strassen(matrix_subtraction(lowerCamelCase					,			lowerCamelCase       )					,			matrix_addition(lowerCamelCase					,			lowerCamelCase       )       )
				UpperCAmelCase__             =							actual_strassen(matrix_subtraction(lowerCamelCase					,			lowerCamelCase       )					,			matrix_addition(lowerCamelCase					,			lowerCamelCase       )       )

				UpperCAmelCase__             =							matrix_addition(matrix_subtraction(matrix_addition(lowerCamelCase					,			lowerCamelCase       )					,			lowerCamelCase       )					,			lowerCamelCase       )
				UpperCAmelCase__             =							matrix_addition(lowerCamelCase					,			lowerCamelCase       )
				UpperCAmelCase__             =							matrix_addition(lowerCamelCase					,			lowerCamelCase       )
				UpperCAmelCase__             =							matrix_subtraction(matrix_subtraction(matrix_addition(lowerCamelCase					,			lowerCamelCase       )					,			lowerCamelCase       )					,			lowerCamelCase       )

				# construct the new matrix from our 4 quadrants
				UpperCAmelCase__             =							[]
				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					,			lowerCamelCase       ):
				if matrix_dimensions(lowerCamelCase       )[1] != matrix_dimensions(lowerCamelCase       )[0]:
								UpperCAmelCase__             =							(
								    'Unable to multiply these matrices, please check the dimensions.\n'
								    f'''Matrix A: {matrixa}\n'''
								    f'''Matrix B: {matrixa}'''
								)
								raise Exception(lowerCamelCase       )
				UpperCAmelCase__             =							matrix_dimensions(lowerCamelCase       )
				UpperCAmelCase__             =							matrix_dimensions(lowerCamelCase       )

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

				UpperCAmelCase__             =							max(*lowerCamelCase					,			*lowerCamelCase       )
				UpperCAmelCase__             =							int(math.pow(2					,			math.ceil(math.loga(lowerCamelCase       )       )       )       )
				UpperCAmelCase__             =							matrixa
				UpperCAmelCase__             =							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       )

				UpperCAmelCase__             =							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__":
						lowerCAmelCase__  :  List[Any]						     =	[
						    [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],
						]
						lowerCAmelCase__  :  List[str]						     =	[[0, 2, 1, 1], [16, 2, 3, 3], [2, 2, 7, 7], [13, 11, 22, 4]]
						print(strassen(matrixa, matrixa))










from diffusers.utils.testing_utils import require_onnxruntime







@require_onnxruntime
class 				__lowerCAmelCase       :
      pass






