



"""simple docstring"""
import inspect
import unittest

from transformers import ConvNextConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
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 transformers import ConvNextBackbone, ConvNextForImageClassification, ConvNextModel
      from transformers.models.convnext.modeling_convnext import CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor



class    SCREAMING_SNAKE_CASE__						:

   def __init__(     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE=13   ,  _SCREAMING_SNAKE_CASE=32   ,  _SCREAMING_SNAKE_CASE=3   ,  _SCREAMING_SNAKE_CASE=4   ,  _SCREAMING_SNAKE_CASE=[10, 20, 30, 40]   ,  _SCREAMING_SNAKE_CASE=[2, 2, 3, 2]   ,  _SCREAMING_SNAKE_CASE=True   ,  _SCREAMING_SNAKE_CASE=True   ,  _SCREAMING_SNAKE_CASE=37   ,  _SCREAMING_SNAKE_CASE="gelu"   ,  _SCREAMING_SNAKE_CASE=10   ,  _SCREAMING_SNAKE_CASE=0.02   ,  _SCREAMING_SNAKE_CASE=["stage2", "stage3", "stage4"]   ,  _SCREAMING_SNAKE_CASE=[2, 3, 4]   ,  _SCREAMING_SNAKE_CASE=None   ,  )						->   Any:





    '''simple docstring'''




    UpperCAmelCase			:      Any			=			parent
    UpperCAmelCase			:      str			=			batch_size
    UpperCAmelCase			:      List[str]			=			image_size
    UpperCAmelCase			:      int			=			num_channels
    UpperCAmelCase			:      Any			=			num_stages
    UpperCAmelCase			:      Tuple			=			hidden_sizes
    UpperCAmelCase			:      Optional[int]			=			depths
    UpperCAmelCase			:      Optional[int]			=			is_training
    UpperCAmelCase			:      List[str]			=			use_labels
    UpperCAmelCase			:      Union[str, Any]			=			intermediate_size
    UpperCAmelCase			:      Optional[Any]			=			hidden_act
    UpperCAmelCase			:      Optional[Any]			=			num_labels
    UpperCAmelCase			:      List[str]			=			initializer_range
    UpperCAmelCase			:      List[Any]			=			out_features
    UpperCAmelCase			:      Optional[int]			=			out_indices
    UpperCAmelCase			:      List[Any]			=			scope

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





    '''simple docstring'''




    UpperCAmelCase			:      Optional[int]			=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

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

    UpperCAmelCase			:      int			=			self.get_config()
    return config, pixel_values, labels

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Optional[int]:





    '''simple docstring'''




    return ConvNextConfig(
        num_channels=self.num_channels   ,  hidden_sizes=self.hidden_sizes   ,  depths=self.depths   ,  num_stages=self.num_stages   ,  hidden_act=self.hidden_act   ,  is_decoder=_SCREAMING_SNAKE_CASE   ,  initializer_range=self.initializer_range   ,  out_features=self.out_features   ,  out_indices=self.out_indices   ,  num_labels=self.num_labels   ,  )

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)						->   Tuple:





    '''simple docstring'''




    UpperCAmelCase			:      str			=			ConvNextModel(config=_SCREAMING_SNAKE_CASE		)
    model.to(_SCREAMING_SNAKE_CASE		)
    model.eval()
    UpperCAmelCase			:      int			=			model(_SCREAMING_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 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)						->   int:





    '''simple docstring'''




    UpperCAmelCase			:      Tuple			=			ConvNextForImageClassification(_SCREAMING_SNAKE_CASE		)
    model.to(_SCREAMING_SNAKE_CASE		)
    model.eval()
    UpperCAmelCase			:      int			=			model(_SCREAMING_SNAKE_CASE   ,  labels=_SCREAMING_SNAKE_CASE		)
    self.parent.assertEqual(result.logits.shape   ,  (self.batch_size, self.num_labels)		)

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)						->   List[str]:





    '''simple docstring'''




    UpperCAmelCase			:      List[str]			=			ConvNextBackbone(config=_SCREAMING_SNAKE_CASE		)
    model.to(_SCREAMING_SNAKE_CASE		)
    model.eval()
    UpperCAmelCase			:      Dict			=			model(_SCREAMING_SNAKE_CASE		)

    # verify hidden states
    self.parent.assertEqual(len(result.feature_maps		)   ,  len(config.out_features		)		)
    self.parent.assertListEqual(list(result.feature_maps[0].shape		)   ,  [self.batch_size, self.hidden_sizes[1], 4, 4]		)

    # verify channels
    self.parent.assertEqual(len(model.channels		)   ,  len(config.out_features		)		)
    self.parent.assertListEqual(model.channels   ,  config.hidden_sizes[1:]		)

    # verify backbone works with out_features=None
    UpperCAmelCase			:      List[Any]			=			None
    UpperCAmelCase			:      Union[str, Any]			=			ConvNextBackbone(config=_SCREAMING_SNAKE_CASE		)
    model.to(_SCREAMING_SNAKE_CASE		)
    model.eval()
    UpperCAmelCase			:      List[Any]			=			model(_SCREAMING_SNAKE_CASE		)

    # verify feature maps
    self.parent.assertEqual(len(result.feature_maps		)   ,  1		)
    self.parent.assertListEqual(list(result.feature_maps[0].shape		)   ,  [self.batch_size, self.hidden_sizes[-1], 1, 1]		)

    # verify channels
    self.parent.assertEqual(len(model.channels		)   ,  1		)
    self.parent.assertListEqual(model.channels   ,  [config.hidden_sizes[-1]]		)




   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





    '''simple docstring'''




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



