






"""simple docstring"""
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 _lowerCAmelCase						(    unittest.TestCase       ):







						def __init__(    self   ,				lowerCAmelCase_   ,				lowerCAmelCase_=3   ,				lowerCAmelCase_=3_2   ,				lowerCAmelCase_=3   ,				lowerCAmelCase_=1_0   ,				lowerCAmelCase_=[1_0, 2_0, 3_0, 4_0]   ,				lowerCAmelCase_=[1, 1, 2, 1]   ,				lowerCAmelCase_=True   ,				lowerCAmelCase_=True   ,				lowerCAmelCase_="relu"   ,				lowerCAmelCase_=3   ,				lowerCAmelCase_=None   ,				)		->							str:
										_SCREAMING_SNAKE_CASE   :		List[str]       		=    parent
										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    batch_size
										_SCREAMING_SNAKE_CASE   :		List[str]       		=    image_size
										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    num_channels
										_SCREAMING_SNAKE_CASE   :		str       		=    embeddings_size
										_SCREAMING_SNAKE_CASE   :		Any       		=    hidden_sizes
										_SCREAMING_SNAKE_CASE   :		Any       		=    depths
										_SCREAMING_SNAKE_CASE   :		int       		=    is_training
										_SCREAMING_SNAKE_CASE   :		List[str]       		=    use_labels
										_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    hidden_act
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    num_labels
										_SCREAMING_SNAKE_CASE   :		int       		=    scope
										_SCREAMING_SNAKE_CASE   :		int       		=    len(lowerCAmelCase_							)







						def 			A      (    self							)		->							Optional[Any]:
										_SCREAMING_SNAKE_CASE   :		Dict       		=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    self.get_config()

										return config, pixel_values







						def 			A      (    self							)		->							int:
										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 			A      (    self   ,				lowerCAmelCase_   ,				lowerCAmelCase_							)		->							Union[str, Any]:
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    FlaxRegNetModel(config=lowerCAmelCase_							)
										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    model(lowerCAmelCase_							)

										# Output shape (b, c, h, w)
										self.parent.assertEqual(
										    result.last_hidden_state.shape   ,				(self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)   ,				)







						def 			A      (    self   ,				lowerCAmelCase_   ,				lowerCAmelCase_							)		->							List[Any]:
										_SCREAMING_SNAKE_CASE   :		int       		=    self.num_labels
										_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    FlaxRegNetForImageClassification(config=lowerCAmelCase_							)
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    model(lowerCAmelCase_							)
										self.parent.assertEqual(result.logits.shape   ,				(self.batch_size, self.num_labels)							)







						def 			A      (    self							)		->							Dict:
										_SCREAMING_SNAKE_CASE   :		Tuple       		=    self.prepare_config_and_inputs()
										_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE   :		Tuple       		=    config_and_inputs
										_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    {'pixel_values': pixel_values}
										return config, inputs_dict







