


"""simple docstring"""







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    __A       ( 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				,					)      ->  int:
     a					=parent
     a					=batch_size
     a					=image_size
     a					=num_channels
     a					=embeddings_size
     a					=hidden_sizes
     a					=depths
     a					=is_training
     a					=use_labels
     a					=hidden_act
     a					=num_labels
     a					=scope
     a					=len(__A		)


 def    SCREAMING_SNAKE_CASE							(	self		)      ->  str:
     a					=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

     a					=self.get_config()

     return config, pixel_values


 def    SCREAMING_SNAKE_CASE							(	self		)      ->  List[Any]:
     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    SCREAMING_SNAKE_CASE							(	self				,					__A				,					__A		)      ->  List[Any]:
     a					=FlaxResNetModel(config=__A		)
     a					=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    SCREAMING_SNAKE_CASE							(	self				,					__A				,					__A		)      ->  Dict:
     a					=self.num_labels
     a					=FlaxResNetForImageClassification(config=__A		)
     a					=model(__A		)
     self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_labels)		)





 def    SCREAMING_SNAKE_CASE							(	self		)      ->  Dict:
     a					=self.prepare_config_and_inputs()
     a	,   a					=config_and_inputs
     a					={'''pixel_values''': pixel_values}
     return config, inputs_dict






@require_flax
class    __A       ( _SCREAMING_SNAKE_CASE,					unittest.TestCase    ):






 """simple docstring"""




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

 __lowerCAmelCase				      =						False
 __lowerCAmelCase				      =						False
 __lowerCAmelCase				      =						False


 def    SCREAMING_SNAKE_CASE							(	self		)      ->  None:
     a					=FlaxResNetModelTester(self		)
     a					=ConfigTester(self				,					config_class=__A				,					has_text_modality=__A		)


 def    SCREAMING_SNAKE_CASE							(	self		)      ->  Union[str, Any]:
     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    SCREAMING_SNAKE_CASE							(	self		)      ->  Union[str, Any]:
     return


 def    SCREAMING_SNAKE_CASE							(	self		)      ->  Optional[int]:
     a					=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*__A		)


 def    SCREAMING_SNAKE_CASE							(	self		)      ->  int:
     a					=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    SCREAMING_SNAKE_CASE							(	self		)      ->  List[Any]:
     pass


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


 def    SCREAMING_SNAKE_CASE							(	self		)      ->  int:
     a	,   a					=self.model_tester.prepare_config_and_inputs_for_common()

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

         a					=['''pixel_values''']
         self.assertListEqual(arg_names[:1]				,					__A		)


 def    SCREAMING_SNAKE_CASE							(	self		)      ->  Optional[int]:
     def check_hidden_states_output(__A				,					__A				,					__A		):
         a					=model_class(__A		)

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

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

         a					=self.model_tester.num_stages
         self.assertEqual(len(__A		)				,					expected_num_stages + 1		)


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





 def    SCREAMING_SNAKE_CASE							(	self		)      ->  List[str]:
     a	,   a					=self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
         with self.subTest(model_class.__name__		):
             a					=self._prepare_for_class(__A				,					__A		)
             a					=model_class(__A		)

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

             with self.subTest('''JIT Enabled'''		):
                 a					=model_jitted(**__A		).to_tuple()

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







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






@require_flax
class    __A       ( unittest.TestCase    ):






 """simple docstring"""




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





 @slow
 def    SCREAMING_SNAKE_CASE							(	self		)      ->  str:
     a					=FlaxResNetForImageClassification.from_pretrained('''microsoft/resnet-50'''		)

     a					=self.default_image_processor
     a					=prepare_img()
     a					=image_processor(images=__A				,					return_tensors='''np'''		)

     a					=model(**__A		)

     # verify the logits
     a					=(1, 1000)
     self.assertEqual(outputs.logits.shape				,					__A		)

     a					=jnp.array([-11.1_069, -9.7_877, -8.3_777]		)

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



"""simple docstring"""







from math import gcd
def _A		(		lowercase = 1_20_00	):







    """simple docstring"""
    a					=0
    for d in range(max_d + 1	):
        for n in range(d // 3 + 1 ,					(d + 1) // 2	):
            if gcd(lowercase ,					lowercase	) == 1:
                fractions_number += 1
    return fractions_number


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