






"""simple docstring"""




from typing import Optional, Tuple, Union

import flax
import flax.linen as nn
import jax
import jax.numpy as jnp
from flax.core.frozen_dict import FrozenDict

from ..configuration_utils import ConfigMixin, flax_register_to_config
from ..utils import BaseOutput
from .embeddings_flax import FlaxTimestepEmbedding, FlaxTimesteps
from .modeling_flax_utils import FlaxModelMixin
from .unet_ad_blocks_flax import (
    FlaxCrossAttnDownBlockaD,
    FlaxCrossAttnUpBlockaD,
    FlaxDownBlockaD,
    FlaxUNetMidBlockaDCrossAttn,
    FlaxUpBlockaD,
)




@flax.struct.dataclass
class    lowercase_    (_UpperCAmelCase     ):
      A__	:		jnp.ndarray







@flax_register_to_config
class    lowercase_    (nn.Module,    _UpperCAmelCase,    _UpperCAmelCase     ):
      A__	:		int       			=				32
      A__	:		int       			=				4
      A__	:		int       			=				4
      A__	:		Tuple[str]       			=				(
          "CrossAttnDownBlock2D",
          "CrossAttnDownBlock2D",
          "CrossAttnDownBlock2D",
          "DownBlock2D",
      )
      A__	:		Tuple[str]       			=				("UpBlock2D", "CrossAttnUpBlock2D", "CrossAttnUpBlock2D", "CrossAttnUpBlock2D")
      A__	:		Union[bool, Tuple[bool]]       			=				False
      A__	:		Tuple[int]       			=				(320, 640, 1280, 1280)
      A__	:		int       			=				2
      A__	:		Union[int, Tuple[int]]       			=				8
      A__	:		Optional[Union[int, Tuple[int]]]       			=				None
      A__	:		int       			=				1280
      A__	:		float       			=				0.0
      A__	:		bool       			=				False
      A__	:		jnp.dtype       			=				jnp.floataa
      A__	:		bool       			=				True
      A__	:		int       			=				0
      A__	:		bool       			=				False






      def 			lowerCamelCase__    (    self     ,     a_	)	->FrozenDict:







        '''simple docstring'''


        _a							=	(1, self.in_channels, self.sample_size, self.sample_size)
        _a							=	jnp.zeros(a_     ,     dtype=jnp.floataa	)
        _a							=	jnp.ones((1,)     ,     dtype=jnp.intaa	)
        _a							=	jnp.zeros((1, 1, self.cross_attention_dim)     ,     dtype=jnp.floataa	)

        _a			,	_a							=	jax.random.split(a_	)
        _a							=	{"params": params_rng, "dropout": dropout_rng}

        return self.init(a_     ,     a_     ,     a_     ,     a_	)["params"]






      def 			lowerCamelCase__    (    self	)	->str:







        '''simple docstring'''


        _a							=	self.block_out_channels
        _a							=	block_out_channels[0] * 4

        if self.num_attention_heads is not None:
          raise ValueError(
              "At the moment it is not possible to define the number of attention heads via `num_attention_heads` because of a naming issue as described in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131. Passing `num_attention_heads` will only be supported in diffusers v0.19."	)

        # If `num_attention_heads` is not defined (which is the case for most models)
        # it will default to `attention_head_dim`. This looks weird upon first reading it and it is.
        # The reason for this behavior is to correct for incorrectly named variables that were introduced
        # when this library was created. The incorrect naming was only discovered much later in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131
        # Changing `attention_head_dim` to `num_attention_heads` for 40,000+ configurations is too backwards breaking
        # which is why we correct for the naming here.
        _a							=	self.num_attention_heads or self.attention_head_dim

        # input
        _a							=	nn.Conv(
            block_out_channels[0]     ,     kernel_size=(3, 3)     ,     strides=(1, 1)     ,     padding=((1, 1), (1, 1))     ,     dtype=self.dtype     ,     )

        # time
        _a							=	FlaxTimesteps(
            block_out_channels[0]     ,     flip_sin_to_cos=self.flip_sin_to_cos     ,     freq_shift=self.config.freq_shift	)
        _a							=	FlaxTimestepEmbedding(a_     ,     dtype=self.dtype	)

        _a							=	self.only_cross_attention
        if isinstance(a_     ,     a_	):
          _a							=	(only_cross_attention,) * len(self.down_block_types	)

        if isinstance(a_     ,     a_	):
          _a							=	(num_attention_heads,) * len(self.down_block_types	)

        # down
        _a							=	[]
        _a							=	block_out_channels[0]
        for i, down_block_type in enumerate(self.down_block_types	):
          _a							=	output_channel
          _a							=	block_out_channels[i]
          _a							=	i == len(a_	) - 1

          if down_block_type == "CrossAttnDownBlock2D":
            _a							=	FlaxCrossAttnDownBlockaD(
                in_channels=a_     ,     out_channels=a_     ,     dropout=self.dropout     ,     num_layers=self.layers_per_block     ,     num_attention_heads=num_attention_heads[i]     ,     add_downsample=not is_final_block     ,     use_linear_projection=self.use_linear_projection     ,     only_cross_attention=only_cross_attention[i]     ,     use_memory_efficient_attention=self.use_memory_efficient_attention     ,     dtype=self.dtype     ,     )
          else:
            _a							=	FlaxDownBlockaD(
                in_channels=a_     ,     out_channels=a_     ,     dropout=self.dropout     ,     num_layers=self.layers_per_block     ,     add_downsample=not is_final_block     ,     dtype=self.dtype     ,     )

          down_blocks.append(a_	)
        _a							=	down_blocks

        # mid
        _a							=	FlaxUNetMidBlockaDCrossAttn(
            in_channels=block_out_channels[-1]     ,     dropout=self.dropout     ,     num_attention_heads=num_attention_heads[-1]     ,     use_linear_projection=self.use_linear_projection     ,     use_memory_efficient_attention=self.use_memory_efficient_attention     ,     dtype=self.dtype     ,     )

        # up
        _a							=	[]
        _a							=	list(reversed(a_	)	)
        _a							=	list(reversed(a_	)	)
        _a							=	list(reversed(a_	)	)
        _a							=	reversed_block_out_channels[0]
        for i, up_block_type in enumerate(self.up_block_types	):
          _a							=	output_channel
          _a							=	reversed_block_out_channels[i]
          _a							=	reversed_block_out_channels[min(i + 1     ,     len(a_	) - 1	)]

          _a							=	i == len(a_	) - 1

          if up_block_type == "CrossAttnUpBlock2D":
            _a							=	FlaxCrossAttnUpBlockaD(
                in_channels=a_     ,     out_channels=a_     ,     prev_output_channel=a_     ,     num_layers=self.layers_per_block + 1     ,     num_attention_heads=reversed_num_attention_heads[i]     ,     add_upsample=not is_final_block     ,     dropout=self.dropout     ,     use_linear_projection=self.use_linear_projection     ,     only_cross_attention=only_cross_attention[i]     ,     use_memory_efficient_attention=self.use_memory_efficient_attention     ,     dtype=self.dtype     ,     )
          else:
            _a							=	FlaxUpBlockaD(
                in_channels=a_     ,     out_channels=a_     ,     prev_output_channel=a_     ,     num_layers=self.layers_per_block + 1     ,     add_upsample=not is_final_block     ,     dropout=self.dropout     ,     dtype=self.dtype     ,     )

          up_blocks.append(a_	)
          _a							=	output_channel
        _a							=	up_blocks

        # out
        _a							=	nn.GroupNorm(num_groups=3_2     ,     epsilon=1E-5	)
        _a							=	nn.Conv(
            self.out_channels     ,     kernel_size=(3, 3)     ,     strides=(1, 1)     ,     padding=((1, 1), (1, 1))     ,     dtype=self.dtype     ,     )






      def __call__(    self     ,     a_     ,     a_     ,     a_     ,     a_=None     ,     a_=None     ,     a_ = True     ,     a_ = False     ,     )	->Union[FlaxUNetaDConditionOutput, Tuple]:







        '''simple docstring'''


        if not isinstance(a_     ,     jnp.ndarray	):
          _a							=	jnp.array([timesteps]     ,     dtype=jnp.intaa	)
        elif isinstance(a_     ,     jnp.ndarray	) and len(timesteps.shape	) == 0:
          _a							=	timesteps.astype(dtype=jnp.floataa	)
          _a							=	jnp.expand_dims(a_     ,     0	)

        _a							=	self.time_proj(a_	)
        _a							=	self.time_embedding(a_	)

        # 2. pre-process
        _a							=	jnp.transpose(a_     ,     (0, 2, 3, 1)	)
        _a							=	self.conv_in(a_	)

        # 3. down
        _a							=	(sample,)
        for down_block in self.down_blocks:
          if isinstance(a_     ,     a_	):
            _a			,	_a							=	down_block(a_     ,     a_     ,     a_     ,     deterministic=not train	)
          else:
            _a			,	_a							=	down_block(a_     ,     a_     ,     deterministic=not train	)
          down_block_res_samples += res_samples

        if down_block_additional_residuals is not None:
          _a							=	()

          for down_block_res_sample, down_block_additional_residual in zip(
              a_     ,     a_	):
            down_block_res_sample += down_block_additional_residual
            new_down_block_res_samples += (down_block_res_sample,)

          _a							=	new_down_block_res_samples

        # 4. mid
        _a							=	self.mid_block(a_     ,     a_     ,     a_     ,     deterministic=not train	)

        if mid_block_additional_residual is not None:
          sample += mid_block_additional_residual

        # 5. up
        for up_block in self.up_blocks:
          _a							=	down_block_res_samples[-(self.layers_per_block + 1) :]
          _a							=	down_block_res_samples[: -(self.layers_per_block + 1)]
          if isinstance(a_     ,     a_	):
            _a							=	up_block(
                a_     ,     temb=a_     ,     encoder_hidden_states=a_     ,     res_hidden_states_tuple=a_     ,     deterministic=not train     ,     )
          else:
            _a							=	up_block(a_     ,     temb=a_     ,     res_hidden_states_tuple=a_     ,     deterministic=not train	)

        # 6. post-process
        _a							=	self.conv_norm_out(a_	)
        _a							=	nn.silu(a_	)
        _a							=	self.conv_out(a_	)
        _a							=	jnp.transpose(a_     ,     (0, 3, 1, 2)	)

        if not return_dict:
          return (sample,)

        return FlaxUNetaDConditionOutput(sample=a_	)










