
from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload





class 	_lowerCAmelCase					:




				def __init__(					self				,				_UpperCamelCase = None     )				->      None:
							if components is None:
										lowerCAmelCase_						=	[]
							lowerCAmelCase_						=	list(_UpperCamelCase     )




				def __len__(					self     )				->      int:
							return len(self.__components     )




				def __str__(					self     )				->      str:
							return "(" + ",".join(map(_UpperCamelCase				,				self.__components     )     ) + ")"




				def __add__(					self				,				_UpperCamelCase     )				->      Vector:
							lowerCAmelCase_						=	len(self     )
							if size == len(_UpperCamelCase     ):
										lowerCAmelCase_						=	[self.__components[i] + other.component(_UpperCamelCase     ) for i in range(_UpperCamelCase     )]
										return Vector(_UpperCamelCase     )
							else:
										raise Exception("must have the same size"     )




				def __sub__(					self				,				_UpperCamelCase     )				->      Vector:
							lowerCAmelCase_						=	len(self     )
							if size == len(_UpperCamelCase     ):
										lowerCAmelCase_						=	[self.__components[i] - other.component(_UpperCamelCase     ) for i in range(_UpperCamelCase     )]
										return Vector(_UpperCamelCase     )
							else:  # error case
										raise Exception("must have the same size"     )




				@overload
				def __mul__(					self				,				_UpperCamelCase     )				->      Vector:
							...




				@overload
				def __mul__(					self				,				_UpperCamelCase     )				->      float:
							...




				def __mul__(					self				,				_UpperCamelCase     )				->      float | Vector:
							if isinstance(_UpperCamelCase				,				(float, int)     ):
										lowerCAmelCase_						=	[c * other for c in self.__components]
										return Vector(_UpperCamelCase     )
							elif isinstance(_UpperCamelCase				,				_UpperCamelCase     ) and len(self     ) == len(_UpperCamelCase     ):
										lowerCAmelCase_						=	len(self     )
										lowerCAmelCase_						=	[self.__components[i] * other.component(_UpperCamelCase     ) for i in range(_UpperCamelCase     )]
										return sum(_UpperCamelCase     )
							else:  # error case
										raise Exception("invalid operand!"     )




				def      __a						(					self     )				->      Vector:
							return Vector(self.__components     )




				def      __a						(					self				,				_UpperCamelCase     )				->      float:
							if isinstance(_UpperCamelCase				,				_UpperCamelCase     ) and -len(self.__components     ) <= i < len(self.__components     ):
										return self.__components[i]
							else:
										raise Exception("index out of range"     )




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase     )				->      None:
							assert -len(self.__components     ) <= pos < len(self.__components     )
							lowerCAmelCase_						=	value




				def      __a						(					self     )				->      float:
							if len(self.__components     ) == 0:
										raise Exception("Vector is empty"     )
							lowerCAmelCase_						=	[c**2 for c in self.__components]
							return math.sqrt(sum(_UpperCamelCase     )     )




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase = False     )				->      float:
							lowerCAmelCase_						=	self * other
							lowerCAmelCase_						=	self.euclidean_length() * other.euclidean_length()
							if deg:
										return math.degrees(math.acos(num / den     )     )
							else:
										return math.acos(num / den     )






def    lowerCamelCase__				(				__lowerCAmelCase  :  int				):




			"""simple docstring"""


			assert isinstance(__lowerCAmelCase    ,							__lowerCAmelCase				)
			return Vector([0] * dimension				)






def    lowerCamelCase__				(				__lowerCAmelCase  :  int    ,							__lowerCAmelCase  :  int				):




			"""simple docstring"""


			assert isinstance(__lowerCAmelCase    ,							__lowerCAmelCase				) and (isinstance(__lowerCAmelCase    ,							__lowerCAmelCase				))
			lowerCAmelCase_						=	[0] * dimension
			lowerCAmelCase_						=	1
			return Vector(__lowerCAmelCase				)






def    lowerCamelCase__				(				__lowerCAmelCase  :  float    ,							__lowerCAmelCase  :  Vector    ,							__lowerCAmelCase  :  Vector				):




			"""simple docstring"""


			assert (
			    isinstance(__lowerCAmelCase    ,							__lowerCAmelCase				)
			    and isinstance(__lowerCAmelCase    ,							__lowerCAmelCase				)
			    and (isinstance(__lowerCAmelCase    ,							(int, float)				))
			)
			return x * scalar + y






