


from __future__ import annotations

import math





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	list:


						'''simple docstring'''






						if len(_lowerCAmelCase ) != 2 or len(a[0] ) != 2 or len(_lowerCAmelCase ) != 2 or len(b[0] ) != 2:
												raise Exception("Matrices are not 2x2" )
						__snake_case				=		[
						    [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       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	Optional[int]:


						'''simple docstring'''






						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       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	Union[str, Any]:


						'''simple docstring'''






						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       (    _lowerCAmelCase )						->	tuple[list, list, list, list]:


						'''simple docstring'''






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

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

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

						__snake_case				=		[[a[i][j] for j in range(_lowerCAmelCase )] for i in range(_lowerCAmelCase )]
						__snake_case				=		[[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       (    _lowerCAmelCase )						->	tuple[int, int]:


						'''simple docstring'''






						return len(_lowerCAmelCase ), len(matrix[0] )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	None:


						'''simple docstring'''






						print("\n".join(str(_lowerCAmelCase ) for line in matrix ) )





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	list:


						'''simple docstring'''






						if matrix_dimensions(_lowerCAmelCase ) == (2, 2):
												return default_matrix_multiplication(_lowerCAmelCase      ,	_lowerCAmelCase )

						__snake_case		,					__snake_case		,					__snake_case		,					__snake_case				=		split_matrix(_lowerCAmelCase )
						__snake_case		,					__snake_case		,					__snake_case		,					__snake_case				=		split_matrix(_lowerCAmelCase )

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

						__snake_case				=		matrix_addition(matrix_subtraction(matrix_addition(_lowerCAmelCase      ,	_lowerCAmelCase )      ,	_lowerCAmelCase )      ,	_lowerCAmelCase )
						__snake_case				=		matrix_addition(_lowerCAmelCase      ,	_lowerCAmelCase )
						__snake_case				=		matrix_addition(_lowerCAmelCase      ,	_lowerCAmelCase )
						__snake_case				=		matrix_subtraction(matrix_subtraction(matrix_addition(_lowerCAmelCase      ,	_lowerCAmelCase )      ,	_lowerCAmelCase )      ,	_lowerCAmelCase )

						# construct the new matrix from our 4 quadrants
						__snake_case				=		[]
						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       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	list:


						'''simple docstring'''






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

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

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

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









from sklearn.metrics import mean_squared_error

import datasets


A							:					List[Any]     						=     '\\n@article{scikit-learn,\n title={Scikit-learn: Machine Learning in {P}ython},\n author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.\n         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.\n         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and\n         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},\n journal={Journal of Machine Learning Research},\n volume={12},\n pages={2825--2830},\n year={2011}\n}\n'

A							:					Optional[int]     						=     '\\nMean Squared Error(MSE) is the average of the square of difference between the predicted\nand actual values.\n'


A							:					str     						=     '\nArgs:\n    predictions: array-like of shape (n_samples,) or (n_samples, n_outputs)\n        Estimated target values.\n    references: array-like of shape (n_samples,) or (n_samples, n_outputs)\n        Ground truth (correct) target values.\n    sample_weight: array-like of shape (n_samples,), default=None\n        Sample weights.\n    multioutput: {"raw_values", "uniform_average"} or array-like of shape (n_outputs,), default="uniform_average"\n        Defines aggregating of multiple output values. Array-like value defines weights used to average errors.\n\n        "raw_values" : Returns a full set of errors in case of multioutput input.\n\n        "uniform_average" : Errors of all outputs are averaged with uniform weight.\n\n    squared : bool, default=True\n        If True returns MSE value, if False returns RMSE (Root Mean Squared Error) value.\n\nReturns:\n    mse : mean squared error.\nExamples:\n\n    >>> mse_metric = datasets.load_metric("mse")\n    >>> predictions = [2.5, 0.0, 2, 8]\n    >>> references = [3, -0.5, 2, 7]\n    >>> results = mse_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'mse\': 0.375}\n    >>> rmse_result = mse_metric.compute(predictions=predictions, references=references, squared=False)\n    >>> print(rmse_result)\n    {\'mse\': 0.6123724356957945}\n\n    If you\'re using multi-dimensional lists, then set the config as follows :\n\n    >>> mse_metric = datasets.load_metric("mse", "multilist")\n    >>> predictions = [[0.5, 1], [-1, 1], [7, -6]]\n    >>> references = [[0, 2], [-1, 2], [8, -5]]\n    >>> results = mse_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'mse\': 0.7083333333333334}\n    >>> results = mse_metric.compute(predictions=predictions, references=references, multioutput=\'raw_values\')\n    >>> print(results) # doctest: +NORMALIZE_WHITESPACE\n    {\'mse\': array([0.41666667, 1. ])}\n'






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION     ,							_KWARGS_DESCRIPTION   )
class     UpperCamelCase(  datasets.Metric   ):


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Union[str, Any]:




											'''simple docstring'''

											return datasets.MetricInfo(
											    description=_DESCRIPTION     ,    citation=_CITATION     ,    inputs_description=_KWARGS_DESCRIPTION     ,    features=datasets.Features(self._get_feature_types()						)     ,    reference_urls=[
											        "https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html"
											    ]     ,    )


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	Dict:




											'''simple docstring'''

											if self.config_name == "multilist":
																	return {
																	    "predictions": datasets.Sequence(datasets.Value("float"						)						),
																	    "references": datasets.Sequence(datasets.Value("float"						)						),
																	}
											else:
																	return {
																	    "predictions": datasets.Value("float"						),
																	    "references": datasets.Value("float"						),
																	}






					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		List[Any]     ,    SCREAMING_SNAKE_CASE	:		str=None     ,    SCREAMING_SNAKE_CASE	:		int="uniform_average"     ,    SCREAMING_SNAKE_CASE	:		Optional[int]=True						)			->	Tuple:




											'''simple docstring'''

											__snake_case				=		mean_squared_error(
											    SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE     ,    sample_weight=SCREAMING_SNAKE_CASE     ,    multioutput=SCREAMING_SNAKE_CASE     ,    squared=SCREAMING_SNAKE_CASE						)

											return {"mse": mse}





