
"""simple docstring"""







from __future__ import annotations

import math
def    __lowerCAmelCase    (_UpperCamelCase	,  _UpperCamelCase		):
	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      :						Tuple						      =				[
	    [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    __lowerCAmelCase    (_UpperCamelCase	,  _UpperCamelCase		):
	return [
	    [matrix_a[row][col] + matrix_b[row][col] for col in range(len(matrix_a[row]		)		)]
	    for row in range(len(__lowerCamelCase		)		)
	]
def    __lowerCAmelCase    (_UpperCamelCase	,  _UpperCamelCase		):
	return [
	    [matrix_a[row][col] - matrix_b[row][col] for col in range(len(matrix_a[row]		)		)]
	    for row in range(len(__lowerCamelCase		)		)
	]
def    __lowerCAmelCase    (_UpperCamelCase		):
	if len(__lowerCamelCase		) % 2 != 0 or len(a[0]		) % 2 != 0:
		raise Exception('Odd matrices are not supported!'		)

	__lowerCAmelCase      :						Optional[int]						      =				len(__lowerCamelCase		)
	__lowerCAmelCase      :						int						      =				matrix_length // 2

	__lowerCAmelCase      :						Any						      =				[[a[i][j] for j in range(__lowerCamelCase	,  __lowerCamelCase		)] for i in range(__lowerCamelCase		)]
	__lowerCAmelCase      :						str						      =				[
	    [a[i][j] for j in range(__lowerCamelCase	,  __lowerCamelCase		)] for i in range(__lowerCamelCase	,  __lowerCamelCase		)
	]

	__lowerCAmelCase      :						List[str]						      =				[[a[i][j] for j in range(__lowerCamelCase		)] for i in range(__lowerCamelCase		)]
	__lowerCAmelCase      :						List[Any]						      =				[[a[i][j] for j in range(__lowerCamelCase		)] for i in range(__lowerCamelCase	,  __lowerCamelCase		)]

	return top_left, top_right, bot_left, bot_right
def    __lowerCAmelCase    (_UpperCamelCase		):
	return len(__lowerCamelCase		), len(matrix[0]		)
def    __lowerCAmelCase    (_UpperCamelCase		):
	print('\n'.join(str(__lowerCamelCase		) for line in matrix		)		)
def    __lowerCAmelCase    (_UpperCamelCase	,  _UpperCamelCase		):
	if matrix_dimensions(__lowerCamelCase		) == (2, 2):
		return default_matrix_multiplication(__lowerCamelCase	,  __lowerCamelCase		)

	__lowerCAmelCase      ,       __lowerCAmelCase      ,       __lowerCAmelCase      ,       __lowerCAmelCase      :						Dict						      =				split_matrix(__lowerCamelCase		)
	__lowerCAmelCase      ,       __lowerCAmelCase      ,       __lowerCAmelCase      ,       __lowerCAmelCase      :						List[Any]						      =				split_matrix(__lowerCamelCase		)

	__lowerCAmelCase      :						List[str]						      =				actual_strassen(__lowerCamelCase	,  matrix_subtraction(__lowerCamelCase	,  __lowerCamelCase		)		)
	__lowerCAmelCase      :						str						      =				actual_strassen(matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)	,  __lowerCamelCase		)
	__lowerCAmelCase      :						int						      =				actual_strassen(matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)	,  __lowerCamelCase		)
	__lowerCAmelCase      :						Dict						      =				actual_strassen(__lowerCamelCase	,  matrix_subtraction(__lowerCamelCase	,  __lowerCamelCase		)		)
	__lowerCAmelCase      :						Optional[int]						      =				actual_strassen(matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)	,  matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)		)
	__lowerCAmelCase      :						List[Any]						      =				actual_strassen(matrix_subtraction(__lowerCamelCase	,  __lowerCamelCase		)	,  matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)		)
	__lowerCAmelCase      :						List[str]						      =				actual_strassen(matrix_subtraction(__lowerCamelCase	,  __lowerCamelCase		)	,  matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)		)

	__lowerCAmelCase      :						Dict						      =				matrix_addition(matrix_subtraction(matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)	,  __lowerCamelCase		)	,  __lowerCamelCase		)
	__lowerCAmelCase      :						List[str]						      =				matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)
	__lowerCAmelCase      :						str						      =				matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)
	__lowerCAmelCase      :						Tuple						      =				matrix_subtraction(matrix_subtraction(matrix_addition(__lowerCamelCase	,  __lowerCamelCase		)	,  __lowerCamelCase		)	,  __lowerCamelCase		)

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

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

	__lowerCAmelCase      :						Union[str, Any]						      =				max(*__lowerCamelCase	,  *__lowerCamelCase		)
	__lowerCAmelCase      :						Union[str, Any]						      =				int(math.pow(2	,  math.ceil(math.loga(__lowerCamelCase		)		)		)		)
	__lowerCAmelCase      :						int						      =				matrixa
	__lowerCAmelCase      :						int						      =				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      :						List[Any]						      =				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__        =		[
				    [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__        =		[[0, 2, 1, 1], [16, 2, 3, 3], [2, 2, 7, 7], [13, 11, 22, 4]]
				print(strassen(matrixa, matrixa))

"""simple docstring"""







import pytest

import datasets.config
from datasets.utils.info_utils import is_small_dataset
@pytest.mark.parametrize('dataset_size'	,  [None, 400 * 2**20, 600 * 2**20]		)
@pytest.mark.parametrize('input_in_memory_max_size'	,  ['default', 0, 100 * 2**20, 900 * 2**20]		)
def    __lowerCAmelCase    (_UpperCamelCase	,  _UpperCamelCase	,  _UpperCamelCase		):
	if input_in_memory_max_size != "default":
		monkeypatch.setattr(datasets.config	,  'IN_MEMORY_MAX_SIZE'	,  _UpperCamelCase		)
	__lowerCAmelCase      :						Union[str, Any]						      =				datasets.config.IN_MEMORY_MAX_SIZE
	if input_in_memory_max_size == "default":
		assert in_memory_max_size == 0
	else:
		assert in_memory_max_size == input_in_memory_max_size
	if dataset_size and in_memory_max_size:
		__lowerCAmelCase      :						Tuple						      =				dataset_size < in_memory_max_size
	else:
		__lowerCAmelCase      :						str						      =				False
	__lowerCAmelCase      :						Optional[int]						      =				is_small_dataset(_UpperCamelCase		)
	assert result == expected