def    lowerCamelCase__				(				__lowerCAmelCase  :  int    ,							__lowerCAmelCase  :  int    ,							__lowerCAmelCase  :  int				):




			"""simple docstring"""


			random.seed(__lowerCAmelCase				)
			lowerCAmelCase_						=	[random.randint(__lowerCAmelCase    ,							__lowerCAmelCase				) for _ in range(__lowerCAmelCase				)]
			return Vector(__lowerCAmelCase				)





class 	_lowerCAmelCase					:




				def __init__(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      None:
							lowerCAmelCase_						=	matrix
							lowerCAmelCase_						=	w
							lowerCAmelCase_						=	h




				def __str__(					self     )				->      str:
							lowerCAmelCase_						=	""
							for i in range(self.__height     ):
										ans += "|"
										for j in range(self.__width     ):
													if j < self.__width - 1:
																ans += str(self.__matrix[i][j]     ) + ","
													else:
																ans += str(self.__matrix[i][j]     ) + "|\n"
							return ans




				def __add__(					self				,				_UpperCamelCase     )				->      Matrix:
							if self.__width == other.width() and self.__height == other.height():
										lowerCAmelCase_						=	[]
										for i in range(self.__height     ):
													lowerCAmelCase_						=	[
													    self.__matrix[i][j] + other.component(_UpperCamelCase				,				_UpperCamelCase     )
													    for j in range(self.__width     )
													]
													matrix.append(_UpperCamelCase     )
										return Matrix(_UpperCamelCase				,				self.__width				,				self.__height     )
							else:
										raise Exception("matrix must have the same dimension!"     )




				def __sub__(					self				,				_UpperCamelCase     )				->      Matrix:
							if self.__width == other.width() and self.__height == other.height():
										lowerCAmelCase_						=	[]
										for i in range(self.__height     ):
													lowerCAmelCase_						=	[
													    self.__matrix[i][j] - other.component(_UpperCamelCase				,				_UpperCamelCase     )
													    for j in range(self.__width     )
													]
													matrix.append(_UpperCamelCase     )
										return Matrix(_UpperCamelCase				,				self.__width				,				self.__height     )
							else:
										raise Exception("matrices must have the same dimension!"     )




				@overload
				def __mul__(					self				,				_UpperCamelCase     )				->      Matrix:
							...




				@overload
				def __mul__(					self				,				_UpperCamelCase     )				->      Vector:
							...




				def __mul__(					self				,				_UpperCamelCase     )				->      Vector | Matrix:
							if isinstance(_UpperCamelCase				,				_UpperCamelCase     ):  # matrix-vector
										if len(_UpperCamelCase     ) == self.__width:
													lowerCAmelCase_						=	zero_vector(self.__height     )
													for i in range(self.__height     ):
																lowerCAmelCase_						=	[
																    self.__matrix[i][j] * other.component(_UpperCamelCase     )
																    for j in range(self.__width     )
																]
																ans.change_component(_UpperCamelCase				,				sum(_UpperCamelCase     )     )
													return ans
										else:
													raise Exception(
													    "vector must have the same size as the "
													    "number of columns of the matrix!"     )
							elif isinstance(_UpperCamelCase				,				(int, float)     ):  # matrix-scalar
										lowerCAmelCase_						=	[
										    [self.__matrix[i][j] * other for j in range(self.__width     )]
										    for i in range(self.__height     )
										]
										return Matrix(_UpperCamelCase				,				self.__width				,				self.__height     )
							return None




				def      __a						(					self     )				->      int:
							return self.__height




				def      __a						(					self     )				->      int:
							return self.__width




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase     )				->      float:
							if 0 <= x < self.__height and 0 <= y < self.__width:
										return self.__matrix[x][y]
							else:
										raise Exception("change_component: indices out of bounds"     )




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      None:
							if 0 <= x < self.__height and 0 <= y < self.__width:
										lowerCAmelCase_						=	value
							else:
										raise Exception("change_component: indices out of bounds"     )




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase     )				->      float:
							if self.__height != self.__width:
										raise Exception("Matrix is not square"     )
							lowerCAmelCase_						=	self.__matrix[:x] + self.__matrix[x + 1 :]
							for i in range(len(_UpperCamelCase     )     ):
										lowerCAmelCase_						=	minor[i][:y] + minor[i][y + 1 :]
							return Matrix(_UpperCamelCase				,				self.__width - 1				,				self.__height - 1     ).determinant()




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase     )				->      float:
							if self.__height != self.__width:
										raise Exception("Matrix is not square"     )
							if 0 <= x < self.__height and 0 <= y < self.__width:
										return (-1) ** (x + y) * self.minor(_UpperCamelCase				,				_UpperCamelCase     )
							else:
										raise Exception("Indices out of bounds"     )




				def      __a						(					self     )				->      float:
							if self.__height != self.__width:
										raise Exception("Matrix is not square"     )
							if self.__height < 1:
										raise Exception("Matrix has no element"     )
							elif self.__height == 1:
										return self.__matrix[0][0]
							elif self.__height == 2:
										return (
										    self.__matrix[0][0] * self.__matrix[1][1]
										    - self.__matrix[0][1] * self.__matrix[1][0]
										)
							else:
										lowerCAmelCase_						=	[
										    self.__matrix[0][y] * self.cofactor(0				,				_UpperCamelCase     ) for y in range(self.__width     )
										]
										return sum(_UpperCamelCase     )






