


'''simple docstring'''
import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
		import jax.numpy as jnp

		from transformers.models.albert.modeling_flax_albert import (
		    FlaxAlbertForMaskedLM,
		    FlaxAlbertForMultipleChoice,
		    FlaxAlbertForPreTraining,
		    FlaxAlbertForQuestionAnswering,
		    FlaxAlbertForSequenceClassification,
		    FlaxAlbertForTokenClassification,
		    FlaxAlbertModel,
		)
class   lowercase      (				unittest.TestCase   ):

		"""simple docstring"""

		def __init__(						self       ,  UpperCamelCase_       ,  UpperCamelCase_=13       ,  UpperCamelCase_=7       ,  UpperCamelCase_=True       ,  UpperCamelCase_=True       ,  UpperCamelCase_=True       ,  UpperCamelCase_=True       ,  UpperCamelCase_=99       ,  UpperCamelCase_=32       ,  UpperCamelCase_=5       ,  UpperCamelCase_=4       ,  UpperCamelCase_=37       ,  UpperCamelCase_="gelu"       ,  UpperCamelCase_=0.1       ,  UpperCamelCase_=0.1       ,  UpperCamelCase_=512       ,  UpperCamelCase_=16       ,  UpperCamelCase_=2       ,  UpperCamelCase_=0.02       ,  UpperCamelCase_=4       ,  ):

							'''simple docstring'''


							UpperCamelCase__  :int				   =					parent
							UpperCamelCase__  :List[Any]				   =					batch_size
							UpperCamelCase__  :Any				   =					seq_length
							UpperCamelCase__  :Optional[int]				   =					is_training
							UpperCamelCase__  :str				   =					use_attention_mask
							UpperCamelCase__  :str				   =					use_token_type_ids
							UpperCamelCase__  :Any				   =					use_labels
							UpperCamelCase__  :int				   =					vocab_size
							UpperCamelCase__  :Tuple				   =					hidden_size
							UpperCamelCase__  :Tuple				   =					num_hidden_layers
							UpperCamelCase__  :Optional[int]				   =					num_attention_heads
							UpperCamelCase__  :List[Any]				   =					intermediate_size
							UpperCamelCase__  :List[Any]				   =					hidden_act
							UpperCamelCase__  :str				   =					hidden_dropout_prob
							UpperCamelCase__  :Optional[int]				   =					attention_probs_dropout_prob
							UpperCamelCase__  :Optional[int]				   =					max_position_embeddings
							UpperCamelCase__  :int				   =					type_vocab_size
							UpperCamelCase__  :int				   =					type_sequence_label_size
							UpperCamelCase__  :List[str]				   =					initializer_range
							UpperCamelCase__  :Union[str, Any]				   =					num_choices




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Optional[Any]				   =					ids_tensor([self.batch_size, self.seq_length]       ,  self.vocab_size				)

							UpperCamelCase__  :Union[str, Any]				   =					None
							if self.use_attention_mask:
												UpperCamelCase__  :List[Any]				   =					random_attention_mask([self.batch_size, self.seq_length]				)

							UpperCamelCase__  :Union[str, Any]				   =					None
							if self.use_token_type_ids:
												UpperCamelCase__  :List[Any]				   =					ids_tensor([self.batch_size, self.seq_length]       ,  self.type_vocab_size				)

							UpperCamelCase__  :int				   =					AlbertConfig(
							    vocab_size=self.vocab_size       ,  hidden_size=self.hidden_size       ,  num_hidden_layers=self.num_hidden_layers       ,  num_attention_heads=self.num_attention_heads       ,  intermediate_size=self.intermediate_size       ,  hidden_act=self.hidden_act       ,  hidden_dropout_prob=self.hidden_dropout_prob       ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,  max_position_embeddings=self.max_position_embeddings       ,  type_vocab_size=self.type_vocab_size       ,  is_decoder=UpperCamelCase_       ,  initializer_range=self.initializer_range       ,  )

							return config, input_ids, token_type_ids, attention_mask




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Dict				   =					self.prepare_config_and_inputs()
							UpperCamelCase__   ,							UpperCamelCase__   ,							UpperCamelCase__   ,							UpperCamelCase__  :Any				   =					config_and_inputs
							UpperCamelCase__  :List[str]				   =					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
							return config, inputs_dict



