


import inspect
import unittest

from transformers import ResNetConfig, 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.resnet.modeling_flax_resnet import FlaxResNetForImageClassification, FlaxResNetModel

if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor



class    __lowercase  (       unittest.TestCase							):

							"""simple docstring"""


							def __init__(    self				, A_				, A_=3				, A_=32				, A_=3				, A_=10				, A_=[10, 20, 30, 40]				, A_=[1, 1, 2, 1]				, A_=True				, A_=True				, A_="relu"				, A_=3				, A_=None				, )->	str:
											_SCREAMING_SNAKE_CASE      = parent
											_SCREAMING_SNAKE_CASE      = batch_size
											_SCREAMING_SNAKE_CASE      = image_size
											_SCREAMING_SNAKE_CASE      = num_channels
											_SCREAMING_SNAKE_CASE      = embeddings_size
											_SCREAMING_SNAKE_CASE      = hidden_sizes
											_SCREAMING_SNAKE_CASE      = depths
											_SCREAMING_SNAKE_CASE      = is_training
											_SCREAMING_SNAKE_CASE      = use_labels
											_SCREAMING_SNAKE_CASE      = hidden_act
											_SCREAMING_SNAKE_CASE      = num_labels
											_SCREAMING_SNAKE_CASE      = scope
											_SCREAMING_SNAKE_CASE      = len(A_	)





							def 		__magic_name__			(    self	)->	Optional[int]:
											_SCREAMING_SNAKE_CASE      = floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

											_SCREAMING_SNAKE_CASE      = self.get_config()

											return config, pixel_values





							def 		__magic_name__			(    self	)->	Dict:
											return ResNetConfig(
											    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 		__magic_name__			(    self				, A_				, A_	)->	Union[str, Any]:
											_SCREAMING_SNAKE_CASE      = FlaxResNetModel(config=A_	)
											_SCREAMING_SNAKE_CASE      = model(A_	)

											# 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 		__magic_name__			(    self				, A_				, A_	)->	Any:
											_SCREAMING_SNAKE_CASE      = self.num_labels
											_SCREAMING_SNAKE_CASE      = FlaxResNetForImageClassification(config=A_	)
											_SCREAMING_SNAKE_CASE      = model(A_	)
											self.parent.assertEqual(result.logits.shape				, (self.batch_size, self.num_labels)	)





							def 		__magic_name__			(    self	)->	str:
											_SCREAMING_SNAKE_CASE      = self.prepare_config_and_inputs()
											_SCREAMING_SNAKE_CASE      ,      _SCREAMING_SNAKE_CASE      = config_and_inputs
											_SCREAMING_SNAKE_CASE      = {'pixel_values': pixel_values}
											return config, inputs_dict







@require_flax
class    __lowercase  (       UpperCamelCase      ,     unittest.TestCase							):

							"""simple docstring"""


							SCREAMING_SNAKE_CASE   :					Optional[int]        =						(FlaxResNetModel, FlaxResNetForImageClassification) if is_flax_available() else ()

							SCREAMING_SNAKE_CASE   :					List[Any]        =						False
							SCREAMING_SNAKE_CASE   :					Tuple        =						False
							SCREAMING_SNAKE_CASE   :					Optional[Any]        =						False





							def 		__magic_name__			(    self	)->	None:
											_SCREAMING_SNAKE_CASE      = FlaxResNetModelTester(self	)
											_SCREAMING_SNAKE_CASE      = ConfigTester(self				, config_class=A_				, has_text_modality=A_	)





							def 		__magic_name__			(    self	)->	List[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 		__magic_name__			(    self	)->	Optional[Any]:
											return





							def 		__magic_name__			(    self	)->	List[str]:
											_SCREAMING_SNAKE_CASE      = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*A_	)





							def 		__magic_name__			(    self	)->	Tuple:
											_SCREAMING_SNAKE_CASE      = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_image_classification(*A_	)





							@unittest.skip(reason='ResNet does not use inputs_embeds'	)
							def 		__magic_name__			(    self	)->	Tuple:
											pass





							@unittest.skip(reason='ResNet does not support input and output embeddings'	)
							def 		__magic_name__			(    self	)->	Dict:
											pass





							def 		__magic_name__			(    self	)->	int:
											_SCREAMING_SNAKE_CASE      ,      _SCREAMING_SNAKE_CASE      = self.model_tester.prepare_config_and_inputs_for_common()

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

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





							def 		__magic_name__			(    self	)->	str:
											def check_hidden_states_output(A_				, A_				, A_	):
															_SCREAMING_SNAKE_CASE      = model_class(A_	)

															_SCREAMING_SNAKE_CASE      = model(**self._prepare_for_class(A_				, A_	)	)

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

															_SCREAMING_SNAKE_CASE      = self.model_tester.num_stages
															self.assertEqual(len(A_	)				, expected_num_stages + 1	)





							@unittest.skip(reason='ResNet does not use feedforward chunking'	)
							def 		__magic_name__			(    self	)->	Tuple:
											pass





							def 		__magic_name__			(    self	)->	int:
											_SCREAMING_SNAKE_CASE      ,      _SCREAMING_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__	):
																			_SCREAMING_SNAKE_CASE      = self._prepare_for_class(A_				, A_	)
																			_SCREAMING_SNAKE_CASE      = model_class(A_	)

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

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

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

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







