






import unittest

import numpy as np

from transformers import DistilBertConfig, 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.distilbert.modeling_flax_distilbert import (
							    FlaxDistilBertForMaskedLM,
							    FlaxDistilBertForMultipleChoice,
							    FlaxDistilBertForQuestionAnswering,
							    FlaxDistilBertForSequenceClassification,
							    FlaxDistilBertForTokenClassification,
							    FlaxDistilBertModel,
							)


class   __SCREAMING_SNAKE_CASE(	unittest.TestCase	):
							def __init__(     self:      Tuple       ,	UpperCamelCase:      List[Any]       ,	UpperCamelCase:      List[str]=13       ,	UpperCamelCase:      List[str]=7       ,	UpperCamelCase:      Dict=True       ,	UpperCamelCase:      Dict=True       ,	UpperCamelCase:      int=True       ,	UpperCamelCase:      List[str]=True       ,	UpperCamelCase:      Union[str, Any]=99       ,	UpperCamelCase:      Tuple=32       ,	UpperCamelCase:      Any=5       ,	UpperCamelCase:      Optional[Any]=4       ,	UpperCamelCase:      List[str]=37       ,	UpperCamelCase:      str="gelu"       ,	UpperCamelCase:      Any=0.1       ,	UpperCamelCase:      Optional[int]=0.1       ,	UpperCamelCase:      Optional[int]=5_12       ,	UpperCamelCase:      str=16       ,	UpperCamelCase:      Optional[Any]=2       ,	UpperCamelCase:      List[str]=0.02       ,	UpperCamelCase:      List[Any]=4       ,	)		->		Tuple:
											snake_case__									=     parent
											snake_case__									=     batch_size
											snake_case__									=     seq_length
											snake_case__									=     is_training
											snake_case__									=     use_attention_mask
											snake_case__									=     use_token_type_ids
											snake_case__									=     use_labels
											snake_case__									=     vocab_size
											snake_case__									=     hidden_size
											snake_case__									=     num_hidden_layers
											snake_case__									=     num_attention_heads
											snake_case__									=     intermediate_size
											snake_case__									=     hidden_act
											snake_case__									=     hidden_dropout_prob
											snake_case__									=     attention_probs_dropout_prob
											snake_case__									=     max_position_embeddings
											snake_case__									=     type_vocab_size
											snake_case__									=     type_sequence_label_size
											snake_case__									=     initializer_range
											snake_case__									=     num_choices
							def lowerCAmelCase_ (     self:      int						)		->		Dict:
											snake_case__									=     ids_tensor([self.batch_size, self.seq_length]       ,	self.vocab_size						)

											snake_case__									=     None
											if self.use_attention_mask:
															snake_case__									=     random_attention_mask([self.batch_size, self.seq_length]						)

											snake_case__									=     DistilBertConfig(
											    vocab_size=self.vocab_size       ,	dim=self.hidden_size       ,	n_layers=self.num_hidden_layers       ,	n_heads=self.num_attention_heads       ,	hidden_dim=self.intermediate_size       ,	hidden_act=self.hidden_act       ,	dropout=self.hidden_dropout_prob       ,	attention_dropout=self.attention_probs_dropout_prob       ,	max_position_embeddings=self.max_position_embeddings       ,	initializer_range=self.initializer_range       ,	tie_weights_=UpperCamelCase       ,	)

											return config, input_ids, attention_mask


							def lowerCAmelCase_ (     self:      Any						)		->		Any:
											snake_case__									=     self.prepare_config_and_inputs()
											snake_case__							,						snake_case__							,						snake_case__									=     config_and_inputs
											snake_case__									=     {'input_ids': input_ids, 'attention_mask': attention_mask}
											return config, inputs_dict


@require_flax
class   __SCREAMING_SNAKE_CASE(	a_    ,  unittest.TestCase	):
							_UpperCAmelCase     =       (
							    (
							        FlaxDistilBertModel,
							        FlaxDistilBertForMaskedLM,
							        FlaxDistilBertForMultipleChoice,
							        FlaxDistilBertForQuestionAnswering,
							        FlaxDistilBertForSequenceClassification,
							        FlaxDistilBertForTokenClassification,
							        FlaxDistilBertForQuestionAnswering,
							    )
							    if is_flax_available()
							    else ()
							)
							def lowerCAmelCase_ (     self:      str						)		->		Any:
											snake_case__									=     FlaxDistilBertModelTester(self						)


							@slow
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		Dict:
											for model_class_name in self.all_model_classes:
															snake_case__									=     model_class_name.from_pretrained('distilbert-base-uncased'						)
															snake_case__									=     model(np.ones((1, 1)						)						)
															self.assertIsNotNone(UpperCamelCase						)


@require_flax
class   __SCREAMING_SNAKE_CASE(	unittest.TestCase	):
							@slow
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		List[Any]:
											snake_case__									=     FlaxDistilBertModel.from_pretrained('distilbert-base-uncased'						)
											snake_case__									=     np.array([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]						)
											snake_case__									=     np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
											snake_case__									=     model(UpperCamelCase       ,	attention_mask=UpperCamelCase						)[0]
											snake_case__									=     (1, 11, 7_68)
											self.assertEqual(output.shape       ,	UpperCamelCase						)
											snake_case__									=     np.array([[[-0.1_639, 0.3_299, 0.1_648], [-0.1_746, 0.3_289, 0.1_710], [-0.1_884, 0.3_357, 0.1_810]]]						)

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