"""simple docstring"""




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







  '''simple docstring'''







  _a							=	(boundary[1] - boundary[0]) / steps
  _a							=	boundary[0]
  _a							=	boundary[1]
  _a							=	make_points(UpperCamelCase_     , UpperCamelCase_     , UpperCamelCase_					)
  _a							=	0.0
  y += (h / 2.0) * f(UpperCamelCase_					)
  for i in x_i:
    # print(i)
    y += h * f(UpperCamelCase_					)
  y += (h / 2.0) * f(UpperCamelCase_					)
  return y






def        lowerCAmelCase (      UpperCamelCase_:							str     , UpperCamelCase_:							Any     , UpperCamelCase_:							Any					)       ->							str:







  '''simple docstring'''







  _a							=	a + h
  while x < (b - h):
    yield x
    _a							=	x + h






def        lowerCAmelCase (      UpperCamelCase_:							List[str]					)       ->							int:  # enter your function here







  '''simple docstring'''







  _a							=	(x - 0) * (x - 0)
  return y






def        lowerCAmelCase (      )       ->							Tuple:







  '''simple docstring'''







  _a							=	0.0  # Lower bound of integration
  _a							=	1.0  # Upper bound of integration
  _a							=	10.0  # define number of steps or resolution
  _a							=	[a, b]  # define boundary of integration
  _a							=	method_a(UpperCamelCase_     , UpperCamelCase_					)
  print(f'''y = {y}'''					)


if __name__ == "__main__":
     main()