def 				SCREAMING_SNAKE_CASE (     ):

				"""simple docstring"""






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



@require_flax
class    __lowercase  (       unittest.TestCase							):

							"""simple docstring"""


							@cached_property
							def 		__magic_name__			(    self	)->	Any:
											return AutoImageProcessor.from_pretrained('microsoft/resnet-50'	) if is_vision_available() else None





							@slow
							def 		__magic_name__			(    self	)->	Optional[Any]:
											_SCREAMING_SNAKE_CASE      = FlaxResNetForImageClassification.from_pretrained('microsoft/resnet-50'	)

											_SCREAMING_SNAKE_CASE      = self.default_image_processor
											_SCREAMING_SNAKE_CASE      = prepare_img()
											_SCREAMING_SNAKE_CASE      = image_processor(images=A_				, return_tensors='np'	)

											_SCREAMING_SNAKE_CASE      = model(**A_	)

											# verify the logits
											_SCREAMING_SNAKE_CASE      = (1, 1000)
											self.assertEqual(outputs.logits.shape				, A_	)

											_SCREAMING_SNAKE_CASE      = jnp.array([-11.1069, -9.7877, -8.3777]	)

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




from __future__ import annotations

from collections import Counter


def 				SCREAMING_SNAKE_CASE (     UpperCAmelCase__							):

				"""simple docstring"""






				_SCREAMING_SNAKE_CASE      = [True] * n
				_SCREAMING_SNAKE_CASE      = False
				_SCREAMING_SNAKE_CASE      = False
				_SCREAMING_SNAKE_CASE      = True

				for i in range(3   ,int(n**0.5 + 1							)   ,2							):
								_SCREAMING_SNAKE_CASE      = i * 2
								while index < n:
												_SCREAMING_SNAKE_CASE      = False
												_SCREAMING_SNAKE_CASE      = index + i

				_SCREAMING_SNAKE_CASE      = [2]

				for i in range(3   ,UpperCAmelCase__   ,2							):
								if is_prime[i]:
												primes.append(UpperCAmelCase__							)

				return primes


def 				SCREAMING_SNAKE_CASE (     UpperCAmelCase__							):

				"""simple docstring"""






				_SCREAMING_SNAKE_CASE      = str(UpperCAmelCase__							)
				_SCREAMING_SNAKE_CASE      = []
				_SCREAMING_SNAKE_CASE      = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

				for duplicate in Counter(UpperCAmelCase__							) - Counter(set(UpperCAmelCase__							)							):
								_SCREAMING_SNAKE_CASE      = [int(number_str.replace(UpperCAmelCase__   ,UpperCAmelCase__							)							) for digit in digits]
								replacements.append(UpperCAmelCase__							)

				return replacements


def 				SCREAMING_SNAKE_CASE (     UpperCAmelCase__ = 8							):

				"""simple docstring"""






				_SCREAMING_SNAKE_CASE      = set()

				# Filter primes with less than 3 replaceable digits
				_SCREAMING_SNAKE_CASE      = {
				    x for x in set(prime_sieve(100_0000							)							) if len(str(UpperCAmelCase__							)							) - len(set(str(UpperCAmelCase__							)							)							) >= 3
				}

				for prime in primes:
								if prime in numbers_checked:
												continue

								_SCREAMING_SNAKE_CASE      = digit_replacements(UpperCAmelCase__							)

								for family in replacements:
												numbers_checked.update(UpperCAmelCase__							)
												_SCREAMING_SNAKE_CASE      = primes.intersection(UpperCAmelCase__							)

												if len(UpperCAmelCase__							) != family_length:
																continue

												return min(UpperCAmelCase__							)

				return -1


if __name__ == "__main__":
							print(solution())
