


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







    """simple docstring"""




    def __init__( self    :   str    ,			__UpperCAmelCase    :   int    ,			__UpperCAmelCase    :   List[str]=3    ,			__UpperCAmelCase    :   Any=32    ,			__UpperCAmelCase    :   Dict=3    ,			__UpperCAmelCase    :   List[str]=10    ,			__UpperCAmelCase    :   Dict=[10, 20, 30, 40]    ,			__UpperCAmelCase    :   Union[str, Any]=[1, 1, 2, 1]    ,			__UpperCAmelCase    :   int=True    ,			__UpperCAmelCase    :   int=True    ,			__UpperCAmelCase    :   str="relu"    ,			__UpperCAmelCase    :   Union[str, Any]=3    ,			__UpperCAmelCase    :   str=None    ,			):
      a						:		Optional[Any]											=      parent
      a						:		List[str]											=      batch_size
      a						:		List[str]											=      image_size
      a						:		Any											=      num_channels
      a						:		int											=      embeddings_size
      a						:		str											=      hidden_sizes
      a						:		Optional[Any]											=      depths
      a						:		List[str]											=      is_training
      a						:		int											=      use_labels
      a						:		List[str]											=      hidden_act
      a						:		Tuple											=      num_labels
      a						:		Union[str, Any]											=      scope
      a						:		int											=      len(__UpperCAmelCase)






    def      __snake_case							( self    :   List[str]):
      a						:		Union[str, Any]											=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

      a						:		str											=      self.get_config()

      return config, pixel_values






    def      __snake_case							( self    :   int):
      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      __snake_case							( self    :   List[str]    ,			__UpperCAmelCase    :   List[str]    ,			__UpperCAmelCase    :   Optional[int]):
      a						:		List[Any]											=      FlaxRegNetModel(config=__UpperCAmelCase)
      a						:		List[str]											=      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      __snake_case							( self    :   str    ,			__UpperCAmelCase    :   int    ,			__UpperCAmelCase    :   Optional[Any]):
      a						:		Any											=      self.num_labels
      a						:		List[Any]											=      FlaxRegNetForImageClassification(config=__UpperCAmelCase)
      a						:		Union[str, Any]											=      model(__UpperCAmelCase)
      self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels))






    def      __snake_case							( self    :   int):
      a						:		str											=      self.prepare_config_and_inputs()
      a							,		a						:		int											=      config_and_inputs
      a						:		Optional[int]											=      {"pixel_values": pixel_values}
      return config, inputs_dict