def    lowerCamelCase__				(				__lowerCAmelCase  :  int				):




			"""simple docstring"""


			lowerCAmelCase_						=	[[0] * n for _ in range(__lowerCAmelCase				)]
			return Matrix(__lowerCAmelCase    ,							__lowerCAmelCase    ,							__lowerCAmelCase				)






def    lowerCamelCase__				(				__lowerCAmelCase  :  int    ,							__lowerCAmelCase  :  int    ,							__lowerCAmelCase  :  int    ,							__lowerCAmelCase  :  int				):




			"""simple docstring"""


			random.seed(__lowerCAmelCase				)
			lowerCAmelCase_						=	[
			    [random.randint(__lowerCAmelCase    ,							__lowerCAmelCase				) for _ in range(__lowerCAmelCase				)] for _ in range(__lowerCAmelCase				)
			]
			return Matrix(__lowerCAmelCase    ,							__lowerCAmelCase    ,							__lowerCAmelCase				)





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


_A   =     logging.get_logger(__name__)

_A   =     {
    # See all MEGATRON_BERT models at https://huggingface.co/models?filter=bert
}





class 	_lowerCAmelCase					(	__a       ):
				_lowercase					='''megatron-bert'''




				def __init__(					self				,				_UpperCamelCase=29_056				,				_UpperCamelCase=1_024				,				_UpperCamelCase=24				,				_UpperCamelCase=16				,				_UpperCamelCase=4_096				,				_UpperCamelCase="gelu"				,				_UpperCamelCase=0.1				,				_UpperCamelCase=0.1				,				_UpperCamelCase=512				,				_UpperCamelCase=2				,				_UpperCamelCase=0.02				,				_UpperCamelCase=1e-1_2				,				_UpperCamelCase=0				,				_UpperCamelCase="absolute"				,				_UpperCamelCase=True				,				**_UpperCamelCase				,				)				->      int:
							super().__init__(pad_token_id=_UpperCamelCase				,				**_UpperCamelCase     )

							lowerCAmelCase_						=	vocab_size
							lowerCAmelCase_						=	hidden_size
							lowerCAmelCase_						=	num_hidden_layers
							lowerCAmelCase_						=	num_attention_heads
							lowerCAmelCase_						=	hidden_act
							lowerCAmelCase_						=	intermediate_size
							lowerCAmelCase_						=	hidden_dropout_prob
							lowerCAmelCase_						=	attention_probs_dropout_prob
							lowerCAmelCase_						=	max_position_embeddings
							lowerCAmelCase_						=	type_vocab_size
							lowerCAmelCase_						=	initializer_range
							lowerCAmelCase_						=	layer_norm_eps
							lowerCAmelCase_						=	position_embedding_type
							lowerCAmelCase_						=	use_cache



