

'''simple docstring'''



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 		lowerCAmelCase__  ( SCREAMING_SNAKE_CASE_   ):



 """simple docstring"""



 lowerCAmelCase__       = 42







class 		lowerCAmelCase__  ( SCREAMING_SNAKE_CASE_					,   SCREAMING_SNAKE_CASE_   ):



 """simple docstring"""



 @register_to_config
 def __init__(						self   :			Optional[int]   ,				__SCREAMING_SNAKE_CASE   :			Dict = 65_536   ,				__SCREAMING_SNAKE_CASE   :			Tuple = None   ,				__SCREAMING_SNAKE_CASE   :			Any = 2   ,				__SCREAMING_SNAKE_CASE   :			List[Any] = 2   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any] = 0   ,				__SCREAMING_SNAKE_CASE   :			List[Any] = "fourier"   ,				__SCREAMING_SNAKE_CASE   :			List[Any] = True   ,				__SCREAMING_SNAKE_CASE   :			str = False   ,				__SCREAMING_SNAKE_CASE   :			Any = 0.0   ,				__SCREAMING_SNAKE_CASE   :			int = ("DownBlock1DNoSkip", "DownBlock1D", "AttnDownBlock1D")   ,				__SCREAMING_SNAKE_CASE   :			str = ("AttnUpBlock1D", "UpBlock1D", "UpBlock1DNoSkip")   ,				__SCREAMING_SNAKE_CASE   :			Optional[int] = "UNetMidBlock1D"   ,				__SCREAMING_SNAKE_CASE   :			List[str] = None   ,				__SCREAMING_SNAKE_CASE   :			int = (32, 32, 64)   ,				__SCREAMING_SNAKE_CASE   :			int = None   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any] = 8   ,				__SCREAMING_SNAKE_CASE   :			List[str] = 1   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any] = False   ,				)    ->					List[str]:


      """simple docstring"""




      super().__init__()
      __SCREAMING_SNAKE_CASE      = sample_size

      # time
      if time_embedding_type == "fourier":
           __SCREAMING_SNAKE_CASE      = GaussianFourierProjection(
               embedding_size=8   ,				set_W_to_weight=lowercase_   ,				log=lowercase_   ,				flip_sin_to_cos=lowercase_     )
           __SCREAMING_SNAKE_CASE      = 2 * block_out_channels[0]
      elif time_embedding_type == "positional":
           __SCREAMING_SNAKE_CASE      = Timesteps(
               block_out_channels[0]   ,				flip_sin_to_cos=lowercase_   ,				downscale_freq_shift=lowercase_     )
           __SCREAMING_SNAKE_CASE      = block_out_channels[0]

      if use_timestep_embedding:
           __SCREAMING_SNAKE_CASE      = block_out_channels[0] * 4
           __SCREAMING_SNAKE_CASE      = TimestepEmbedding(
               in_channels=lowercase_   ,				time_embed_dim=lowercase_   ,				act_fn=lowercase_   ,				out_dim=block_out_channels[0]   ,				)

      __SCREAMING_SNAKE_CASE      = nn.ModuleList([]     )
      __SCREAMING_SNAKE_CASE      = None
      __SCREAMING_SNAKE_CASE      = nn.ModuleList([]     )
      __SCREAMING_SNAKE_CASE      = None

      # down
      __SCREAMING_SNAKE_CASE      = in_channels
      for i, down_block_type in enumerate(lowercase_     ):
           __SCREAMING_SNAKE_CASE      = output_channel
           __SCREAMING_SNAKE_CASE      = block_out_channels[i]

           if i == 0:
                input_channel += extra_in_channels

           __SCREAMING_SNAKE_CASE      = i == len(lowercase_     ) - 1

           __SCREAMING_SNAKE_CASE      = get_down_block(
               lowercase_   ,				num_layers=lowercase_   ,				in_channels=lowercase_   ,				out_channels=lowercase_   ,				temb_channels=block_out_channels[0]   ,				add_downsample=not is_final_block or downsample_each_block   ,				)
           self.down_blocks.append(lowercase_     )

      # mid
      __SCREAMING_SNAKE_CASE      = get_mid_block(
          lowercase_   ,				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=lowercase_   ,				add_downsample=lowercase_   ,				)

      # up
      __SCREAMING_SNAKE_CASE      = list(reversed(lowercase_     )     )
      __SCREAMING_SNAKE_CASE      = reversed_block_out_channels[0]
      if out_block_type is None:
           __SCREAMING_SNAKE_CASE      = out_channels
      else:
           __SCREAMING_SNAKE_CASE      = block_out_channels[0]

      for i, up_block_type in enumerate(lowercase_     ):
           __SCREAMING_SNAKE_CASE      = output_channel
           __SCREAMING_SNAKE_CASE      = (
               reversed_block_out_channels[i + 1] if i < len(lowercase_     ) - 1 else final_upsample_channels
           )

           __SCREAMING_SNAKE_CASE      = i == len(lowercase_     ) - 1

           __SCREAMING_SNAKE_CASE      = get_up_block(
               lowercase_   ,				num_layers=lowercase_   ,				in_channels=lowercase_   ,				out_channels=lowercase_   ,				temb_channels=block_out_channels[0]   ,				add_upsample=not is_final_block   ,				)
           self.up_blocks.append(lowercase_     )
           __SCREAMING_SNAKE_CASE      = output_channel

      # out
      __SCREAMING_SNAKE_CASE      = norm_num_groups if norm_num_groups is not None else min(block_out_channels[0] // 4   ,				32     )
      __SCREAMING_SNAKE_CASE      = get_out_block(
          out_block_type=lowercase_   ,				num_groups_out=lowercase_   ,				embed_dim=block_out_channels[0]   ,				out_channels=lowercase_   ,				act_fn=lowercase_   ,				fc_dim=block_out_channels[-1] // 4   ,				)


 def  UpperCAmelCase__						(						self   :			Dict   ,				__SCREAMING_SNAKE_CASE   :			Union[str, Any]   ,				__SCREAMING_SNAKE_CASE   :			Union[str, Any]   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any] = True   ,				)    ->					Union[UNetaDOutput, Tuple]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = timestep
      if not torch.is_tensor(lowercase_     ):
           __SCREAMING_SNAKE_CASE      = torch.tensor([timesteps]   ,				dtype=torch.long   ,				device=sample.device     )
      elif torch.is_tensor(lowercase_     ) and len(timesteps.shape     ) == 0:
           __SCREAMING_SNAKE_CASE      = timesteps[None].to(sample.device     )

      __SCREAMING_SNAKE_CASE      = self.time_proj(lowercase_     )
      if self.config.use_timestep_embedding:
           __SCREAMING_SNAKE_CASE      = self.time_mlp(lowercase_     )
      else:
           __SCREAMING_SNAKE_CASE      = timestep_embed[..., None]
           __SCREAMING_SNAKE_CASE      = timestep_embed.repeat([1, 1, sample.shape[2]]     ).to(sample.dtype     )
           __SCREAMING_SNAKE_CASE      = timestep_embed.broadcast_to((sample.shape[:1] + timestep_embed.shape[1:])     )

      # 2. down
      __SCREAMING_SNAKE_CASE      = ()
      for downsample_block in self.down_blocks:
           __SCREAMING_SNAKE_CASE  ,     __SCREAMING_SNAKE_CASE      = downsample_block(hidden_states=lowercase_   ,				temb=lowercase_     )
           down_block_res_samples += res_samples

      # 3. mid
      if self.mid_block:
           __SCREAMING_SNAKE_CASE      = self.mid_block(lowercase_   ,				lowercase_     )

      # 4. up
      for i, upsample_block in enumerate(self.up_blocks     ):
           __SCREAMING_SNAKE_CASE      = down_block_res_samples[-1:]
           __SCREAMING_SNAKE_CASE      = down_block_res_samples[:-1]
           __SCREAMING_SNAKE_CASE      = upsample_block(lowercase_   ,				res_hidden_states_tuple=lowercase_   ,				temb=lowercase_     )

      # 5. post-process
      if self.out_block:
           __SCREAMING_SNAKE_CASE      = self.out_block(lowercase_   ,				lowercase_     )

      if not return_dict:
           return (sample,)

      return UNetaDOutput(sample=lowercase_     )








"""simple docstring"""

import math




def      lowercase__    (       lowerCAmelCase					:       str			,					lowerCAmelCase					:       Optional[Any]			)			->   List[Any]:






    """simple docstring"""




    if 0 not in (x, y):
        # We use the relation x^y = y*log10(x), where 10 is the base.
        return y * math.logaa(lowerCAmelCase			)
    else:
        if x == 0:  # 0 raised to any number is 0
            return 0
        elif y == 0:
            return 1  # any number raised to 0 is 1
    raise AssertionError('This should never happen'			)


if __name__ == "__main__":  # Main function
   # Read two numbers from input and typecast them to int using map function.
   # Here x is the base and y is the power.
   SCREAMING_SNAKE_CASE_            =    '''Enter the base and the power separated by a comma: '''
   SCREAMING_SNAKE_CASE_       ,    SCREAMING_SNAKE_CASE_            =    map(int, input(prompt).split(''','''))
   SCREAMING_SNAKE_CASE_       ,    SCREAMING_SNAKE_CASE_            =    map(int, input(prompt).split(''','''))

   # We find the log of each number, using the function res(), which takes two
   # arguments.
   SCREAMING_SNAKE_CASE_            =    res(xa, ya)
   SCREAMING_SNAKE_CASE_            =    res(xa, ya)

   # We check for the largest number
   if resa > resa:
      print('''Largest number is''', xa, '''^''', ya)
   elif resa > resa:
      print('''Largest number is''', xa, '''^''', ya)
   else:
      print('''Both are equal''')



