




"""simple docstring"""

import math
from datetime import datetime, timedelta






def 		_snake_case	(   _snake_case				:   int				)       ->   datetime:






      '''simple docstring'''


      _A     =  year % 19
      _A     =  year % 4
      _A     =  year % 7
      _A     =  math.floor(year / 1_00				)
      _A     =  math.floor((13 + 8 * leap_day_inhibits) / 25				)
      _A     =  leap_day_inhibits / 4
      _A     =  (
          15 - lunar_orbit_correction + leap_day_inhibits - leap_day_reinstall_number
      ) % 30
      _A     =  (4 + leap_day_inhibits - leap_day_reinstall_number) % 7

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

      # PHM -> Paschal Full Moon
      _A     =  (
          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(_snake_case							,    4							,    19				)
      elif days_to_add == 28 and days_from_phm_to_sunday == 6:
            return datetime(_snake_case							,    4							,    18				)
      else:
            return datetime(_snake_case							,    3							,    22				) + timedelta(
                days=int(days_to_add + days_from_phm_to_sunday				)				)


if __name__ == "__main__":
       for year in (1_994, 2_000, 2_010, 2_021, 2_023):
              a							      =     '''will be''' if year > datetime.now().year else '''was'''
              print(F'''Easter in {year} {tense} {gauss_easter(year)}''')


from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .embeddings import GaussianFourierProjection, TimestepEmbedding, Timesteps
from .modeling_utils import ModelMixin
from .unet_ad_blocks import get_down_block, get_mid_block, get_out_block, get_up_block

@dataclass
class 					_lowercase    (     UpperCAmelCase__			):






    '''simple docstring'''
    SCREAMING_SNAKE_CASE:				torch.FloatTensor





class 					_lowercase    (     UpperCAmelCase__ ,  UpperCAmelCase__			):






    '''simple docstring'''




    @register_to_config
    def __init__(    self       ,						lowerCamelCase__ = 65_536       ,						lowerCamelCase__ = None       ,						lowerCamelCase__ = 2       ,						lowerCamelCase__ = 2       ,						lowerCamelCase__ = 0       ,						lowerCamelCase__ = "fourier"       ,						lowerCamelCase__ = True       ,						lowerCamelCase__ = False       ,						lowerCamelCase__ = 0.0       ,						lowerCamelCase__ = ("DownBlock1DNoSkip", "DownBlock1D", "AttnDownBlock1D")       ,						lowerCamelCase__ = ("AttnUpBlock1D", "UpBlock1D", "UpBlock1DNoSkip")       ,						lowerCamelCase__ = "UNetMidBlock1D"       ,						lowerCamelCase__ = None       ,						lowerCamelCase__ = (32, 32, 64)       ,						lowerCamelCase__ = None       ,						lowerCamelCase__ = 8       ,						lowerCamelCase__ = 1       ,						lowerCamelCase__ = False       ,						):
       super().__init__()
       lowerCAmelCase_:							Optional[Any]       =	sample_size

       # time
       if time_embedding_type == "fourier":
          lowerCAmelCase_:							Dict       =	GaussianFourierProjection(
              embedding_size=8       ,						set_W_to_weight=lowerCamelCase__       ,						log=lowerCamelCase__       ,						flip_sin_to_cos=lowerCamelCase__ )
          lowerCAmelCase_:							List[str]       =	2 * block_out_channels[0]
       elif time_embedding_type == "positional":
          lowerCAmelCase_:							Tuple       =	Timesteps(
              block_out_channels[0]       ,						flip_sin_to_cos=lowerCamelCase__       ,						downscale_freq_shift=lowerCamelCase__ )
          lowerCAmelCase_:							Dict       =	block_out_channels[0]

       if use_timestep_embedding:
          lowerCAmelCase_:							Tuple       =	block_out_channels[0] * 4
          lowerCAmelCase_:							Any       =	TimestepEmbedding(
              in_channels=lowerCamelCase__       ,						time_embed_dim=lowerCamelCase__       ,						act_fn=lowerCamelCase__       ,						out_dim=block_out_channels[0]       ,						)

       lowerCAmelCase_:							str       =	nn.ModuleList([] )
       lowerCAmelCase_:							Dict       =	None
       lowerCAmelCase_:							Optional[Any]       =	nn.ModuleList([] )
       lowerCAmelCase_:							int       =	None

       # down
       lowerCAmelCase_:							List[str]       =	in_channels
       for i, down_block_type in enumerate(lowerCamelCase__ ):
          lowerCAmelCase_:							Optional[int]       =	output_channel
          lowerCAmelCase_:							Optional[Any]       =	block_out_channels[i]

          if i == 0:
             input_channel += extra_in_channels

          lowerCAmelCase_:							List[str]       =	i == len(lowerCamelCase__ ) - 1

          lowerCAmelCase_:							List[str]       =	get_down_block(
              lowerCamelCase__       ,						num_layers=lowerCamelCase__       ,						in_channels=lowerCamelCase__       ,						out_channels=lowerCamelCase__       ,						temb_channels=block_out_channels[0]       ,						add_downsample=not is_final_block or downsample_each_block       ,						)
          self.down_blocks.append(lowerCamelCase__ )

       # mid
       lowerCAmelCase_:							Optional[int]       =	get_mid_block(
           lowerCamelCase__       ,						in_channels=block_out_channels[-1]       ,						mid_channels=block_out_channels[-1]       ,						out_channels=block_out_channels[-1]       ,						embed_dim=block_out_channels[0]       ,						num_layers=lowerCamelCase__       ,						add_downsample=lowerCamelCase__       ,						)

       # up
       lowerCAmelCase_:							Dict       =	list(reversed(lowerCamelCase__ ) )
       lowerCAmelCase_:							Any       =	reversed_block_out_channels[0]
       if out_block_type is None:
          lowerCAmelCase_:							str       =	out_channels
       else:
          lowerCAmelCase_:							Any       =	block_out_channels[0]

       for i, up_block_type in enumerate(lowerCamelCase__ ):
          lowerCAmelCase_:							Dict       =	output_channel
          lowerCAmelCase_:							int       =	(
              reversed_block_out_channels[i + 1] if i < len(lowerCamelCase__ ) - 1 else final_upsample_channels
          )

          lowerCAmelCase_:							Optional[int]       =	i == len(lowerCamelCase__ ) - 1

          lowerCAmelCase_:							Union[str, Any]       =	get_up_block(
              lowerCamelCase__       ,						num_layers=lowerCamelCase__       ,						in_channels=lowerCamelCase__       ,						out_channels=lowerCamelCase__       ,						temb_channels=block_out_channels[0]       ,						add_upsample=not is_final_block       ,						)
          self.up_blocks.append(lowerCamelCase__ )
          lowerCAmelCase_:							str       =	output_channel

       # out
       lowerCAmelCase_:							List[str]       =	norm_num_groups if norm_num_groups is not None else min(block_out_channels[0] // 4       ,						32 )
       lowerCAmelCase_:							int       =	get_out_block(
           out_block_type=lowerCamelCase__       ,						num_groups_out=lowerCamelCase__       ,						embed_dim=block_out_channels[0]       ,						out_channels=lowerCamelCase__       ,						act_fn=lowerCamelCase__       ,						fc_dim=block_out_channels[-1] // 4       ,						)




    def      _a    (    self       ,						lowerCamelCase__       ,						lowerCamelCase__       ,						lowerCamelCase__ = True       ,						):
       lowerCAmelCase_:							Any       =	timestep
       if not torch.is_tensor(lowerCamelCase__ ):
          lowerCAmelCase_:							Optional[Any]       =	torch.tensor([timesteps]       ,						dtype=torch.long       ,						device=sample.device )
       elif torch.is_tensor(lowerCamelCase__ ) and len(timesteps.shape ) == 0:
          lowerCAmelCase_:							List[Any]       =	timesteps[None].to(sample.device )

       lowerCAmelCase_:							Union[str, Any]       =	self.time_proj(lowerCamelCase__ )
       if self.config.use_timestep_embedding:
          lowerCAmelCase_:							Any       =	self.time_mlp(lowerCamelCase__ )
       else:
          lowerCAmelCase_:							Any       =	timestep_embed[..., None]
          lowerCAmelCase_:							str       =	timestep_embed.repeat([1, 1, sample.shape[2]] ).to(sample.dtype )
          lowerCAmelCase_:							Dict       =	timestep_embed.broadcast_to((sample.shape[:1] + timestep_embed.shape[1:]) )

       # 2. down
       lowerCAmelCase_:							Dict       =	()
       for downsample_block in self.down_blocks:
          lowerCAmelCase_  ,	lowerCAmelCase_:							Optional[int]       =	downsample_block(hidden_states=lowerCamelCase__       ,						temb=lowerCamelCase__ )
          down_block_res_samples += res_samples

       # 3. mid
       if self.mid_block:
          lowerCAmelCase_:							int       =	self.mid_block(lowerCamelCase__       ,						lowerCamelCase__ )

       # 4. up
       for i, upsample_block in enumerate(self.up_blocks ):
          lowerCAmelCase_:							Any       =	down_block_res_samples[-1:]
          lowerCAmelCase_:							str       =	down_block_res_samples[:-1]
          lowerCAmelCase_:							List[str]       =	upsample_block(lowerCamelCase__       ,						res_hidden_states_tuple=lowerCamelCase__       ,						temb=lowerCamelCase__ )

       # 5. post-process
       if self.out_block:
          lowerCAmelCase_:							Any       =	self.out_block(lowerCamelCase__       ,						lowerCamelCase__ )

       if not return_dict:
          return (sample,)

       return UNetaDOutput(sample=lowerCamelCase__ )