



'''simple docstring'''
import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
					from transformers.models.bert.modeling_flax_bert import (
					    FlaxBertForMaskedLM,
					    FlaxBertForMultipleChoice,
					    FlaxBertForNextSentencePrediction,
					    FlaxBertForPreTraining,
					    FlaxBertForQuestionAnswering,
					    FlaxBertForSequenceClassification,
					    FlaxBertForTokenClassification,
					    FlaxBertModel,
					)






class 				lowercase__      (				unittest.TestCase  ):





	def __init__(					self   :							Tuple					,lowerCamelCase__   :							List[str]					,lowerCamelCase__   :							int=13					,lowerCamelCase__   :							Optional[Any]=7					,lowerCamelCase__   :							Dict=True					,lowerCamelCase__   :							Tuple=True					,lowerCamelCase__   :							Optional[Any]=True					,lowerCamelCase__   :							int=True					,lowerCamelCase__   :							Union[str, Any]=99					,lowerCamelCase__   :							Tuple=32					,lowerCamelCase__   :							Union[str, Any]=5					,lowerCamelCase__   :							int=4					,lowerCamelCase__   :							Optional[Any]=37					,lowerCamelCase__   :							Optional[Any]="gelu"					,lowerCamelCase__   :							List[Any]=0.1					,lowerCamelCase__   :							int=0.1					,lowerCamelCase__   :							Tuple=512					,lowerCamelCase__   :							Dict=16					,lowerCamelCase__   :							Union[str, Any]=2					,lowerCamelCase__   :							Any=0.0_2					,lowerCamelCase__   :							List[Any]=4					,):







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





	def       UpperCamelCase_    (					self   :							List[Any]					):







							'''simple docstring'''
							_UpperCamelCase   :						Tuple												=  ids_tensor([self.batch_size, self.seq_length]					,self.vocab_size					)

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

							_UpperCamelCase   :						Dict												=  None
							if self.use_token_type_ids:
													_UpperCamelCase   :						Tuple												=  ids_tensor([self.batch_size, self.seq_length]					,self.type_vocab_size					)

							_UpperCamelCase   :						Optional[int]												=  BertConfig(
							    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=lowerCamelCase__					,initializer_range=self.initializer_range					,)

							return config, input_ids, token_type_ids, attention_mask





	def       UpperCamelCase_    (					self   :							int					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[Any]												=  self.prepare_config_and_inputs()
							_UpperCamelCase							,     _UpperCamelCase							,     _UpperCamelCase							,     _UpperCamelCase   :						List[str]												=  config_and_inputs
							_UpperCamelCase   :						Union[str, Any]												=  {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
							return config, inputs_dict





	def       UpperCamelCase_    (					self   :							Tuple					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[Any]												=  self.prepare_config_and_inputs()
							_UpperCamelCase							,     _UpperCamelCase							,     _UpperCamelCase							,     _UpperCamelCase   :						Any												=  config_and_inputs

							_UpperCamelCase   :						Optional[int]												=  True
							_UpperCamelCase   :						List[Any]												=  floats_tensor([self.batch_size, self.seq_length, self.hidden_size]					)
							_UpperCamelCase   :						Dict												=  ids_tensor([self.batch_size, self.seq_length]					,vocab_size=2					)

							return (
							    config,
							    input_ids,
							    attention_mask,
							    encoder_hidden_states,
							    encoder_attention_mask,
							)






@require_flax
class 				lowercase__      (				lowercase		,   unittest.TestCase  ):
	lowercase__    							=     True

	lowercase__    							=     (
	    (
	        FlaxBertModel,
	        FlaxBertForPreTraining,
	        FlaxBertForMaskedLM,
	        FlaxBertForMultipleChoice,
	        FlaxBertForQuestionAnswering,
	        FlaxBertForNextSentencePrediction,
	        FlaxBertForSequenceClassification,
	        FlaxBertForTokenClassification,
	        FlaxBertForQuestionAnswering,
	    )
	    if is_flax_available()
	    else ()
	)





	def       UpperCamelCase_    (					self   :							Optional[Any]					):







							'''simple docstring'''
							_UpperCamelCase   :						Tuple												=  FlaxBertModelTester(self					)





	@slow
	def       UpperCamelCase_    (					self   :							Optional[int]					):







							'''simple docstring'''
							# Only check this for base model, not necessary for all model classes.
							# This will also help speed-up tests.
							_UpperCamelCase   :						List[str]												=  FlaxBertModel.from_pretrained('bert-base-cased'					)
							_UpperCamelCase   :						str												=  model(np.ones((1, 1)					)					)
							self.assertIsNotNone(lowerCamelCase__					)







'''simple docstring'''
from collections.abc import Iterator, MutableMapping
from dataclasses import dataclass
from typing import Generic, TypeVar

snake_case_					:      Optional[Any]    			=    TypeVar('KEY')
snake_case_					:      Dict    			=    TypeVar('VAL')






@dataclass(frozen=lowercase		,   slots=lowercase  )
class 				lowercase__      (				Generic[KEY, VAL]  ):
	lowercase__    							=     42
	lowercase__    							=     42






class 				lowercase__      (				_Item  ):





	def __init__(					self   :							Union[str, Any]					):







							'''simple docstring'''
							super().__init__(lowerCamelCase__					,lowerCamelCase__					)





	def __bool__(					self   :							Tuple					):







							'''simple docstring'''
							return False
snake_case_					:      int    			=    _DeletedItem()






class 				lowercase__      (				MutableMapping[KEY, VAL]  ):





	def __init__(					self   :							Any					,lowerCamelCase__   :							int = 8					,lowerCamelCase__   :							float = 0.7_5					):







							'''simple docstring'''
							_UpperCamelCase   :						Union[str, Any]												=  initial_block_size
							_UpperCamelCase   :						list[_Item | None]												=  [None] * initial_block_size
							assert 0.0 < capacity_factor < 1.0
							_UpperCamelCase   :						Optional[int]												=  capacity_factor
							_UpperCamelCase   :						List[Any]												=  0





	def       UpperCamelCase_    (					self   :							Optional[int]					,lowerCamelCase__   :							KEY					):







							'''simple docstring'''
							return hash(lowerCamelCase__					) % len(self._buckets					)





	def       UpperCamelCase_    (					self   :							List[Any]					,lowerCamelCase__   :							int					):







							'''simple docstring'''
							return (ind + 1) % len(self._buckets					)





	def       UpperCamelCase_    (					self   :							Union[str, Any]					,lowerCamelCase__   :							int					,lowerCamelCase__   :							KEY					,lowerCamelCase__   :							VAL					):







							'''simple docstring'''
							_UpperCamelCase   :						str												=  self._buckets[ind]
							if not stored:
													_UpperCamelCase   :						str												=  _Item(lowerCamelCase__					,lowerCamelCase__					)
													self._len += 1
													return True
							elif stored.key == key:
													_UpperCamelCase   :						Union[str, Any]												=  _Item(lowerCamelCase__					,lowerCamelCase__					)
													return True
							else:
													return False





	def       UpperCamelCase_    (					self   :							Optional[int]					):







							'''simple docstring'''
							_UpperCamelCase   :						Dict												=  len(self._buckets					) * self._capacity_factor
							return len(self					) >= int(lowerCamelCase__					)





	def       UpperCamelCase_    (					self   :							Dict					):







							'''simple docstring'''
							if len(self._buckets					) <= self._initial_block_size:
													return False
							_UpperCamelCase   :						str												=  len(self._buckets					) * self._capacity_factor / 2
							return len(self					) < limit





	def       UpperCamelCase_    (					self   :							int					,lowerCamelCase__   :							int					):







							'''simple docstring'''
							_UpperCamelCase   :						int												=  self._buckets
							_UpperCamelCase   :						Dict												=  [None] * new_size
							_UpperCamelCase   :						str												=  0
							for item in old_buckets:
													if item:
																			self._add_item(item.key					,item.val					)





	def       UpperCamelCase_    (					self   :							int					):







							'''simple docstring'''
							self._resize(len(self._buckets					) * 2					)





	def       UpperCamelCase_    (					self   :							List[str]					):







							'''simple docstring'''
							self._resize(len(self._buckets					) // 2					)





	def       UpperCamelCase_    (					self   :							Union[str, Any]					,lowerCamelCase__   :							KEY					):







							'''simple docstring'''
							_UpperCamelCase   :						List[str]												=  self._get_bucket_index(lowerCamelCase__					)
							for _ in range(len(self._buckets					)					):
													yield ind
													_UpperCamelCase   :						Optional[int]												=  self._get_next_ind(lowerCamelCase__					)





	def       UpperCamelCase_    (					self   :							str					,lowerCamelCase__   :							KEY					,lowerCamelCase__   :							VAL					):







							'''simple docstring'''
							for ind in self._iterate_buckets(lowerCamelCase__					):
													if self._try_set(lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					):
																			break





	def __setitem__(					self   :							Dict					,lowerCamelCase__   :							KEY					,lowerCamelCase__   :							VAL					):







							'''simple docstring'''
							if self._is_full():
													self._size_up()

							self._add_item(lowerCamelCase__					,lowerCamelCase__					)





	def __delitem__(					self   :							Optional[Any]					,lowerCamelCase__   :							KEY					):







							'''simple docstring'''
							for ind in self._iterate_buckets(lowerCamelCase__					):
													_UpperCamelCase   :						Any												=  self._buckets[ind]
													if item is None:
																			raise KeyError(lowerCamelCase__					)
													if item is _deleted:
																			continue
													if item.key == key:
																			_UpperCamelCase   :						Optional[Any]												=  _deleted
																			self._len -= 1
																			break
							if self._is_sparse():
													self._size_down()





	def __getitem__(					self   :							Dict					,lowerCamelCase__   :							KEY					):







							'''simple docstring'''
							for ind in self._iterate_buckets(lowerCamelCase__					):
													_UpperCamelCase   :						Any												=  self._buckets[ind]
													if item is None:
																			break
													if item is _deleted:
																			continue
													if item.key == key:
																			return item.val
							raise KeyError(lowerCamelCase__					)





	def __len__(					self   :							Dict					):







							'''simple docstring'''
							return self._len





	def __iter__(					self   :							List[str]					):







							'''simple docstring'''
							yield from (item.key for item in self._buckets if item)





	def __repr__(					self   :							Union[str, Any]					):







							'''simple docstring'''
							_UpperCamelCase   :						Tuple												=  ' ,'.join(
							    F'{item.key}: {item.val}' for item in self._buckets if item					)
							return F'HashMap({val_string})'