@require_flax
class   lowercase      (				A__      ,						unittest.TestCase   ):

		"""simple docstring"""

		_a       					=							(
		    (
		        FlaxAlbertModel,
		        FlaxAlbertForPreTraining,
		        FlaxAlbertForMaskedLM,
		        FlaxAlbertForMultipleChoice,
		        FlaxAlbertForQuestionAnswering,
		        FlaxAlbertForSequenceClassification,
		        FlaxAlbertForTokenClassification,
		        FlaxAlbertForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Optional[Any]				   =					FlaxAlbertModelTester(self				)




		@slow
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							for model_class_name in self.all_model_classes:
												UpperCamelCase__  :Tuple				   =					model_class_name.from_pretrained('''albert-base-v2'''				)
												UpperCamelCase__  :Any				   =					model(np.ones((1, 1)				)				)
												self.assertIsNotNone(UpperCamelCase_				)



@require_flax
class   lowercase      (				unittest.TestCase   ):

		"""simple docstring"""

		@slow
		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							UpperCamelCase__  :int				   =					FlaxAlbertModel.from_pretrained('''albert-base-v2'''				)
							UpperCamelCase__  :List[str]				   =					np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]				)
							UpperCamelCase__  :Optional[Any]				   =					np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
							UpperCamelCase__  :List[Any]				   =					model(UpperCamelCase_       ,  attention_mask=UpperCamelCase_				)[0]
							UpperCamelCase__  :Any				   =					(1, 11, 768)
							self.assertEqual(output.shape       ,  UpperCamelCase_				)
							UpperCamelCase__  :Dict				   =					np.array(
							    [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]				)

							self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]       ,  UpperCamelCase_       ,  atol=1e-4				)				)



'''simple docstring'''
from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload
class   lowercase      :

		"""simple docstring"""

		def __init__(						self       ,  UpperCamelCase_ = None				):

							'''simple docstring'''


							if components is None:
												UpperCamelCase__  :List[Any]				   =					[]
							UpperCamelCase__  :Optional[Any]				   =					list(UpperCamelCase_				)




		def __len__(						self				):

							'''simple docstring'''


							return len(self.__components				)




		def __str__(						self				):

							'''simple docstring'''


							return "(" + ",".join(map(UpperCamelCase_       ,  self.__components				)				) + ")"




		def __add__(						self       ,  UpperCamelCase_				):

							'''simple docstring'''


							UpperCamelCase__  :Any				   =					len(self				)
							if size == len(UpperCamelCase_				):
												UpperCamelCase__  :Dict				   =					[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_				):

							'''simple docstring'''


							UpperCamelCase__  :Optional[Any]				   =					len(self				)
							if size == len(UpperCamelCase_				):
												UpperCamelCase__  :List[str]				   =					[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_				):

							'''simple docstring'''


							...




		@overload
		def __mul__(						self       ,  UpperCamelCase_				):

							'''simple docstring'''


							...




		def __mul__(						self       ,  UpperCamelCase_				):

							'''simple docstring'''


							if isinstance(UpperCamelCase_       ,  (float, int)				):
												UpperCamelCase__  :Optional[Any]				   =					[c * other for c in self.__components]
												return Vector(UpperCamelCase_				)
							elif isinstance(UpperCamelCase_       ,  UpperCamelCase_				) and len(self				) == len(UpperCamelCase_				):
												UpperCamelCase__  :Optional[int]				   =					len(self				)
												UpperCamelCase__  :List[Any]				   =					[self.__components[i] * other.component(UpperCamelCase_				) for i in range(UpperCamelCase_				)]
												return sum(UpperCamelCase_				)
							else:  # error case
												raise Exception('''invalid operand!'''				)




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							return Vector(self.__components				)




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_				):

							'''simple docstring'''


							if isinstance(UpperCamelCase_       ,  UpperCamelCase_				) and -len(self.__components				) <= i < len(self.__components				):
												return self.__components[i]
							else:
												raise Exception('''index out of range'''				)




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							assert -len(self.__components				) <= pos < len(self.__components				)
							UpperCamelCase__  :Optional[int]				   =					value




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							if len(self.__components				) == 0:
												raise Exception('''Vector is empty'''				)
							UpperCamelCase__  :List[str]				   =					[c**2 for c in self.__components]
							return math.sqrt(sum(UpperCamelCase_				)				)




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_ = False				):

							'''simple docstring'''


							UpperCamelCase__  :List[Any]				   =					self * other
							UpperCamelCase__  :Optional[int]				   =					self.euclidean_length() * other.euclidean_length()
							if deg:
												return math.degrees(math.acos(num / den				)				)
							else:
												return math.acos(num / den				)



