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 	_SCREAMING_SNAKE_CASE							(     unittest.TestCase							):






  """simple docstring"""







  def __init__(			self    :				str  ,					__SCREAMING_SNAKE_CASE    :				Optional[int]  ,					__SCREAMING_SNAKE_CASE    :				Optional[Any]=3  ,					__SCREAMING_SNAKE_CASE    :				Dict=32  ,					__SCREAMING_SNAKE_CASE    :				str=3  ,					__SCREAMING_SNAKE_CASE    :				Union[str, Any]=10  ,					__SCREAMING_SNAKE_CASE    :				Optional[Any]=[10, 20, 30, 40]  ,					__SCREAMING_SNAKE_CASE    :				Tuple=[1, 1, 2, 1]  ,					__SCREAMING_SNAKE_CASE    :				Optional[Any]=True  ,					__SCREAMING_SNAKE_CASE    :				Tuple=True  ,					__SCREAMING_SNAKE_CASE    :				Optional[Any]="relu"  ,					__SCREAMING_SNAKE_CASE    :				Optional[Any]=3  ,					__SCREAMING_SNAKE_CASE    :				Optional[int]=None  ,					):






     """simple docstring"""
     _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(__A   )



  def 				_a				(			self    :				Any   ):






     """simple docstring"""
     _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 				_a				(			self    :				Dict   ):






     """simple docstring"""
     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 				_a				(			self    :				List[Any]  ,					__SCREAMING_SNAKE_CASE    :				Union[str, Any]  ,					__SCREAMING_SNAKE_CASE    :				Tuple   ):






     """simple docstring"""
     _snake_case              =      FlaxResNetModel(config=__A   )
     _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 				_a				(			self    :				str  ,					__SCREAMING_SNAKE_CASE    :				Dict  ,					__SCREAMING_SNAKE_CASE    :				int   ):






     """simple docstring"""
     _snake_case              =      self.num_labels
     _snake_case              =      FlaxResNetForImageClassification(config=__A   )
     _snake_case              =      model(__A   )
     self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.num_labels)   )







  def 				_a				(			self    :				Optional[int]   ):






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






  """simple docstring"""







  A_						 =      (FlaxResNetModel, FlaxResNetForImageClassification) if is_flax_available() else ()

  A_						 =      False
  A_						 =      False
  A_						 =      False



  def 				_a				(			self    :				Optional[int]   ):






     """simple docstring"""
     _snake_case              =      FlaxResNetModelTester(self   )
     _snake_case              =      ConfigTester(self  ,					config_class=__A  ,					has_text_modality=__A   )



  def 				_a				(			self    :				Optional[int]   ):






     """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 				_a				(			self    :				List[str]   ):






     """simple docstring"""
     return



  def 				_a				(			self    :				Optional[Any]   ):






     """simple docstring"""
     _snake_case              =      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*__A   )



  def 				_a				(			self    :				Dict   ):






     """simple docstring"""
     _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 				_a				(			self    :				Optional[Any]   ):






     """simple docstring"""
     pass



  @unittest.skip(reason="ResNet does not support input and output embeddings"   )
  def 				_a				(			self    :				Optional[Any]   ):






     """simple docstring"""
     pass



  def 				_a				(			self    :				str   ):






     """simple docstring"""
     _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(__A   )
        _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]  ,					__A   )



  def 				_a				(			self    :				Optional[int]   ):






     """simple docstring"""
     def check_hidden_states_output(__SCREAMING_SNAKE_CASE    :				int  ,					__SCREAMING_SNAKE_CASE    :				Optional[Any]  ,					__SCREAMING_SNAKE_CASE    :				Optional[int]   ):
        _snake_case              =      model_class(__A   )

        _snake_case              =      model(**self._prepare_for_class(__A  ,					__A   )   )

        _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(__A   )  ,					expected_num_stages + 1   )



  @unittest.skip(reason="ResNet does not use feedforward chunking"   )
  def 				_a				(			self    :				Optional[Any]   ):






     """simple docstring"""
     pass







  def 				_a				(			self    :				Tuple   ):






     """simple docstring"""
     _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(__A  ,					__A   )
           _snake_case              =      model_class(__A   )

           @jax.jit
           def model_jitted(__SCREAMING_SNAKE_CASE    :				Optional[int]  ,					**__SCREAMING_SNAKE_CASE    :				Optional[int]   ):
              return model(pixel_values=__A  ,					**__A   )

           with self.subTest("JIT Enabled"   ):
              _snake_case              =      model_jitted(**__A   ).to_tuple()

           with self.subTest("JIT Disabled"   ):
              with jax.disable_jit():
                 _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    UpperCAmelCase__(						):



   """simple docstring"""





   _snake_case              =      Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"  )
   return image







@require_flax
class 	_SCREAMING_SNAKE_CASE							(     unittest.TestCase							):






  """simple docstring"""







  @cached_property
  def 				_a				(			self    :				Tuple   ):






     """simple docstring"""
     return AutoImageProcessor.from_pretrained("microsoft/resnet-50"   ) if is_vision_available() else None







  @slow
  def 				_a				(			self    :				Dict   ):






     """simple docstring"""
     _snake_case              =      FlaxResNetForImageClassification.from_pretrained("microsoft/resnet-50"   )

     _snake_case              =      self.default_image_processor
     _snake_case              =      prepare_img()
     _snake_case              =      image_processor(images=__A  ,					return_tensors="np"   )

     _snake_case              =      model(**__A   )

     # verify the logits
     _snake_case              =      (1, 1_000)
     self.assertEqual(outputs.logits.shape  ,					__A   )

     _snake_case              =      jnp.array([-1_1.1_0_6_9, -9.7_8_7_7, -8.3_7_7_7]   )

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


from math import gcd






def    UpperCAmelCase__(						lowerCamelCase_ = 12000  ):



			"""simple docstring"""





			_snake_case              =      0
			for d in range(max_d + 1  ):
						for n in range(d // 3 + 1							,	(d + 1) // 2  ):
									if gcd(lowerCamelCase_							,	lowerCamelCase_  ) == 1:
												fractions_number += 1
			return fractions_number


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