@require_flax
class _lowerCAmelCase						(    __UpperCAmelCase   ,  unittest.TestCase       ):
						SCREAMING_SNAKE_CASE_:					int 					=				(FlaxRegNetModel, FlaxRegNetForImageClassification) if is_flax_available() else ()

						SCREAMING_SNAKE_CASE_:					Union[str, Any] 					=				False
						SCREAMING_SNAKE_CASE_:					List[str] 					=				False
						SCREAMING_SNAKE_CASE_:					int 					=				False







						def 			A      (    self							)		->							None:
										_SCREAMING_SNAKE_CASE   :		str       		=    FlaxRegNetModelTester(self							)
										_SCREAMING_SNAKE_CASE   :		Any       		=    ConfigTester(self   ,				config_class=lowerCAmelCase_   ,				has_text_modality=lowerCAmelCase_							)







						def 			A      (    self							)		->							str:
										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 			A      (    self							)		->							Tuple:
										return







						def 			A      (    self							)		->							Optional[Any]:
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCAmelCase_							)







						def 			A      (    self							)		->							List[Any]:
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase_							)







						@unittest.skip(reason='RegNet does not use inputs_embeds'							)
						def 			A      (    self							)		->							int:
										pass







						@unittest.skip(reason='RegNet does not support input and output embeddings'							)
						def 			A      (    self							)		->							str:
										pass







						def 			A      (    self							)		->							List[str]:
										_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE   :		int       		=    self.model_tester.prepare_config_and_inputs_for_common()

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

														_SCREAMING_SNAKE_CASE   :		Dict       		=    ['pixel_values']
														self.assertListEqual(arg_names[:1]   ,				lowerCAmelCase_							)







						def 			A      (    self							)		->							Union[str, Any]:
										def check_hidden_states_output(lowerCAmelCase_   ,				lowerCAmelCase_   ,				lowerCAmelCase_							):
														_SCREAMING_SNAKE_CASE   :		Dict       		=    model_class(lowerCAmelCase_							)

														_SCREAMING_SNAKE_CASE   :		List[str]       		=    model(**self._prepare_for_class(lowerCAmelCase_   ,				lowerCAmelCase_							)							)

														_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

														_SCREAMING_SNAKE_CASE   :		Dict       		=    self.model_tester.num_stages
														self.assertEqual(len(lowerCAmelCase_							)   ,				expected_num_stages + 1							)

										_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
														_SCREAMING_SNAKE_CASE   :		str       		=    True
														check_hidden_states_output(lowerCAmelCase_   ,				lowerCAmelCase_   ,				lowerCAmelCase_							)

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    True

														check_hidden_states_output(lowerCAmelCase_   ,				lowerCAmelCase_   ,				lowerCAmelCase_							)







						def 			A      (    self							)		->							List[str]:
										_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE   :		Dict       		=    self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
														with self.subTest(model_class.__name__							):
																		_SCREAMING_SNAKE_CASE   :		List[str]       		=    self._prepare_for_class(lowerCAmelCase_   ,				lowerCAmelCase_							)
																		_SCREAMING_SNAKE_CASE   :		List[str]       		=    model_class(lowerCAmelCase_							)

																		@jax.jit
																		def model_jitted(lowerCAmelCase_   ,				**lowerCAmelCase_							):
																						return model(pixel_values=lowerCAmelCase_   ,				**lowerCAmelCase_							)

																		with self.subTest('JIT Enabled'							):
																						_SCREAMING_SNAKE_CASE   :		int       		=    model_jitted(**lowerCAmelCase_							).to_tuple()

																		with self.subTest('JIT Disabled'							):
																						with jax.disable_jit():
																										_SCREAMING_SNAKE_CASE   :		Tuple       		=    model_jitted(**lowerCAmelCase_							).to_tuple()

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







def 				lowercase__		(					):
				_SCREAMING_SNAKE_CASE   :		Any       		=    Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'       )
				return image






@require_flax
class _lowerCAmelCase						(    unittest.TestCase       ):







						@cached_property
						def 			A      (    self							)		->							Optional[Any]:
										return AutoImageProcessor.from_pretrained('facebook/regnet-y-040'							) if is_vision_available() else None







						@slow
						def 			A      (    self							)		->							Union[str, Any]:
										_SCREAMING_SNAKE_CASE   :		str       		=    FlaxRegNetForImageClassification.from_pretrained('facebook/regnet-y-040'							)

										_SCREAMING_SNAKE_CASE   :		int       		=    self.default_image_processor
										_SCREAMING_SNAKE_CASE   :		str       		=    prepare_img()
										_SCREAMING_SNAKE_CASE   :		Dict       		=    image_processor(images=lowerCAmelCase_   ,				return_tensors='np'							)

										_SCREAMING_SNAKE_CASE   :		int       		=    model(**lowerCAmelCase_							)

										# verify the logits
										_SCREAMING_SNAKE_CASE   :		Any       		=    (1, 1_0_0_0)
										self.assertEqual(outputs.logits.shape   ,				lowerCAmelCase_							)

										_SCREAMING_SNAKE_CASE   :		List[str]       		=    jnp.array([-0.4_180, -1.5_051, -3.4_836]							)

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









"""simple docstring"""
class _lowerCAmelCase						:







						def __init__(    self   ,				lowerCAmelCase_   ,				lowerCAmelCase_=None   ,				lowerCAmelCase_=None							)		->							int:
										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    data
										_SCREAMING_SNAKE_CASE   :		Tuple       		=    previous
										_SCREAMING_SNAKE_CASE   :		Any       		=    next_node







						def __str__(    self							)		->							str:
										return F"""{self.data}"""







						def 			A      (    self							)		->							int:
										return self.data







						def 			A      (    self							)		->							Dict:
										return self.next







						def 			A      (    self							)		->							Union[str, Any]:
										return self.previous







class _lowerCAmelCase						:







						def __init__(    self   ,				lowerCAmelCase_							)		->							List[str]:
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    head







						def __iter__(    self							)		->							Any:
										return self







						def 			A      (    self							)		->							Dict:
										if not self.current:
														raise StopIteration
										else:
														_SCREAMING_SNAKE_CASE   :		Any       		=    self.current.get_data()
														_SCREAMING_SNAKE_CASE   :		Dict       		=    self.current.get_next()
														return value







