





'''simple docstring'''


import inspect
import unittest

from transformers import RegNetConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch
 from torch import nn

 from transformers import RegNetForImageClassification, RegNetModel
 from transformers.models.regnet.modeling_regnet import REGNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import AutoImageProcessor
class  a_  :





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





        """simple docstring"""




        lowercase_     :Union[str, Any]            =					parent
        lowercase_     :Optional[Any]            =					batch_size
        lowercase_     :List[Any]            =					image_size
        lowercase_     :Dict            =					num_channels
        lowercase_     :Any            =					embeddings_size
        lowercase_     :int            =					hidden_sizes
        lowercase_     :Any            =					depths
        lowercase_     :Union[str, Any]            =					is_training
        lowercase_     :Union[str, Any]            =					use_labels
        lowercase_     :Dict            =					hidden_act
        lowercase_     :Union[str, Any]            =					num_labels
        lowercase_     :int            =					scope
        lowercase_     :List[Any]            =					len(snake_case__		)





     def 				lowercase__ (					self						:   Dict		):





        """simple docstring"""




        lowercase_     :Union[str, Any]            =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

        lowercase_     :Optional[int]            =					None
        if self.use_labels:
           lowercase_     :Any            =					ids_tensor([self.batch_size]      , self.num_labels		)

        lowercase_     :Dict            =					self.get_config()

        return config, pixel_values, labels





     def 				lowercase__ (					self						:   List[str]		):





        """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      , )





     def 				lowercase__ (					self						:   Dict      , lowercase						:   str      , lowercase						:   List[Any]      , lowercase						:   str		):





        """simple docstring"""




        lowercase_     :Optional[Any]            =					RegNetModel(config=snake_case__		)
        model.to(snake_case__		)
        model.eval()
        lowercase_     :Any            =					model(snake_case__		)
        # expected last hidden states: B, C, H // 32, W // 32
        self.parent.assertEqual(
            result.last_hidden_state.shape      , (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)      , )





     def 				lowercase__ (					self						:   str      , lowercase						:   List[str]      , lowercase						:   List[str]      , lowercase						:   Any		):





        """simple docstring"""




        lowercase_     :List[str]            =					self.num_labels
        lowercase_     :Optional[Any]            =					RegNetForImageClassification(snake_case__		)
        model.to(snake_case__		)
        model.eval()
        lowercase_     :int            =					model(snake_case__      , labels=snake_case__		)
        self.parent.assertEqual(result.logits.shape      , (self.batch_size, self.num_labels)		)







     def 				lowercase__ (					self						:   str		):





        """simple docstring"""




        lowercase_     :Tuple            =					self.prepare_config_and_inputs()
        lowercase_     ,				lowercase_     ,				lowercase_     :Dict            =					config_and_inputs
        lowercase_     :List[Any]            =					{"pixel_values": pixel_values}
        return config, inputs_dict







@require_torch
class  a_  (							SCREAMING_SNAKE_CASE__      ,		SCREAMING_SNAKE_CASE__      ,		unittest.TestCase				):
     __A						=     (RegNetModel, RegNetForImageClassification) if is_torch_available() else ()
     __A						=     (
         {"feature-extraction": RegNetModel, "image-classification": RegNetForImageClassification}
         if is_torch_available()
         else {}
     )

     __A						=     False
     __A						=     False
     __A						=     False
     __A						=     False





     def 				lowercase__ (					self						:   Optional[Any]		):





        """simple docstring"""




        lowercase_     :Dict            =					RegNetModelTester(self		)
        lowercase_     :Any            =					ConfigTester(self      , config_class=snake_case__      , has_text_modality=snake_case__		)





     def 				lowercase__ (					self						:   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 				lowercase__ (					self						:   int		):





        """simple docstring"""




        return





     @unittest.skip(reason="RegNet does not use inputs_embeds"		)
     def 				lowercase__ (					self						:   Any		):





        """simple docstring"""




        pass





     @unittest.skip(reason="RegNet does not support input and output embeddings"		)
     def 				lowercase__ (					self						:   List[Any]		):





        """simple docstring"""




        pass





     def 				lowercase__ (					self						:   List[str]		):





        """simple docstring"""




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

        for model_class in self.all_model_classes:
           lowercase_     :str            =					model_class(snake_case__		)
           lowercase_     :str            =					inspect.signature(model.forward		)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           lowercase_     :str            =					[*signature.parameters.keys()]

           lowercase_     :Optional[Any]            =					["pixel_values"]
           self.assertListEqual(arg_names[:1]      , snake_case__		)





     def 				lowercase__ (					self						:   Dict		):





        """simple docstring"""




        lowercase_     :List[Any]            =					self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*snake_case__		)





     def 				lowercase__ (					self						:   Dict		):





        """simple docstring"""




        lowercase_     ,				lowercase_     :List[Any]            =					self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
           lowercase_     :Tuple            =					model_class(config=snake_case__		)
           for name, module in model.named_modules():
              if isinstance(snake_case__      , (nn.BatchNormad, nn.GroupNorm)		):
                 self.assertTrue(
                     torch.all(module.weight == 1		)      , msg=F'Parameter {name} of model {model_class} seems not properly initialized'      , )
                 self.assertTrue(
                     torch.all(module.bias == 0		)      , msg=F'Parameter {name} of model {model_class} seems not properly initialized'      , )





     def 				lowercase__ (					self						:   List[str]		):





        """simple docstring"""




        def check_hidden_states_output(lowercase						:   Union[str, Any]      , lowercase						:   Tuple      , lowercase						:   Optional[int]		):
           lowercase_     :List[str]            =					model_class(snake_case__		)
           model.to(snake_case__		)
           model.eval()

           with torch.no_grad():
              lowercase_     :Union[str, Any]            =					model(**self._prepare_for_class(snake_case__      , snake_case__		)		)

           lowercase_     :Optional[Any]            =					outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

           lowercase_     :Optional[int]            =					self.model_tester.num_stages
           self.assertEqual(len(snake_case__		)      , expected_num_stages + 1		)

           # RegNet's feature maps are of shape (batch_size, num_channels, height, width)
           self.assertListEqual(
               list(hidden_states[0].shape[-2:]		)      , [self.model_tester.image_size // 2, self.model_tester.image_size // 2]      , )

        lowercase_     ,				lowercase_     :str            =					self.model_tester.prepare_config_and_inputs_for_common()
        lowercase_     :Optional[int]            =					["basic", "bottleneck"]
        for model_class in self.all_model_classes:
           for layer_type in layers_type:
              lowercase_     :List[Any]            =					layer_type
              lowercase_     :Tuple            =					True
              check_hidden_states_output(snake_case__      , snake_case__      , snake_case__		)

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

              check_hidden_states_output(snake_case__      , snake_case__      , snake_case__		)





     def 				lowercase__ (					self						:   int		):





        """simple docstring"""




        lowercase_     :Tuple            =					self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*snake_case__		)







     @slow
     def 				lowercase__ (					self						:   int		):





        """simple docstring"""




        for model_name in REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           lowercase_     :Dict            =					RegNetModel.from_pretrained(snake_case__		)
           self.assertIsNotNone(snake_case__		)







def 				UpperCAmelCase_    (		):
   lowercase_     :Tuple            =					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"					)
   return image


@require_torch
@require_vision
class  a_  (							unittest.TestCase				):





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





        """simple docstring"""




        return (
            AutoImageProcessor.from_pretrained(REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)
            if is_vision_available()
            else None
        )







     @slow
     def 				lowercase__ (					self						:   List[Any]		):





        """simple docstring"""




        lowercase_     :List[str]            =					RegNetForImageClassification.from_pretrained(REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]		).to(snake_case__		)

        lowercase_     :int            =					self.default_image_processor
        lowercase_     :List[str]            =					prepare_img()
        lowercase_     :Tuple            =					image_processor(images=snake_case__      , return_tensors="pt"		).to(snake_case__		)

        # forward pass
        with torch.no_grad():
           lowercase_     :str            =					model(**snake_case__		)

        # verify the logits
        lowercase_     :int            =					torch.Size((1, 1_000)		)
        self.assertEqual(outputs.logits.shape      , snake_case__		)

        lowercase_     :str            =					torch.tensor([-0.41_80, -1.50_51, -3.48_36]		).to(snake_case__		)

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








from __future__ import annotations

import math


def 					_a							(					lowerCAmelCase )->	bool:

		if 1 < number < 4:
				# 2 and 3 are primes
				return True
		elif number < 2 or number % 2 == 0 or number % 3 == 0:
				# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
				return False

		# All primes number are in format of 6k +/- 1
		for i in range(5    ,						int(math.sqrt(lowerCAmelCase ) + 1 )    ,						6 ):
				if number % i == 0 or number % (i + 2) == 0:
						return False
		return True


SCREAMING_SNAKE_CASE:     List[str]									= [num for num in range(3, 1_0_0_0_0_1, 2) if not is_prime(num)]


def 					_a							(					lowerCAmelCase )->	list[int]:
		if not isinstance(lowerCAmelCase    ,						lowerCAmelCase ):
				raise ValueError('n must be an integer' )
		if n <= 0:
				raise ValueError('n must be >= 0' )

		SCREAMING_SNAKE_CASE_					      =							[]
		for num in range(len(lowerCAmelCase ) ):
				SCREAMING_SNAKE_CASE_					      =							0
				while 2 * i * i <= odd_composites[num]:
						SCREAMING_SNAKE_CASE_					      =							odd_composites[num] - 2 * i * i
						if is_prime(lowerCAmelCase ):
								break
						i += 1
				else:
						list_nums.append(odd_composites[num] )
						if len(lowerCAmelCase ) == n:
								return list_nums

		return []


def 					_a							(					)->	int:
		return compute_nums(1 )[0]


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