






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()












import inspect
import unittest

from transformers import RegNetConfig, is_flax_available
from transformers.testing_utils import require_flax, slow
from transformers.utils import cached_property, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
							import jax
							import jax.numpy as jnp

							from transformers.models.regnet.modeling_flax_regnet import FlaxRegNetForImageClassification, FlaxRegNetModel

if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor


class   __SCREAMING_SNAKE_CASE(	unittest.TestCase	):
							def __init__(     self:      List[str]       ,	UpperCamelCase:      Dict       ,	UpperCamelCase:      Optional[int]=3       ,	UpperCamelCase:      Union[str, Any]=32       ,	UpperCamelCase:      Optional[int]=3       ,	UpperCamelCase:      Any=10       ,	UpperCamelCase:      List[str]=[10, 20, 30, 40]       ,	UpperCamelCase:      Optional[Any]=[1, 1, 2, 1]       ,	UpperCamelCase:      Tuple=True       ,	UpperCamelCase:      List[str]=True       ,	UpperCamelCase:      Optional[int]="relu"       ,	UpperCamelCase:      List[str]=3       ,	UpperCamelCase:      Dict=None       ,	)		->		Optional[Any]:
											snake_case__									=     parent
											snake_case__									=     batch_size
											snake_case__									=     image_size
											snake_case__									=     num_channels
											snake_case__									=     embeddings_size
											snake_case__									=     hidden_sizes
											snake_case__									=     depths
											snake_case__									=     is_training
											snake_case__									=     use_labels
											snake_case__									=     hidden_act
											snake_case__									=     num_labels
											snake_case__									=     scope
											snake_case__									=     len(UpperCamelCase						)
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Dict:
											snake_case__									=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

											snake_case__									=     self.get_config()

											return config, pixel_values
							def lowerCAmelCase_ (     self:      int						)		->		Optional[Any]:
											return RegNetConfig(
											    num_channels=self.num_channels       ,	embeddings_size=self.embeddings_size       ,	hidden_sizes=self.hidden_sizes       ,	depths=self.depths       ,	hidden_act=self.hidden_act       ,	num_labels=self.num_labels       ,	image_size=self.image_size       ,	)
							def lowerCAmelCase_ (     self:      Optional[Any]       ,	UpperCamelCase:      List[Any]       ,	UpperCamelCase:      List[Any]						)		->		Optional[Any]:
											snake_case__									=     FlaxRegNetModel(config=UpperCamelCase						)
											snake_case__									=     model(UpperCamelCase						)

											# Output shape (b, c, h, w)
											self.parent.assertEqual(
											    result.last_hidden_state.shape       ,	(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)       ,	)
							def lowerCAmelCase_ (     self:      List[str]       ,	UpperCamelCase:      Tuple       ,	UpperCamelCase:      Optional[Any]						)		->		List[str]:
											snake_case__									=     self.num_labels
											snake_case__									=     FlaxRegNetForImageClassification(config=UpperCamelCase						)
											snake_case__									=     model(UpperCamelCase						)
											self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.num_labels)						)


							def lowerCAmelCase_ (     self:      Tuple						)		->		List[str]:
											snake_case__									=     self.prepare_config_and_inputs()
											snake_case__							,						snake_case__									=     config_and_inputs
											snake_case__									=     {'pixel_values': pixel_values}
											return config, inputs_dict


