


'''simple docstring'''






import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A	:	Dict     =     logging.get_logger(__name__)

__A	:	int     =     {
    'asapp/sew-tiny-100k': 'https://huggingface.co/asapp/sew-tiny-100k/resolve/main/config.json',
    # See all SEW models at https://huggingface.co/models?filter=sew
}
class 						__UpperCamelCase	(						lowercase__							):
							lowercase			:		Tuple   		=  'sew'





							def __init__(  self		:Optional[Any]  ,_UpperCamelCase		:int=3_2  ,_UpperCamelCase		:Tuple=7_6_8  ,_UpperCamelCase		:Any=1_2  ,_UpperCamelCase		:Union[str, Any]=1_2  ,_UpperCamelCase		:Union[str, Any]=3_0_7_2  ,_UpperCamelCase		:Optional[Any]=2  ,_UpperCamelCase		:List[str]="gelu"  ,_UpperCamelCase		:Tuple=0.1  ,_UpperCamelCase		:List[Any]=0.1  ,_UpperCamelCase		:Union[str, Any]=0.1  ,_UpperCamelCase		:List[Any]=0.0  ,_UpperCamelCase		:Optional[int]=0.1  ,_UpperCamelCase		:Union[str, Any]=0.1  ,_UpperCamelCase		:Any=0.02  ,_UpperCamelCase		:str=1E-5  ,_UpperCamelCase		:Optional[int]="group"  ,_UpperCamelCase		:List[str]="gelu"  ,_UpperCamelCase		:List[str]=(6_4, 1_2_8, 1_2_8, 1_2_8, 1_2_8, 2_5_6, 2_5_6, 2_5_6, 2_5_6, 5_1_2, 5_1_2, 5_1_2, 5_1_2)  ,_UpperCamelCase		:Optional[int]=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)  ,_UpperCamelCase		:Optional[int]=(1_0, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)  ,_UpperCamelCase		:List[str]=False  ,_UpperCamelCase		:Dict=1_2_8  ,_UpperCamelCase		:Optional[int]=1_6  ,_UpperCamelCase		:Union[str, Any]=True  ,_UpperCamelCase		:int=0.05  ,_UpperCamelCase		:str=1_0  ,_UpperCamelCase		:Optional[int]=2  ,_UpperCamelCase		:Any=0.0  ,_UpperCamelCase		:Union[str, Any]=1_0  ,_UpperCamelCase		:Dict=0  ,_UpperCamelCase		:Optional[int]="mean"  ,_UpperCamelCase		:Any=False  ,_UpperCamelCase		:Optional[int]=False  ,_UpperCamelCase		:Union[str, Any]=2_5_6  ,_UpperCamelCase		:Dict=0  ,_UpperCamelCase		:Optional[Any]=1  ,_UpperCamelCase		:int=2  ,**_UpperCamelCase		:Dict  ,):
									super().__init__(**_UpperCamelCase  ,pad_token_id=_UpperCamelCase  ,bos_token_id=_UpperCamelCase  ,eos_token_id=_UpperCamelCase			)
									snake_case_		:							Optional[int]			       =						hidden_size
									snake_case_		:							Any			       =						feat_extract_norm
									snake_case_		:							Any			       =						feat_extract_activation
									snake_case_		:							Dict			       =						list(_UpperCamelCase			)
									snake_case_		:							Tuple			       =						list(_UpperCamelCase			)
									snake_case_		:							str			       =						list(_UpperCamelCase			)
									snake_case_		:							Dict			       =						conv_bias
									snake_case_		:							Tuple			       =						num_conv_pos_embeddings
									snake_case_		:							List[str]			       =						num_conv_pos_embedding_groups
									snake_case_		:							Any			       =						len(self.conv_dim			)
									snake_case_		:							Optional[Any]			       =						num_hidden_layers
									snake_case_		:							str			       =						intermediate_size
									snake_case_		:							Tuple			       =						squeeze_factor
									snake_case_		:							List[Any]			       =						hidden_act
									snake_case_		:							List[str]			       =						num_attention_heads
									snake_case_		:							Union[str, Any]			       =						hidden_dropout
									snake_case_		:							List[str]			       =						attention_dropout
									snake_case_		:							List[str]			       =						activation_dropout
									snake_case_		:							Optional[int]			       =						feat_proj_dropout
									snake_case_		:							Union[str, Any]			       =						final_dropout
									snake_case_		:							Tuple			       =						layerdrop
									snake_case_		:							List[Any]			       =						layer_norm_eps
									snake_case_		:							List[Any]			       =						initializer_range
									snake_case_		:							str			       =						vocab_size

									if (
									    (len(self.conv_stride			) != self.num_feat_extract_layers)
									    or (len(self.conv_kernel			) != self.num_feat_extract_layers)
									    or (len(self.conv_dim			) != self.num_feat_extract_layers)
									):
											raise ValueError(
											    """Configuration for convolutional layers is incorrect."""
											    """It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,"""
											    F'''but is `len(config.conv_dim) = {len(self.conv_dim			)}`, `len(config.conv_stride)'''
											    F'''= {len(self.conv_stride			)}`, `len(config.conv_kernel) = {len(self.conv_kernel			)}`.'''			)

									# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
									snake_case_		:							Any			       =						apply_spec_augment
									snake_case_		:							Any			       =						mask_time_prob
									snake_case_		:							List[str]			       =						mask_time_length
									snake_case_		:							List[Any]			       =						mask_time_min_masks
									snake_case_		:							int			       =						mask_feature_prob
									snake_case_		:							Union[str, Any]			       =						mask_feature_length
									snake_case_		:							Union[str, Any]			       =						mask_feature_min_masks

									# ctc loss
									snake_case_		:							Tuple			       =						ctc_loss_reduction
									snake_case_		:							str			       =						ctc_zero_infinity

									# sequence classification
									snake_case_		:							Dict			       =						use_weighted_layer_sum
									snake_case_		:							Any			       =						classifier_proj_size





							@property
							def 		a__   (  self		:Tuple			):
									return functools.reduce(operator.mul  ,self.conv_stride  ,1			)