@require_torch
class    SCREAMING_SNAKE_CASE__						(      UpperCAmelCase__   ,    UpperCAmelCase__   ,    unittest.TestCase				):
   __lowerCAmelCase						:     Tuple		=		(
       (
           ConvNextModel,
           ConvNextForImageClassification,
           ConvNextBackbone,
       )
       if is_torch_available()
       else ()
   )
   __lowerCAmelCase						:     Tuple		=		(
       {'feature-extraction': ConvNextModel, 'image-classification': ConvNextForImageClassification}
       if is_torch_available()
       else {}
   )

   __lowerCAmelCase						:     Tuple		=		True
   __lowerCAmelCase						:     Tuple		=		False
   __lowerCAmelCase						:     Union[str, Any]		=		False
   __lowerCAmelCase						:     str		=		False
   __lowerCAmelCase						:     Tuple		=		False

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Dict:





    '''simple docstring'''




    UpperCAmelCase			:      Dict			=			ConvNextModelTester(self		)
    UpperCAmelCase			:      Optional[int]			=			ConfigTester(self   ,  config_class=_SCREAMING_SNAKE_CASE   ,  has_text_modality=_SCREAMING_SNAKE_CASE   ,  hidden_size=37		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





    '''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 			SCREAMING_SNAKE_CASE  (     self		)						->   str:





    '''simple docstring'''




    return

   @unittest.skip(reason="""ConvNext does not use inputs_embeds"""		)
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Optional[int]:





    '''simple docstring'''




    pass

   @unittest.skip(reason="""ConvNext does not support input and output embeddings"""		)
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[Any]:





    '''simple docstring'''




    pass

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





    '''simple docstring'''




    pass

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   str:





    '''simple docstring'''




    UpperCAmelCase			:      Any			=			self.model_tester.prepare_config_and_inputs_for_common()

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

     UpperCAmelCase			:      Dict			=			["""pixel_values"""]
     self.assertListEqual(arg_names[:1]   ,  _SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   str:





    '''simple docstring'''




    UpperCAmelCase			:      str			=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





    '''simple docstring'''




    UpperCAmelCase			:      Tuple			=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_backbone(*_SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





    '''simple docstring'''




    def check_hidden_states_output(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		):
     UpperCAmelCase			:      Union[str, Any]			=			model_class(_SCREAMING_SNAKE_CASE		)
     model.to(_SCREAMING_SNAKE_CASE		)
     model.eval()

     with torch.no_grad():
      UpperCAmelCase			:      Optional[Any]			=			model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)		)

     UpperCAmelCase			:      Optional[int]			=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

     UpperCAmelCase			:      Any			=			self.model_tester.num_stages
     self.assertEqual(len(_SCREAMING_SNAKE_CASE		)   ,  expected_num_stages + 1		)

     # ConvNext'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 // 4, self.model_tester.image_size // 4]   ,  )

    UpperCAmelCase			:      Optional[Any]			=			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
     UpperCAmelCase			:      Optional[int]			=			True
     check_hidden_states_output(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)

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

     check_hidden_states_output(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[Any]:





    '''simple docstring'''




    UpperCAmelCase			:      Any			=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE		)




   @slow
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





    '''simple docstring'''




    for model_name in CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     UpperCAmelCase			:      Dict			=			ConvNextModel.from_pretrained(_SCREAMING_SNAKE_CASE		)
     self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)

def    _snake_case		(		):
 UpperCAmelCase			:      Optional[int]			=			Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""		)
 return image



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

   @cached_property
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





    '''simple docstring'''




    return AutoImageProcessor.from_pretrained("""facebook/convnext-tiny-224"""		) if is_vision_available() else None




   @slow
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





    '''simple docstring'''




    UpperCAmelCase			:      str			=			ConvNextForImageClassification.from_pretrained("""facebook/convnext-tiny-224"""		).to(_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Optional[Any]			=			self.default_image_processor
    UpperCAmelCase			:      int			=			prepare_img()
    UpperCAmelCase			:      List[Any]			=			image_processor(images=_SCREAMING_SNAKE_CASE   ,  return_tensors="""pt"""		).to(_SCREAMING_SNAKE_CASE		)

    # forward pass
    with torch.no_grad():
     UpperCAmelCase			:      Union[str, Any]			=			model(**_SCREAMING_SNAKE_CASE		)

    # verify the logits
    UpperCAmelCase			:      Optional[int]			=			torch.Size((1, 1000)		)
    self.assertEqual(outputs.logits.shape   ,  _SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Optional[Any]			=			torch.tensor([-0.0260, -0.4739, 0.1911]		).to(_SCREAMING_SNAKE_CASE		)

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



@require_torch
class    SCREAMING_SNAKE_CASE__						(      unittest.TestCase   ,    UpperCAmelCase__				):
   __lowerCAmelCase						:     List[str]		=		(ConvNextBackbone,) if is_torch_available() else ()
   __lowerCAmelCase						:     List[str]		=		ConvNextConfig

   __lowerCAmelCase						:     Optional[Any]		=		False

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Optional[int]:





    '''simple docstring'''




    UpperCAmelCase			:      Tuple			=			ConvNextModelTester(self		)











"""simple docstring"""
import math
from datetime import datetime, timedelta

def    _snake_case		(		UpperCamelCase		:	int		):
 UpperCAmelCase			:      Any			=			year % 19
 UpperCAmelCase			:      Any			=			year % 4
 UpperCAmelCase			:      str			=			year % 7
 UpperCAmelCase			:      Union[str, Any]			=			math.floor(year / 100		)
 UpperCAmelCase			:      Optional[Any]			=			math.floor((13 + 8 * leap_day_inhibits) / 25		)
 UpperCAmelCase			:      int			=			leap_day_inhibits / 4
 UpperCAmelCase			:      int			=			(
     15 - lunar_orbit_correction + leap_day_inhibits - leap_day_reinstall_number
 ) % 30
 UpperCAmelCase			:      Tuple			=			(4 + leap_day_inhibits - leap_day_reinstall_number) % 7

 # days to be added to March 21
 UpperCAmelCase			:      int			=			(19 * metonic_cycle + secular_moon_shift) % 30

 # PHM -> Paschal Full Moon
 UpperCAmelCase			:      Tuple			=			(
     2 * julian_leap_year
     + 4 * non_leap_year
     + 6 * days_to_add
     + century_starting_point
 ) % 7

 if days_to_add == 29 and days_from_phm_to_sunday == 6:
  return datetime(UpperCamelCase    ,	4    ,	19		)
 elif days_to_add == 28 and days_from_phm_to_sunday == 6:
  return datetime(UpperCamelCase    ,	4    ,	18		)
 else:
  return datetime(UpperCamelCase    ,	3    ,	22		) + timedelta(
      days=int(days_to_add + days_from_phm_to_sunday		)		)


if __name__ == "__main__":
      for year in (1_9_9_4, 2_0_0_0, 2_0_1_0, 2_0_2_1, 2_0_2_3):
            A:     Any										=	"will be" if year > datetime.now().year else "was"
            print(f"""Easter in {year} {tense} {gauss_easter(year)}""")
