


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






      def __init__(			self      :Union[str, Any]					,						SCREAMING_SNAKE_CASE      :List[str]					,						SCREAMING_SNAKE_CASE      :List[Any]=3					,						SCREAMING_SNAKE_CASE      :Tuple=3_2					,						SCREAMING_SNAKE_CASE      :Dict=3					,						SCREAMING_SNAKE_CASE      :List[str]=1_0					,						SCREAMING_SNAKE_CASE      :Optional[Any]=[1_0, 2_0, 3_0, 4_0]					,						SCREAMING_SNAKE_CASE      :str=[1, 1, 2, 1]					,						SCREAMING_SNAKE_CASE      :List[Any]=True					,						SCREAMING_SNAKE_CASE      :str=True					,						SCREAMING_SNAKE_CASE      :List[Any]="relu"					,						SCREAMING_SNAKE_CASE      :Any=3					,						SCREAMING_SNAKE_CASE      :Optional[int]=None					,						)	-> int:




             '''simple docstring'''
             _a   :			Optional[int]					 =parent
             _a   :			Optional[int]					 =batch_size
             _a   :			int					 =image_size
             _a   :			Any					 =num_channels
             _a   :			Any					 =embeddings_size
             _a   :			List[str]					 =hidden_sizes
             _a   :			Dict					 =depths
             _a   :			List[Any]					 =is_training
             _a   :			str					 =use_labels
             _a   :			Optional[Any]					 =hidden_act
             _a   :			str					 =num_labels
             _a   :			int					 =scope
             _a   :			str					 =len(SCREAMING_SNAKE_CASE     )






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




             '''simple docstring'''
             _a   :			Union[str, Any]					 =floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

             _a   :			Tuple					 =self.get_config()

             return config, pixel_values






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




             '''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 __UpperCAmelCase	(			self      :Dict					,						SCREAMING_SNAKE_CASE      :int					,						SCREAMING_SNAKE_CASE      :Union[str, Any]     )	-> Dict:




             '''simple docstring'''
             _a   :			Dict					 =FlaxResNetModel(config=SCREAMING_SNAKE_CASE     )
             _a   :			Union[str, Any]					 =model(SCREAMING_SNAKE_CASE     )

             # 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 __UpperCAmelCase	(			self      :str					,						SCREAMING_SNAKE_CASE      :List[Any]					,						SCREAMING_SNAKE_CASE      :Tuple     )	-> str:




             '''simple docstring'''
             _a   :			Dict					 =self.num_labels
             _a   :			Union[str, Any]					 =FlaxResNetForImageClassification(config=SCREAMING_SNAKE_CASE     )
             _a   :			str					 =model(SCREAMING_SNAKE_CASE     )
             self.parent.assertEqual(result.logits.shape					,						(self.batch_size, self.num_labels)     )






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




             '''simple docstring'''
             _a   :			str					 =self.prepare_config_and_inputs()
             _a ,   _a   :			Optional[int]					 =config_and_inputs
             _a   :			Dict					 ={"""pixel_values""": pixel_values}
             return config, inputs_dict







@require_flax
class A__	(						UpperCAmelCase__			,					unittest.TestCase				):
      __UpperCamelCase	:  Optional[Any]     	=							(FlaxResNetModel, FlaxResNetForImageClassification) if is_flax_available() else ()

      __UpperCamelCase	:  Dict     	=							False
      __UpperCamelCase	:  Tuple     	=							False
      __UpperCamelCase	:  List[str]     	=							False






      def __UpperCAmelCase	(			self      :str     )	-> None:




             '''simple docstring'''
             _a   :			Optional[Any]					 =FlaxResNetModelTester(self     )
             _a   :			Tuple					 =ConfigTester(self					,						config_class=SCREAMING_SNAKE_CASE					,						has_text_modality=SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :List[str]     )	-> Tuple:




             '''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 __UpperCAmelCase	(			self      :List[str]     )	-> Union[str, Any]:




             '''simple docstring'''
             return






      def __UpperCAmelCase	(			self      :str     )	-> str:




             '''simple docstring'''
             _a   :			List[str]					 =self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :int     )	-> List[Any]:




             '''simple docstring'''
             _a   :			List[str]					 =self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE     )






      @unittest.skip(reason="""ResNet does not use inputs_embeds"""     )
      def __UpperCAmelCase	(			self      :Tuple     )	-> Any:




             '''simple docstring'''
             pass






      @unittest.skip(reason="""ResNet does not support input and output embeddings"""     )
      def __UpperCAmelCase	(			self      :List[str]     )	-> Tuple:




             '''simple docstring'''
             pass






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




             '''simple docstring'''
             _a ,   _a   :			List[Any]					 =self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    _a   :			Union[str, Any]					 =model_class(SCREAMING_SNAKE_CASE     )
                    _a   :			Tuple					 =inspect.signature(model.__call__     )
                    # signature.parameters is an OrderedDict => so arg_names order is deterministic
                    _a   :			List[Any]					 =[*signature.parameters.keys()]

                    _a   :			List[str]					 =["""pixel_values"""]
                    self.assertListEqual(arg_names[:1]					,						SCREAMING_SNAKE_CASE     )






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




             '''simple docstring'''
             def check_hidden_states_output(SCREAMING_SNAKE_CASE      :Optional[Any]					,						SCREAMING_SNAKE_CASE      :Tuple					,						SCREAMING_SNAKE_CASE      :List[Any]     ):
                    _a   :			Optional[int]					 =model_class(SCREAMING_SNAKE_CASE     )

                    _a   :			List[str]					 =model(**self._prepare_for_class(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )     )

                    _a   :			Dict					 =outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

                    _a   :			str					 =self.model_tester.num_stages
                    self.assertEqual(len(SCREAMING_SNAKE_CASE     )					,						expected_num_stages + 1     )






      @unittest.skip(reason="""ResNet does not use feedforward chunking"""     )
      def __UpperCAmelCase	(			self      :int     )	-> str:




             '''simple docstring'''
             pass






      def __UpperCAmelCase	(			self      :Dict     )	-> Dict:




             '''simple docstring'''
             _a ,   _a   :			Tuple					 =self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    with self.subTest(model_class.__name__     ):
                           _a   :			List[str]					 =self._prepare_for_class(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )
                           _a   :			int					 =model_class(SCREAMING_SNAKE_CASE     )

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

                           with self.subTest("""JIT Enabled"""     ):
                                  _a   :			Tuple					 =model_jitted(**SCREAMING_SNAKE_CASE     ).to_tuple()

                           with self.subTest("""JIT Disabled"""     ):
                                  with jax.disable_jit():
                                         _a   :			str					 =model_jitted(**SCREAMING_SNAKE_CASE     ).to_tuple()

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


