


'''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       :       List[str]  ,		UpperCamelCase       :       Tuple  ,		UpperCamelCase       :       Optional[int]=3  ,		UpperCamelCase       :       Optional[int]=32  ,		UpperCamelCase       :       List[str]=3  ,		UpperCamelCase       :       Tuple=10  ,		UpperCamelCase       :       Any=[10, 20, 30, 40]  ,		UpperCamelCase       :       Dict=[1, 1, 2, 1]  ,		UpperCamelCase       :       Union[str, Any]=True  ,		UpperCamelCase       :       Tuple=True  ,		UpperCamelCase       :       Tuple="relu"  ,		UpperCamelCase       :       Union[str, Any]=3  ,		UpperCamelCase       :       Dict=None  ,		):

             '''simple docstring'''







             lowercase__      =					parent
             lowercase__      =					batch_size
             lowercase__      =					image_size
             lowercase__      =					num_channels
             lowercase__      =					embeddings_size
             lowercase__      =					hidden_sizes
             lowercase__      =					depths
             lowercase__      =					is_training
             lowercase__      =					use_labels
             lowercase__      =					hidden_act
             lowercase__      =					num_labels
             lowercase__      =					scope
             lowercase__      =					len(UpperCamelCase					)



      def  UpperCamelCase__						(self       :       List[str]					):

             '''simple docstring'''







             lowercase__      =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

             lowercase__      =					self.get_config()

             return config, pixel_values



      def  UpperCamelCase__						(self       :       Dict					):

             '''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  UpperCamelCase__						(self       :       Dict  ,		UpperCamelCase       :       Dict  ,		UpperCamelCase       :       List[str]					):

             '''simple docstring'''







             lowercase__      =					FlaxRegNetModel(config=UpperCamelCase					)
             lowercase__      =					model(UpperCamelCase					)

             # 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  UpperCamelCase__						(self       :       Any  ,		UpperCamelCase       :       int  ,		UpperCamelCase       :       int					):

             '''simple docstring'''







             lowercase__      =					self.num_labels
             lowercase__      =					FlaxRegNetForImageClassification(config=UpperCamelCase					)
             lowercase__      =					model(UpperCamelCase					)
             self.parent.assertEqual(result.logits.shape  ,		(self.batch_size, self.num_labels)					)






      def  UpperCamelCase__						(self       :       List[Any]					):

             '''simple docstring'''







             lowercase__      =					self.prepare_config_and_inputs()
             lowercase__     ,lowercase__      =					config_and_inputs
             lowercase__      =					{'''pixel_values''': pixel_values}
             return config, inputs_dict