from __future__ import annotations

from collections.abc import Iterator
from typing import Any


class   __SCREAMING_SNAKE_CASE:
							def __init__(     self:      int       ,	UpperCamelCase:      Any						)		->		List[Any]:
											snake_case__									=     data
											snake_case__									=     None


class   __SCREAMING_SNAKE_CASE:
							def __init__(     self:      Dict						)		->		Optional[Any]:
											snake_case__									=     None
											snake_case__									=     None
							def __iter__(     self:      Optional[int]						)		->		Iterator[Any]:
											snake_case__									=     self.head
											while self.head:
															yield node.data
															snake_case__									=     node.next
															if node == self.head:
																			break
							def __len__(     self:      int						)		->		int:
											return sum(1 for _ in self						)
							def __repr__(     self:      int						)		->		Optional[int]:
											return "->".join(str(UpperCamelCase						) for item in iter(self						)						)
							def lowerCAmelCase_ (     self:      Union[str, Any]       ,	UpperCamelCase:      Any						)		->		None:
											self.insert_nth(len(self						)       ,	UpperCamelCase						)
							def lowerCAmelCase_ (     self:      Tuple       ,	UpperCamelCase:      Any						)		->		None:
											self.insert_nth(0       ,	UpperCamelCase						)
							def lowerCAmelCase_ (     self:      int       ,	UpperCamelCase:      int       ,	UpperCamelCase:      Any						)		->		None:
											if index < 0 or index > len(self						):
															raise IndexError('list index out of range.'						)
											snake_case__									=     Node(UpperCamelCase						)
											if self.head is None:
															snake_case__									=     new_node  # first node points itself
															snake_case__									=     snake_case__									=     new_node
											elif index == 0:  # insert at head
															snake_case__									=     self.head
															snake_case__									=     snake_case__									=     new_node
											else:
															snake_case__									=     self.head
															for _ in range(index - 1						):
																			snake_case__									=     temp.next
															snake_case__									=     temp.next
															snake_case__									=     new_node
															if index == len(self						) - 1:  # insert at tail
																			snake_case__									=     new_node
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		Union[str, Any]:
											return self.delete_nth(0						)
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Any:
											return self.delete_nth(len(self						) - 1						)
							def lowerCAmelCase_ (     self:      str       ,	UpperCamelCase:      int = 0						)		->		Any:
											if not 0 <= index < len(self						):
															raise IndexError('list index out of range.'						)
											snake_case__									=     self.head
											if self.head == self.tail:  # just one node
															snake_case__									=     snake_case__									=     None
											elif index == 0:  # delete head node
															snake_case__									=     self.tail.next.next
															snake_case__									=     self.head.next
											else:
															snake_case__									=     self.head
															for _ in range(index - 1						):
																			snake_case__									=     temp.next
															snake_case__									=     temp.next
															snake_case__									=     temp.next.next
															if index == len(self						) - 1:  # delete at tail
																			snake_case__									=     temp
											return delete_node.data


							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		bool:
											return len(self						) == 0


def      a_ (      )			->			None:







				"""simple docstring"""
				snake_case__									=     CircularLinkedList()
				assert len(_A  ) == 0
				assert circular_linked_list.is_empty() is True
				assert str(_A  ) == ""

				try:
								circular_linked_list.delete_front()
								raise AssertionError  # This should not happen
				except IndexError:
								assert True  # This should happen

				try:
								circular_linked_list.delete_tail()
								raise AssertionError  # This should not happen
				except IndexError:
								assert True  # This should happen

				try:
								circular_linked_list.delete_nth(-1  )
								raise AssertionError
				except IndexError:
								assert True

				try:
								circular_linked_list.delete_nth(0  )
								raise AssertionError
				except IndexError:
								assert True

				assert circular_linked_list.is_empty() is True
				for i in range(5  ):
								assert len(_A  ) == i
								circular_linked_list.insert_nth(_A      ,   i + 1  )
				assert str(_A  ) == "->".join(str(_A  ) for i in range(1      ,   6  )  )

				circular_linked_list.insert_tail(6  )
				assert str(_A  ) == "->".join(str(_A  ) for i in range(1      ,   7  )  )
				circular_linked_list.insert_head(0  )
				assert str(_A  ) == "->".join(str(_A  ) for i in range(0      ,   7  )  )

				assert circular_linked_list.delete_front() == 0
				assert circular_linked_list.delete_tail() == 6
				assert str(_A  ) == "->".join(str(_A  ) for i in range(1      ,   6  )  )
				assert circular_linked_list.delete_nth(2  ) == 3

				circular_linked_list.insert_nth(2      ,   3  )
				assert str(_A  ) == "->".join(str(_A  ) for i in range(1      ,   6  )  )

				assert circular_linked_list.is_empty() is False


if __name__ == "__main__":
							import doctest

							doctest.testmod()