def      SCREAMING_SNAKE_CASE_ (  )  ->      Dict:
       _a   :			int					 =Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
       return image







@require_flax
class A__	(						unittest.TestCase				):






      @cached_property
      def __UpperCAmelCase	(			self      :Optional[int]     )	-> List[str]:




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






      @slow
      def __UpperCAmelCase	(			self      :List[str]     )	-> Any:




             '''simple docstring'''
             _a   :			List[str]					 =FlaxResNetForImageClassification.from_pretrained("""microsoft/resnet-50"""     )

             _a   :			Tuple					 =self.default_image_processor
             _a   :			Optional[int]					 =prepare_img()
             _a   :			Any					 =image_processor(images=SCREAMING_SNAKE_CASE					,						return_tensors="""np"""     )

             _a   :			Any					 =model(**SCREAMING_SNAKE_CASE     )

             # verify the logits
             _a   :			Tuple					 =(1, 1_0_0_0)
             self.assertEqual(outputs.logits.shape					,						SCREAMING_SNAKE_CASE     )

             _a   :			List[Any]					 =jnp.array([-11.1_069, -9.7_877, -8.3_777]     )

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






'''simple docstring'''







import math


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int  )  ->      int:
       return sum(int(_UpperCAmelCase  ) for digit in str(_UpperCAmelCase  )  )


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int = 30  )  ->      int:
       _a   :			List[Any]					 =[]
       for digit in range(2   ,100  ):
              for power in range(2   ,100  ):
                     _a   :			Optional[Any]					 =int(math.pow(_UpperCAmelCase   ,_UpperCAmelCase  )  )
                     if digit == digit_sum(_UpperCAmelCase  ):
                            digit_to_powers.append(_UpperCAmelCase  )

       digit_to_powers.sort()
       return digit_to_powers[n - 1]


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