'''simple docstring'''






from __future__ import annotations

import math





def      UpperCAmelCase      (		lowerCamelCase_  :list				,      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_		:							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      UpperCAmelCase      (		lowerCamelCase_  :list				,      lowerCamelCase_  :list ):







		'''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      UpperCAmelCase      (		lowerCamelCase_  :list				,      lowerCamelCase_  :list ):







		'''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      UpperCAmelCase      (		lowerCamelCase_  :list ):







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

		snake_case_		:							Optional[int]			       =						len(lowerCamelCase_ )
		snake_case_		:							List[str]			       =						matrix_length // 2

		snake_case_		:							Union[str, Any]			       =						[[a[i][j] for j in range(lowerCamelCase_				,      lowerCamelCase_ )] for i in range(lowerCamelCase_ )]
		snake_case_		:							Dict			       =						[
		    [a[i][j] for j in range(lowerCamelCase_				,      lowerCamelCase_ )] for i in range(lowerCamelCase_				,      lowerCamelCase_ )
		]

		snake_case_		:							str			       =						[[a[i][j] for j in range(lowerCamelCase_ )] for i in range(lowerCamelCase_ )]
		snake_case_		:							Dict			       =						[[a[i][j] for j in range(lowerCamelCase_ )] for i in range(lowerCamelCase_				,      lowerCamelCase_ )]

		return top_left, top_right, bot_left, bot_right





def      UpperCAmelCase      (		lowerCamelCase_  :list ):







		'''simple docstring'''
		return len(lowerCamelCase_ ), len(matrix[0] )





def      UpperCAmelCase      (		lowerCamelCase_  :list ):







		'''simple docstring'''
		print("""\n""".join(str(lowerCamelCase_ ) for line in matrix ) )





def      UpperCAmelCase      (		lowerCamelCase_  :list				,      lowerCamelCase_  :list ):







		'''simple docstring'''
		if matrix_dimensions(lowerCamelCase_ ) == (2, 2):
				return default_matrix_multiplication(lowerCamelCase_				,      lowerCamelCase_ )

		snake_case_       ,      snake_case_       ,      snake_case_       ,      snake_case_		:							Any			       =						split_matrix(lowerCamelCase_ )
		snake_case_       ,      snake_case_       ,      snake_case_       ,      snake_case_		:							List[Any]			       =						split_matrix(lowerCamelCase_ )

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

		snake_case_		:							List[Any]			       =						matrix_addition(matrix_subtraction(matrix_addition(lowerCamelCase_				,      lowerCamelCase_ )				,      lowerCamelCase_ )				,      lowerCamelCase_ )
		snake_case_		:							List[Any]			       =						matrix_addition(lowerCamelCase_				,      lowerCamelCase_ )
		snake_case_		:							str			       =						matrix_addition(lowerCamelCase_				,      lowerCamelCase_ )
		snake_case_		:							Any			       =						matrix_subtraction(matrix_subtraction(matrix_addition(lowerCamelCase_				,      lowerCamelCase_ )				,      lowerCamelCase_ )				,      lowerCamelCase_ )

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







		'''simple docstring'''
		if matrix_dimensions(lowerCamelCase_ )[1] != matrix_dimensions(lowerCamelCase_ )[0]:
				snake_case_		:							Optional[int]			       =						(
				    """Unable to multiply these matrices, please check the dimensions.\n"""
				    F'''Matrix A: {matrixa}\n'''
				    F'''Matrix B: {matrixa}'''
				)
				raise Exception(lowerCamelCase_ )
		snake_case_		:							Tuple			       =						matrix_dimensions(lowerCamelCase_ )
		snake_case_		:							Union[str, Any]			       =						matrix_dimensions(lowerCamelCase_ )

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

		snake_case_		:							int			       =						max(*lowerCamelCase_				,      *lowerCamelCase_ )
		snake_case_		:							Union[str, Any]			       =						int(math.pow(2				,      math.ceil(math.loga(lowerCamelCase_ ) ) ) )
		snake_case_		:							Dict			       =						matrixa
		snake_case_		:							Optional[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 )

		snake_case_		:							Dict			       =						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	:	Optional[int]     =     [
							    [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[str]     =     [[0, 2, 1, 1], [16, 2, 3, 3], [2, 2, 7, 7], [13, 11, 22, 4]]
							print(strassen(matrixa, matrixa))