

"""simple docstring"""




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


lowerCAmelCase							:  Union[str, Any]            =						logging.get_logger(__name__)

lowerCAmelCase							:  Any            =						{
    """microsoft/trocr-base-handwritten""": (
        """https://huggingface.co/microsoft/trocr-base-handwritten/resolve/main/config.json"""
    ),
    # See all TrOCR models at https://huggingface.co/models?filter=trocr
}



class   __lowercase    (			UpperCAmelCase_     ):




			"""simple docstring"""







			_UpperCAmelCase       :							Any      							=					'''trocr'''
			_UpperCAmelCase       :							Optional[Any]      							=					['''past_key_values''']
			_UpperCAmelCase       :							List[Any]      							=					{
			    '''num_attention_heads''': '''decoder_attention_heads''',
			    '''hidden_size''': '''d_model''',
			    '''num_hidden_layers''': '''decoder_layers''',
			}



			def __init__(			self  :					Any       ,						lowerCAmelCase__  :					Dict=5_0265       ,						lowerCAmelCase__  :					Union[str, Any]=1024       ,						lowerCAmelCase__  :					Union[str, Any]=12       ,						lowerCAmelCase__  :					List[str]=16       ,						lowerCAmelCase__  :					Optional[Any]=4096       ,						lowerCAmelCase__  :					Any="gelu"       ,						lowerCAmelCase__  :					Optional[int]=512       ,						lowerCAmelCase__  :					int=0.1       ,						lowerCAmelCase__  :					str=0.0       ,						lowerCAmelCase__  :					str=0.0       ,						lowerCAmelCase__  :					List[Any]=2       ,						lowerCAmelCase__  :					List[Any]=0.02       ,						lowerCAmelCase__  :					List[Any]=0.0       ,						lowerCAmelCase__  :					Optional[int]=True       ,						lowerCAmelCase__  :					Tuple=False       ,						lowerCAmelCase__  :					str=True       ,						lowerCAmelCase__  :					Optional[int]=True       ,						lowerCAmelCase__  :					Any=1       ,						lowerCAmelCase__  :					int=0       ,						lowerCAmelCase__  :					Union[str, Any]=2       ,						**lowerCAmelCase__  :					List[str]       ,						):
									SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	vocab_size
									SCREAMING_SNAKE_CASE_:			int  		=	d_model
									SCREAMING_SNAKE_CASE_:			str  		=	decoder_layers
									SCREAMING_SNAKE_CASE_:			List[str]  		=	decoder_attention_heads
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	decoder_ffn_dim
									SCREAMING_SNAKE_CASE_:			Tuple  		=	activation_function
									SCREAMING_SNAKE_CASE_:			Dict  		=	max_position_embeddings
									SCREAMING_SNAKE_CASE_:			Optional[Any]  		=	dropout
									SCREAMING_SNAKE_CASE_:			List[str]  		=	attention_dropout
									SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	activation_dropout
									SCREAMING_SNAKE_CASE_:			int  		=	init_std
									SCREAMING_SNAKE_CASE_:			str  		=	decoder_layerdrop
									SCREAMING_SNAKE_CASE_:			int  		=	use_cache
									SCREAMING_SNAKE_CASE_:			Dict  		=	scale_embedding
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	use_learned_position_embeddings
									SCREAMING_SNAKE_CASE_:			Optional[int]  		=	layernorm_embedding

									super().__init__(
									    pad_token_id=lowerCAmelCase__       ,						bos_token_id=lowerCAmelCase__       ,						eos_token_id=lowerCAmelCase__       ,						decoder_start_token_id=lowerCAmelCase__       ,						**lowerCAmelCase__       ,						)









import doctest
from collections import deque

import numpy as np



class   __lowercase    :




			"""simple docstring"""







			def __init__(			self  :					Union[str, Any]):
									SCREAMING_SNAKE_CASE_:			int  		=	[2, 1, 2, -1]
									SCREAMING_SNAKE_CASE_:			Optional[Any]  		=	[1, 2, 3, 4]




			def 	_SCREAMING_SNAKE_CASE      (			self  :					Tuple):
									SCREAMING_SNAKE_CASE_:			Any  		=	len(self.first_signal)
									SCREAMING_SNAKE_CASE_:			Dict  		=	len(self.second_signal)

									SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	max(lowerCAmelCase__       ,						lowerCAmelCase__)

									# create a zero matrix of max_length x max_length
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	[[0] * max_length for i in range(lowerCAmelCase__)]

									# fills the smaller signal with zeros to make both signals of same length
									if length_first_signal < length_second_signal:
															self.first_signal += [0] * (max_length - length_first_signal)
									elif length_first_signal > length_second_signal:
															self.second_signal += [0] * (max_length - length_second_signal)
									for i in range(lowerCAmelCase__):
															SCREAMING_SNAKE_CASE_:			Tuple  		=	deque(self.second_signal)
															rotated_signal.rotate(lowerCAmelCase__)
															for j, item in enumerate(lowerCAmelCase__):
																					matrix[i][j] += item

        # multiply the matrix with the first signal
									SCREAMING_SNAKE_CASE_:			Optional[Any]  		=	np.matmul(np.transpose(lowerCAmelCase__)       ,						np.transpose(self.first_signal))

									# rounding-off to two decimal places
									return [round(lowerCAmelCase__       ,						2) for i in final_signal]


if __name__ == "__main__":
						doctest.testmod()