def      a (     __a  )    ->      Vector:



					'''simple docstring'''






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


def      a (     __a					,   __a  )    ->      Vector:



					'''simple docstring'''






					assert isinstance(__a					,   __a  ) and (isinstance(__a					,   __a  ))
					UpperCamelCase__  :str				   =					[0] * dimension
					UpperCamelCase__  :Tuple				   =					1
					return Vector(__a  )


def      a (     __a					,   __a					,   __a  )    ->      Vector:



					'''simple docstring'''






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


def      a (     __a					,   __a					,   __a  )    ->      Vector:



					'''simple docstring'''






					random.seed(__a  )
					UpperCamelCase__  :Optional[Any]				   =					[random.randint(__a					,   __a  ) for _ in range(__a  )]
					return Vector(__a  )
class   lowercase      :

		"""simple docstring"""

		def __init__(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							UpperCamelCase__  :int				   =					matrix
							UpperCamelCase__  :Union[str, Any]				   =					w
							UpperCamelCase__  :Optional[int]				   =					h




		def __str__(						self				):

							'''simple docstring'''


							UpperCamelCase__  :Dict				   =					''''''
							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_				):

							'''simple docstring'''


							if self.__width == other.width() and self.__height == other.height():
												UpperCamelCase__  :int				   =					[]
												for i in range(self.__height				):
																	UpperCamelCase__  :int				   =					[
																	    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_				):

							'''simple docstring'''


							if self.__width == other.width() and self.__height == other.height():
												UpperCamelCase__  :Optional[Any]				   =					[]
												for i in range(self.__height				):
																	UpperCamelCase__  :Optional[int]				   =					[
																	    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_				):

							'''simple docstring'''


							...




		@overload
		def __mul__(						self       ,  UpperCamelCase_				):

							'''simple docstring'''


							...




		def __mul__(						self       ,  UpperCamelCase_				):

							'''simple docstring'''


							if isinstance(UpperCamelCase_       ,  UpperCamelCase_				):  # matrix-vector
												if len(UpperCamelCase_				) == self.__width:
																	UpperCamelCase__  :Any				   =					zero_vector(self.__height				)
																	for i in range(self.__height				):
																						UpperCamelCase__  :Any				   =					[
																						    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
												UpperCamelCase__  :Union[str, Any]				   =					[
												    [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        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							return self.__height




		def        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							return self.__width




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							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        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							if 0 <= x < self.__height and 0 <= y < self.__width:
												UpperCamelCase__  :Tuple				   =					value
							else:
												raise Exception('''change_component: indices out of bounds'''				)




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							if self.__height != self.__width:
												raise Exception('''Matrix is not square'''				)
							UpperCamelCase__  :str				   =					self.__matrix[:x] + self.__matrix[x + 1 :]
							for i in range(len(UpperCamelCase_				)				):
												UpperCamelCase__  :Union[str, Any]				   =					minor[i][:y] + minor[i][y + 1 :]
							return Matrix(UpperCamelCase_       ,  self.__width - 1       ,  self.__height - 1				).determinant()




		def        lowerCAmelCase__							(						self       ,  UpperCamelCase_       ,  UpperCamelCase_				):

							'''simple docstring'''


							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        lowerCAmelCase__							(						self				):

							'''simple docstring'''


							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:
												UpperCamelCase__  :Optional[Any]				   =					[
												    self.__matrix[0][y] * self.cofactor(0       ,  UpperCamelCase_				) for y in range(self.__width				)
												]
												return sum(UpperCamelCase_				)



def      a (     __a  )    ->      Matrix:



					'''simple docstring'''






					UpperCamelCase__  :list[list[float]]				   =					[[0] * n for _ in range(__a  )]
					return Matrix(__a					,   __a					,   __a  )







def      a (     __a					,   __a					,   __a					,   __a  )    ->      Matrix:



					'''simple docstring'''






					random.seed(__a  )
					UpperCamelCase__  :list[list[float]]				   =					[
					    [random.randint(__a					,   __a  ) for _ in range(__a  )] for _ in range(__a  )
					]
					return Matrix(__a					,   __a					,   __a  )