class _lowerCAmelCase						:







						def __init__(    self							)		->							Dict:
										_SCREAMING_SNAKE_CASE   :		Dict       		=    None  # First node in list
										_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    None  # Last node in list







						def __str__(    self							)		->							Any:
										_SCREAMING_SNAKE_CASE   :		str       		=    self.head
										_SCREAMING_SNAKE_CASE   :		int       		=    []
										while current is not None:
														nodes.append(current.get_data()							)
														_SCREAMING_SNAKE_CASE   :		List[Any]       		=    current.get_next()
										return " ".join(str(lowerCAmelCase_							) for node in nodes							)







						def __contains__(    self   ,				lowerCAmelCase_							)		->							Any:
										_SCREAMING_SNAKE_CASE   :		Any       		=    self.head
										while current:
														if current.get_data() == value:
																		return True
														_SCREAMING_SNAKE_CASE   :		int       		=    current.get_next()
										return False







						def __iter__(    self							)		->							str:
										return LinkedListIterator(self.head							)







						def 			A      (    self							)		->							Dict:
										if self.head:
														return self.head.get_data()
										return None







						def 			A      (    self							)		->							List[Any]:
										if self.tail:
														return self.tail.get_data()
										return None







						def 			A      (    self   ,				lowerCAmelCase_							)		->							None:
										if self.head is None:
														_SCREAMING_SNAKE_CASE   :		List[Any]       		=    node
														_SCREAMING_SNAKE_CASE   :		Dict       		=    node
										else:
														self.insert_before_node(self.head   ,				lowerCAmelCase_							)







						def 			A      (    self   ,				lowerCAmelCase_							)		->							None:
										if self.head is None:
														self.set_head(lowerCAmelCase_							)
										else:
														self.insert_after_node(self.tail   ,				lowerCAmelCase_							)







						def 			A      (    self   ,				lowerCAmelCase_							)		->							None:
										_SCREAMING_SNAKE_CASE   :		Any       		=    Node(lowerCAmelCase_							)
										if self.head is None:
														self.set_head(lowerCAmelCase_							)
										else:
														self.set_tail(lowerCAmelCase_							)







						def 			A      (    self   ,				lowerCAmelCase_   ,				lowerCAmelCase_							)		->							None:
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    node
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    node.previous

										if node.get_previous() is None:
														_SCREAMING_SNAKE_CASE   :		List[Any]       		=    node_to_insert
										else:
														_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    node_to_insert

										_SCREAMING_SNAKE_CASE   :		Any       		=    node_to_insert







						def 			A      (    self   ,				lowerCAmelCase_   ,				lowerCAmelCase_							)		->							None:
										_SCREAMING_SNAKE_CASE   :		Optional[Any]       		=    node
										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    node.next

										if node.get_next() is None:
														_SCREAMING_SNAKE_CASE   :		Tuple       		=    node_to_insert
										else:
														_SCREAMING_SNAKE_CASE   :		Any       		=    node_to_insert

										_SCREAMING_SNAKE_CASE   :		List[str]       		=    node_to_insert







						def 			A      (    self   ,				lowerCAmelCase_   ,				lowerCAmelCase_							)		->							None:
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    1
										_SCREAMING_SNAKE_CASE   :		str       		=    Node(lowerCAmelCase_							)
										_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    self.head
										while node:
														if current_position == position:
																		self.insert_before_node(lowerCAmelCase_   ,				lowerCAmelCase_							)
																		return
														current_position += 1
														_SCREAMING_SNAKE_CASE   :		List[str]       		=    node.next
										self.insert_after_node(self.tail   ,				lowerCAmelCase_							)







						def 			A      (    self   ,				lowerCAmelCase_							)		->							Node:
										_SCREAMING_SNAKE_CASE   :		Tuple       		=    self.head
										while node:
														if node.get_data() == item:
																		return node
														_SCREAMING_SNAKE_CASE   :		Dict       		=    node.get_next()
										raise Exception('Node not found'							)







						def 			A      (    self   ,				lowerCAmelCase_							)		->							int:
										if (node := self.get_node(lowerCAmelCase_							)) is not None:
														if node == self.head:
																		_SCREAMING_SNAKE_CASE   :		Union[str, Any]       		=    self.head.get_next()

														if node == self.tail:
																		_SCREAMING_SNAKE_CASE   :		int       		=    self.tail.get_previous()

														self.remove_node_pointers(lowerCAmelCase_							)







						@staticmethod
						def 			A      (    lowerCAmelCase_							)		->							None:
										if node.get_next():
														_SCREAMING_SNAKE_CASE   :		List[Any]       		=    node.previous

										if node.get_previous():
														_SCREAMING_SNAKE_CASE   :		str       		=    node.next

										_SCREAMING_SNAKE_CASE   :		Optional[int]       		=    None
										_SCREAMING_SNAKE_CASE   :		List[Any]       		=    None







						def 			A      (    self							)		->							List[str]:
										return self.head is None







def 				lowercase__		(					):
				pass


if __name__ == "__main__":
			import doctest

			doctest.testmod()

