



'''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):




		'''simple docstring'''



		def __init__(self	,__lowerCamelCase	,__lowerCamelCase=3	,__lowerCamelCase=32	,__lowerCamelCase=3	,__lowerCamelCase=10	,__lowerCamelCase=[10, 20, 30, 40]	,__lowerCamelCase=[1, 1, 2, 1]	,__lowerCamelCase=True	,__lowerCamelCase=True	,__lowerCamelCase="relu"	,__lowerCamelCase=3	,__lowerCamelCase=None	,)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       Optional[Any]				=  parent
						lowerCAmelCase__  :       str				=  batch_size
						lowerCAmelCase__  :       Optional[int]				=  image_size
						lowerCAmelCase__  :       Optional[Any]				=  num_channels
						lowerCAmelCase__  :       int				=  embeddings_size
						lowerCAmelCase__  :       List[str]				=  hidden_sizes
						lowerCAmelCase__  :       Any				=  depths
						lowerCAmelCase__  :       List[str]				=  is_training
						lowerCAmelCase__  :       Optional[Any]				=  use_labels
						lowerCAmelCase__  :       List[str]				=  hidden_act
						lowerCAmelCase__  :       Dict				=  num_labels
						lowerCAmelCase__  :       Optional[Any]				=  scope
						lowerCAmelCase__  :       Union[str, Any]				=  len(__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    List[str]:

						"""simple docstring"""






						lowerCAmelCase__  :       int				=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

						lowerCAmelCase__  :       List[Any]				=  self.get_config()

						return config, pixel_values



		def 	lowerCAmelCase__   (self				)  ->    Any:

						"""simple docstring"""






						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	,__lowerCamelCase	,__lowerCamelCase				)  ->    Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       Dict				=  FlaxRegNetModel(config=__lowerCamelCase				)
						lowerCAmelCase__  :       str				=  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 // 32, self.image_size // 32)	,)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase				)  ->    Optional[int]:

						"""simple docstring"""






						lowerCAmelCase__  :       str				=  self.num_labels
						lowerCAmelCase__  :       str				=  FlaxRegNetForImageClassification(config=__lowerCamelCase				)
						lowerCAmelCase__  :       Optional[Any]				=  model(__lowerCamelCase				)
						self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.num_labels)				)



		def 	lowerCAmelCase__   (self				)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       Optional[int]				=  self.prepare_config_and_inputs()
						lowerCAmelCase__  :       Dict				=  config_and_inputs
						lowerCAmelCase__  :       List[Any]				=  {'''pixel_values''': pixel_values}
						return config, inputs_dict



@require_flax
class  lowerCamelCase__    (							lowerCamelCase__   ,       unittest.TestCase):




		'''simple docstring'''



		snake_case_			=(FlaxRegNetModel, FlaxRegNetForImageClassification) if is_flax_available() else ()

		snake_case_			=False
		snake_case_			=False
		snake_case_			=False



		def 	lowerCAmelCase__   (self				)  ->    None:

						"""simple docstring"""






						lowerCAmelCase__  :       List[str]				=  FlaxRegNetModelTester(self				)
						lowerCAmelCase__  :       Tuple				=  ConfigTester(self	,config_class=__lowerCamelCase	,has_text_modality=__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    str:

						"""simple docstring"""






						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				)  ->    Tuple:

						"""simple docstring"""






						return



		def 	lowerCAmelCase__   (self				)  ->    List[Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       int				=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    Any:

						"""simple docstring"""






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

						"""simple docstring"""






						pass



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

						"""simple docstring"""






						pass



		def 	lowerCAmelCase__   (self				)  ->    List[Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       List[Any]				=  self.model_tester.prepare_config_and_inputs_for_common()

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

										lowerCAmelCase__  :       Optional[Any]				=  ['''pixel_values''']
										self.assertListEqual(arg_names[:1]	,__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    Union[str, Any]:

						"""simple docstring"""






						def check_hidden_states_output(__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				):
										lowerCAmelCase__  :       Optional[int]				=  model_class(__lowerCamelCase				)

										lowerCAmelCase__  :       Any				=  model(**self._prepare_for_class(__lowerCamelCase	,__lowerCamelCase				)				)

										lowerCAmelCase__  :       Tuple				=  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

										lowerCAmelCase__  :       int				=  self.model_tester.num_stages
										self.assertEqual(len(__lowerCamelCase				)	,expected_num_stages + 1				)

						lowerCAmelCase__  :       str				=  self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										lowerCAmelCase__  :       int				=  True
										check_hidden_states_output(__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)

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

										check_hidden_states_output(__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)



		def 	lowerCAmelCase__   (self				)  ->    Optional[Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       str				=  self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										with self.subTest(model_class.__name__				):
														lowerCAmelCase__  :       Optional[Any]				=  self._prepare_for_class(__lowerCamelCase	,__lowerCamelCase				)
														lowerCAmelCase__  :       str				=  model_class(__lowerCamelCase				)

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

														with self.subTest('''JIT Enabled'''				):
																		lowerCAmelCase__  :       str				=  model_jitted(**__lowerCamelCase				).to_tuple()

														with self.subTest('''JIT Disabled'''				):
																		with jax.disable_jit():
																						lowerCAmelCase__  :       Dict				=  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 			lowerCAmelCase__	(					):





				'''simple docstring'''

				lowerCAmelCase__  :       Optional[int]				=  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''')
				return image



@require_flax
class  lowerCamelCase__    (							unittest.TestCase):




		'''simple docstring'''



		@cached_property
		def 	lowerCAmelCase__   (self				)  ->    Optional[int]:

						"""simple docstring"""






						return AutoImageProcessor.from_pretrained('''facebook/regnet-y-040'''				) if is_vision_available() else None



		@slow
		def 	lowerCAmelCase__   (self				)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       Union[str, Any]				=  FlaxRegNetForImageClassification.from_pretrained('''facebook/regnet-y-040'''				)

						lowerCAmelCase__  :       List[Any]				=  self.default_image_processor
						lowerCAmelCase__  :       List[Any]				=  prepare_img()
						lowerCAmelCase__  :       Dict				=  image_processor(images=__lowerCamelCase	,return_tensors='''np'''				)

						lowerCAmelCase__  :       int				=  model(**__lowerCamelCase				)

						# verify the logits
						lowerCAmelCase__  :       int				=  (1, 10_00)
						self.assertEqual(outputs.logits.shape	,__lowerCamelCase				)

						lowerCAmelCase__  :       Union[str, Any]				=  jnp.array([-0.4180, -1.5051, -3.4836]				)

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






from __future__ import annotations






def 			lowerCAmelCase__	(					lowerCamelCase_	:	int):





				'''simple docstring'''

				lowerCAmelCase__  :       Optional[int]				=  str(lowerCamelCase_)
				return len(lowerCamelCase_) == 9 and set(lowerCamelCase_) == set('''123456789''')






def 			lowerCAmelCase__	(					):





				'''simple docstring'''

				for base_num in range(9999 ,4999 ,-1):
								lowerCAmelCase__  :       Union[str, Any]				=  100002 * base_num
								if is_9_pandigital(lowerCamelCase_):
												return candidate

				for base_num in range(333 ,99 ,-1):
								lowerCAmelCase__  :       Any				=  1002003 * base_num
								if is_9_pandigital(lowerCamelCase_):
												return candidate

				return None


if __name__ == "__main__":
							print(f"""{solution() = }""")