@require_flax
class   __SCREAMING_SNAKE_CASE(	a_    ,  unittest.TestCase	):
							_UpperCAmelCase     =       (FlaxRegNetModel, FlaxRegNetForImageClassification) if is_flax_available() else ()

							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       False
							def lowerCAmelCase_ (     self:      Dict						)		->		None:
											snake_case__									=     FlaxRegNetModelTester(self						)
											snake_case__									=     ConfigTester(self       ,	config_class=UpperCamelCase       ,	has_text_modality=UpperCamelCase						)
							def lowerCAmelCase_ (     self:      str						)		->		Optional[int]:
											self.create_and_test_config_common_properties()
											self.config_tester.create_and_test_config_to_json_string()
											self.config_tester.create_and_test_config_to_json_file()
											self.config_tester.create_and_test_config_from_and_save_pretrained()
											self.config_tester.create_and_test_config_with_num_labels()
											self.config_tester.check_config_can_be_init_without_params()
											self.config_tester.check_config_arguments_init()
							def lowerCAmelCase_ (     self:      List[Any]						)		->		List[str]:
											return
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		Union[str, Any]:
											snake_case__									=     self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*UpperCamelCase						)
							def lowerCAmelCase_ (     self:      Tuple						)		->		List[Any]:
											snake_case__									=     self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_image_classification(*UpperCamelCase						)
							@unittest.skip(reason='RegNet does not use inputs_embeds'						)
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		Dict:
											pass
							@unittest.skip(reason='RegNet does not support input and output embeddings'						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		Dict:
											pass
							def lowerCAmelCase_ (     self:      Tuple						)		->		int:
											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
															snake_case__									=     model_class(UpperCamelCase						)
															snake_case__									=     inspect.signature(model.__call__						)
															# signature.parameters is an OrderedDict => so arg_names order is deterministic
															snake_case__									=     [*signature.parameters.keys()]

															snake_case__									=     ['pixel_values']
															self.assertListEqual(arg_names[:1]       ,	UpperCamelCase						)
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		int:
											def check_hidden_states_output(UpperCamelCase:      Optional[int]       ,	UpperCamelCase:      Optional[Any]       ,	UpperCamelCase:      List[Any]						):
															snake_case__									=     model_class(UpperCamelCase						)

															snake_case__									=     model(**self._prepare_for_class(UpperCamelCase       ,	UpperCamelCase						)						)

															snake_case__									=     outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

															snake_case__									=     self.model_tester.num_stages
															self.assertEqual(len(UpperCamelCase						)       ,	expected_num_stages + 1						)

											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
															snake_case__									=     True
															check_hidden_states_output(UpperCamelCase       ,	UpperCamelCase       ,	UpperCamelCase						)

															# check that output_hidden_states also work using config
															del inputs_dict["output_hidden_states"]
															snake_case__									=     True

															check_hidden_states_output(UpperCamelCase       ,	UpperCamelCase       ,	UpperCamelCase						)


							def lowerCAmelCase_ (     self:      str						)		->		str:
											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
															with self.subTest(model_class.__name__						):
																			snake_case__									=     self._prepare_for_class(UpperCamelCase       ,	UpperCamelCase						)
																			snake_case__									=     model_class(UpperCamelCase						)

																			@jax.jit
																			def model_jitted(UpperCamelCase:      str       ,	**UpperCamelCase:      Tuple						):
																							return model(pixel_values=UpperCamelCase       ,	**UpperCamelCase						)

																			with self.subTest('JIT Enabled'						):
																							snake_case__									=     model_jitted(**UpperCamelCase						).to_tuple()

																			with self.subTest('JIT Disabled'						):
																							with jax.disable_jit():
																											snake_case__									=     model_jitted(**UpperCamelCase						).to_tuple()

																			self.assertEqual(len(UpperCamelCase						)       ,	len(UpperCamelCase						)						)
																			for jitted_output, output in zip(UpperCamelCase       ,	UpperCamelCase						):
																							self.assertEqual(jitted_output.shape       ,	output.shape						)


def      a_ (      )			->			Optional[int]:







				"""simple docstring"""
				snake_case__									=     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'  )
				return image


@require_flax
class   __SCREAMING_SNAKE_CASE(	unittest.TestCase	):
							@cached_property
							def lowerCAmelCase_ (     self:      str						)		->		Any:
											return AutoImageProcessor.from_pretrained('facebook/regnet-y-040'						) if is_vision_available() else None


							@slow
							def lowerCAmelCase_ (     self:      List[str]						)		->		Optional[Any]:
											snake_case__									=     FlaxRegNetForImageClassification.from_pretrained('facebook/regnet-y-040'						)

											snake_case__									=     self.default_image_processor
											snake_case__									=     prepare_img()
											snake_case__									=     image_processor(images=UpperCamelCase       ,	return_tensors='np'						)

											snake_case__									=     model(**UpperCamelCase						)

											# verify the logits
											snake_case__									=     (1, 10_00)
											self.assertEqual(outputs.logits.shape       ,	UpperCamelCase						)

											snake_case__									=     jnp.array([-0.4_180, -1.5_051, -3.4_836]						)

											self.assertTrue(jnp.allclose(outputs.logits[0, :3]       ,	UpperCamelCase       ,	atol=1e-4						)						)