@require_flax
class     __lowerCAmelCase		(lowercase_    ,	unittest.TestCase	):





      '''simple docstring'''






      lowerCAmelCase__   :	Optional[Any]       =				(FlaxRegNetModel, FlaxRegNetForImageClassification) if is_flax_available() else ()

      lowerCAmelCase__   :	List[str]       =				False
      lowerCAmelCase__   :	Tuple       =				False
      lowerCAmelCase__   :	int       =				False



      def  UpperCamelCase__						(self       :       List[Any]					):

             '''simple docstring'''







             lowercase__      =					FlaxRegNetModelTester(self					)
             lowercase__      =					ConfigTester(self  ,		config_class=UpperCamelCase  ,		has_text_modality=UpperCamelCase					)



      def  UpperCamelCase__						(self       :       List[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  UpperCamelCase__						(self       :       int					):

             '''simple docstring'''







             return



      def  UpperCamelCase__						(self       :       Union[str, Any]					):

             '''simple docstring'''







             lowercase__      =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*UpperCamelCase					)



      def  UpperCamelCase__						(self       :       Dict					):

             '''simple docstring'''







             lowercase__      =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*UpperCamelCase					)



      @unittest.skip(reason='''RegNet does not use inputs_embeds'''					)
      def  UpperCamelCase__						(self       :       int					):

             '''simple docstring'''







             pass



      @unittest.skip(reason='''RegNet does not support input and output embeddings'''					)
      def  UpperCamelCase__						(self       :       Optional[Any]					):

             '''simple docstring'''







             pass



      def  UpperCamelCase__						(self       :       Any					):

             '''simple docstring'''







             lowercase__     ,lowercase__      =					self.model_tester.prepare_config_and_inputs_for_common()

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

                    lowercase__      =					['''pixel_values''']
                    self.assertListEqual(arg_names[:1]  ,		UpperCamelCase					)



      def  UpperCamelCase__						(self       :       Dict					):

             '''simple docstring'''







             def check_hidden_states_output(UpperCamelCase       :       List[Any]  ,		UpperCamelCase       :       Tuple  ,		UpperCamelCase       :       List[Any]					):
                    lowercase__      =					model_class(UpperCamelCase					)

                    lowercase__      =					model(**self._prepare_for_class(UpperCamelCase  ,		UpperCamelCase					)					)

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

                    lowercase__      =					self.model_tester.num_stages
                    self.assertEqual(len(UpperCamelCase					)  ,		expected_num_stages + 1					)

             lowercase__     ,lowercase__      =					self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    lowercase__      =					True
                    check_hidden_states_output(UpperCamelCase  ,		UpperCamelCase  ,		UpperCamelCase					)

                    # check that output_hidden_states also work using config
                    del inputs_dict["output_hidden_states"]
                    lowercase__      =					True

                    check_hidden_states_output(UpperCamelCase  ,		UpperCamelCase  ,		UpperCamelCase					)






      def  UpperCamelCase__						(self       :       Any					):

             '''simple docstring'''







             lowercase__     ,lowercase__      =					self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    with self.subTest(model_class.__name__					):
                           lowercase__      =					self._prepare_for_class(UpperCamelCase  ,		UpperCamelCase					)
                           lowercase__      =					model_class(UpperCamelCase					)

                           @jax.jit
                           def model_jitted(UpperCamelCase       :       Any  ,		**UpperCamelCase       :       Union[str, Any]					):
                                  return model(pixel_values=UpperCamelCase  ,		**UpperCamelCase					)

                           with self.subTest('''JIT Enabled'''					):
                                  lowercase__      =					model_jitted(**UpperCamelCase					).to_tuple()

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

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






def _SCREAMING_SNAKE_CASE ()			->			Optional[Any]:






       """simple docstring"""







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

@require_flax
class     __lowerCAmelCase		(unittest.TestCase	):





      '''simple docstring'''






      @cached_property
      def  UpperCamelCase__						(self       :       Optional[Any]					):

             '''simple docstring'''







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






      @slow
      def  UpperCamelCase__						(self       :       Optional[Any]					):

             '''simple docstring'''







             lowercase__      =					FlaxRegNetForImageClassification.from_pretrained('''facebook/regnet-y-040'''					)

             lowercase__      =					self.default_image_processor
             lowercase__      =					prepare_img()
             lowercase__      =					image_processor(images=UpperCamelCase  ,		return_tensors='''np'''					)

             lowercase__      =					model(**UpperCamelCase					)

             # verify the logits
             lowercase__      =					(1, 1000)
             self.assertEqual(outputs.logits.shape  ,		UpperCamelCase					)

             lowercase__      =					jnp.array([-0.41_80, -1.50_51, -3.48_36]					)

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








'''simple docstring'''

from math import sqrt

def _SCREAMING_SNAKE_CASE (A = 1_000_000			)			->			int:






       """simple docstring"""







       lowercase__      =					0
       lowercase__      =					0
       lowercase__      =					42

       while num_cuboids <= limit:
              max_cuboid_size += 1
              for sum_shortest_sides in range(2    ,					2 * max_cuboid_size + 1			):
                     if sqrt(sum_shortest_sides**2 + max_cuboid_size**2			).is_integer():
                            num_cuboids += (
                                min(A    ,					sum_shortest_sides // 2			)
                                - max(1    ,					sum_shortest_sides - max_cuboid_size			)
                                + 1
                            )

       return max_cuboid_size


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