@require_flax
class 						_A  (  _a   ,unittest.TestCase  ):







    """simple docstring"""




    UpperCAmelCase	:							int     =	(FlaxRegNetModel, FlaxRegNetForImageClassification) if is_flax_available() else ()

    UpperCAmelCase	:							Dict     =	False
    UpperCAmelCase	:							Any     =	False
    UpperCAmelCase	:							Dict     =	False






    def      __snake_case							( self    :   str):
      a						:		Union[str, Any]											=      FlaxRegNetModelTester(self)
      a						:		str											=      ConfigTester(self    ,			config_class=__UpperCAmelCase    ,			has_text_modality=__UpperCAmelCase)






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






    def      __snake_case							( self    :   Any):
      a						:		Optional[int]											=      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__UpperCAmelCase)






    def      __snake_case							( self    :   Tuple):
      a						:		int											=      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      __snake_case							( self    :   Any):
      pass






    @unittest.skip(reason="RegNet does not support input and output embeddings")
    def      __snake_case							( self    :   Dict):
      pass






    def      __snake_case							( self    :   Optional[Any]):
      a							,		a						:		str											=      self.model_tester.prepare_config_and_inputs_for_common()

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

        a						:		int											=      ["pixel_values"]
        self.assertListEqual(arg_names[:1]    ,			__UpperCAmelCase)






    def      __snake_case							( self    :   Union[str, Any]):
      def check_hidden_states_output(__UpperCAmelCase    :   Optional[Any]    ,			__UpperCAmelCase    :   List[str]    ,			__UpperCAmelCase    :   str):
        a						:		Optional[Any]											=      model_class(__UpperCAmelCase)

        a						:		List[Any]											=      model(**self._prepare_for_class(__UpperCAmelCase    ,			__UpperCAmelCase))

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

        a						:		str											=      self.model_tester.num_stages
        self.assertEqual(len(__UpperCAmelCase)    ,			expected_num_stages + 1)

      a							,		a						:		Union[str, Any]											=      self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        a						:		str											=      True
        check_hidden_states_output(__UpperCAmelCase    ,			__UpperCAmelCase    ,			__UpperCAmelCase)

        # check that output_hidden_states also work using config
        del inputs_dict["output_hidden_states"]
        a						:		Tuple											=      True

        check_hidden_states_output(__UpperCAmelCase    ,			__UpperCAmelCase    ,			__UpperCAmelCase)






    def      __snake_case							( self    :   Union[str, Any]):
      a							,		a						:		Dict											=      self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        with self.subTest(model_class.__name__):
          a						:		int											=      self._prepare_for_class(__UpperCAmelCase    ,			__UpperCAmelCase)
          a						:		Optional[int]											=      model_class(__UpperCAmelCase)

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

          with self.subTest("JIT Enabled"):
            a						:		Dict											=      model_jitted(**__UpperCAmelCase).to_tuple()

          with self.subTest("JIT Disabled"):
            with jax.disable_jit():
              a						:		Any											=      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 					lowercase      (    )->				List[Any]:
  '''simple docstring'''







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







@require_flax
class 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    @cached_property
    def      __snake_case							( self    :   str):
      return AutoImageProcessor.from_pretrained("facebook/regnet-y-040") if is_vision_available() else None






    @slow
    def      __snake_case							( self    :   int):
      a						:		Tuple											=      FlaxRegNetForImageClassification.from_pretrained("facebook/regnet-y-040")

      a						:		Optional[Any]											=      self.default_image_processor
      a						:		List[Any]											=      prepare_img()
      a						:		List[str]											=      image_processor(images=__UpperCAmelCase    ,			return_tensors="np")

      a						:		Any											=      model(**__UpperCAmelCase)

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

      a						:		Tuple											=      jnp.array([-0.4_180, -1.5_051, -3.4_836])

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










"""simple docstring"""







import sys
import turtle


def 					lowercase      (    A_  ,       A_	)->				tuple[float, float]:
  '''simple docstring'''







  return (pa[0] + pa[0]) / 2, (pa[1] + pa[1]) / 2


def 					lowercase      (    A_  ,       A_  ,       A_  ,       A_  ,       )->				None:
  '''simple docstring'''







  my_pen.up()
  my_pen.goto(vertexa[0]  ,       vertexa[1]	)
  my_pen.down()
  my_pen.goto(vertexa[0]  ,       vertexa[1]	)
  my_pen.goto(vertexa[0]  ,       vertexa[1]	)
  my_pen.goto(vertexa[0]  ,       vertexa[1]	)

  if depth == 0:
    return

  triangle(A_  ,       get_mid(A_  ,       A_	)  ,       get_mid(A_  ,       A_	)  ,       depth - 1	)
  triangle(A_  ,       get_mid(A_  ,       A_	)  ,       get_mid(A_  ,       A_	)  ,       depth - 1	)
  triangle(A_  ,       get_mid(A_  ,       A_	)  ,       get_mid(A_  ,       A_	)  ,       depth - 1	)


if __name__ == "__main__":
 if len(sys.argv) != 2:
  raise ValueError(
      """Correct format for using this script: """
      """python fractals.py <int:depth_for_fractal>"""
  )
 __lowercase    =				turtle.Turtle()
 my_pen.ht()
 my_pen.speed(5)
 my_pen.pencolor("""red""")

 __lowercase    =				[(-175, -125), (0, 175), (175, -125)]  # vertices of triangle
 triangle(vertices[0], vertices[1], vertices[2], int(sys.argv[1]))






