





"""simple docstring"""





import flax.linen as nn
import jax.numpy as jnp

from .attention_flax import FlaxTransformeraDModel
from .resnet_flax import FlaxDownsampleaD, FlaxResnetBlockaD, FlaxUpsampleaD

class 		lowercase					(					nn.Module					):
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      0.0
      _SCREAMING_SNAKE_CASE					=      1
      _SCREAMING_SNAKE_CASE					=      1
      _SCREAMING_SNAKE_CASE					=      True
      _SCREAMING_SNAKE_CASE					=      False
      _SCREAMING_SNAKE_CASE					=      False
      _SCREAMING_SNAKE_CASE					=      False
      _SCREAMING_SNAKE_CASE					=      jnp.floataa





      def     _snake_case			(       self )		->     Tuple:
            lowerCAmelCase  						=       []
            lowerCAmelCase  						=       []

            for i in range(self.num_layers ):
                  lowerCAmelCase  						=       self.in_channels if i == 0 else self.out_channels

                  lowerCAmelCase  						=       FlaxResnetBlockaD(
                      in_channels=lowercase      ,						out_channels=self.out_channels      ,						dropout_prob=self.dropout      ,						dtype=self.dtype      ,						)
                  resnets.append(lowercase )

                  lowerCAmelCase  						=       FlaxTransformeraDModel(
                      in_channels=self.out_channels      ,						n_heads=self.num_attention_heads      ,						d_head=self.out_channels // self.num_attention_heads      ,						depth=1      ,						use_linear_projection=self.use_linear_projection      ,						only_cross_attention=self.only_cross_attention      ,						use_memory_efficient_attention=self.use_memory_efficient_attention      ,						dtype=self.dtype      ,						)
                  attentions.append(lowercase )

            lowerCAmelCase  						=       resnets
            lowerCAmelCase  						=       attentions

            if self.add_downsample:
                  lowerCAmelCase  						=       FlaxDownsampleaD(self.out_channels      ,						dtype=self.dtype )





      def __call__(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase=True )		->     Optional[Any]:
            lowerCAmelCase  						=       ()

            for resnet, attn in zip(self.resnets      ,						self.attentions ):
                  lowerCAmelCase  						=       resnet(lowercase      ,						lowercase      ,						deterministic=lowercase )
                  lowerCAmelCase  						=       attn(lowercase      ,						lowercase      ,						deterministic=lowercase )
                  output_states += (hidden_states,)

            if self.add_downsample:
                  lowerCAmelCase  						=       self.downsamplers_a(lowercase )
                  output_states += (hidden_states,)

            return hidden_states, output_states







class 		lowercase					(					nn.Module					):
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      0.0
      _SCREAMING_SNAKE_CASE					=      1
      _SCREAMING_SNAKE_CASE					=      True
      _SCREAMING_SNAKE_CASE					=      jnp.floataa





      def     _snake_case			(       self )		->     Optional[Any]:
            lowerCAmelCase  						=       []

            for i in range(self.num_layers ):
                  lowerCAmelCase  						=       self.in_channels if i == 0 else self.out_channels

                  lowerCAmelCase  						=       FlaxResnetBlockaD(
                      in_channels=lowercase      ,						out_channels=self.out_channels      ,						dropout_prob=self.dropout      ,						dtype=self.dtype      ,						)
                  resnets.append(lowercase )
            lowerCAmelCase  						=       resnets

            if self.add_downsample:
                  lowerCAmelCase  						=       FlaxDownsampleaD(self.out_channels      ,						dtype=self.dtype )





      def __call__(       self      ,						lowercase      ,						lowercase      ,						lowercase=True )		->     Tuple:
            lowerCAmelCase  						=       ()

            for resnet in self.resnets:
                  lowerCAmelCase  						=       resnet(lowercase      ,						lowercase      ,						deterministic=lowercase )
                  output_states += (hidden_states,)

            if self.add_downsample:
                  lowerCAmelCase  						=       self.downsamplers_a(lowercase )
                  output_states += (hidden_states,)

            return hidden_states, output_states







class 		lowercase					(					nn.Module					):
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      0.0
      _SCREAMING_SNAKE_CASE					=      1
      _SCREAMING_SNAKE_CASE					=      1
      _SCREAMING_SNAKE_CASE					=      True
      _SCREAMING_SNAKE_CASE					=      False
      _SCREAMING_SNAKE_CASE					=      False
      _SCREAMING_SNAKE_CASE					=      False
      _SCREAMING_SNAKE_CASE					=      jnp.floataa





      def     _snake_case			(       self )		->     Tuple:
            lowerCAmelCase  						=       []
            lowerCAmelCase  						=       []

            for i in range(self.num_layers ):
                  lowerCAmelCase  						=       self.in_channels if (i == self.num_layers - 1) else self.out_channels
                  lowerCAmelCase  						=       self.prev_output_channel if i == 0 else self.out_channels

                  lowerCAmelCase  						=       FlaxResnetBlockaD(
                      in_channels=resnet_in_channels + res_skip_channels      ,						out_channels=self.out_channels      ,						dropout_prob=self.dropout      ,						dtype=self.dtype      ,						)
                  resnets.append(lowercase )

                  lowerCAmelCase  						=       FlaxTransformeraDModel(
                      in_channels=self.out_channels      ,						n_heads=self.num_attention_heads      ,						d_head=self.out_channels // self.num_attention_heads      ,						depth=1      ,						use_linear_projection=self.use_linear_projection      ,						only_cross_attention=self.only_cross_attention      ,						use_memory_efficient_attention=self.use_memory_efficient_attention      ,						dtype=self.dtype      ,						)
                  attentions.append(lowercase )

            lowerCAmelCase  						=       resnets
            lowerCAmelCase  						=       attentions

            if self.add_upsample:
                  lowerCAmelCase  						=       FlaxUpsampleaD(self.out_channels      ,						dtype=self.dtype )





      def __call__(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase=True )		->     Any:
            for resnet, attn in zip(self.resnets      ,						self.attentions ):
                  # pop res hidden states
                  lowerCAmelCase  						=       res_hidden_states_tuple[-1]
                  lowerCAmelCase  						=       res_hidden_states_tuple[:-1]
                  lowerCAmelCase  						=       jnp.concatenate((hidden_states, res_hidden_states)      ,						axis=-1 )

                  lowerCAmelCase  						=       resnet(lowercase      ,						lowercase      ,						deterministic=lowercase )
                  lowerCAmelCase  						=       attn(lowercase      ,						lowercase      ,						deterministic=lowercase )

            if self.add_upsample:
                  lowerCAmelCase  						=       self.upsamplers_a(lowercase )

            return hidden_states







class 		lowercase					(					nn.Module					):
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      0.0
      _SCREAMING_SNAKE_CASE					=      1
      _SCREAMING_SNAKE_CASE					=      True
      _SCREAMING_SNAKE_CASE					=      jnp.floataa





      def     _snake_case			(       self )		->     Any:
            lowerCAmelCase  						=       []

            for i in range(self.num_layers ):
                  lowerCAmelCase  						=       self.in_channels if (i == self.num_layers - 1) else self.out_channels
                  lowerCAmelCase  						=       self.prev_output_channel if i == 0 else self.out_channels

                  lowerCAmelCase  						=       FlaxResnetBlockaD(
                      in_channels=resnet_in_channels + res_skip_channels      ,						out_channels=self.out_channels      ,						dropout_prob=self.dropout      ,						dtype=self.dtype      ,						)
                  resnets.append(lowercase )

            lowerCAmelCase  						=       resnets

            if self.add_upsample:
                  lowerCAmelCase  						=       FlaxUpsampleaD(self.out_channels      ,						dtype=self.dtype )





      def __call__(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase=True )		->     str:
            for resnet in self.resnets:
                  # pop res hidden states
                  lowerCAmelCase  						=       res_hidden_states_tuple[-1]
                  lowerCAmelCase  						=       res_hidden_states_tuple[:-1]
                  lowerCAmelCase  						=       jnp.concatenate((hidden_states, res_hidden_states)      ,						axis=-1 )

                  lowerCAmelCase  						=       resnet(lowercase      ,						lowercase      ,						deterministic=lowercase )

            if self.add_upsample:
                  lowerCAmelCase  						=       self.upsamplers_a(lowercase )

            return hidden_states







class 		lowercase					(					nn.Module					):
      _SCREAMING_SNAKE_CASE					=      42
      _SCREAMING_SNAKE_CASE					=      0.0
      _SCREAMING_SNAKE_CASE					=      1
      _SCREAMING_SNAKE_CASE					=      1
      _SCREAMING_SNAKE_CASE					=      False
      _SCREAMING_SNAKE_CASE					=      False
      _SCREAMING_SNAKE_CASE					=      jnp.floataa





      def     _snake_case			(       self )		->     Any:
            # there is always at least one resnet
            lowerCAmelCase  						=       [
                FlaxResnetBlockaD(
                    in_channels=self.in_channels      ,						out_channels=self.in_channels      ,						dropout_prob=self.dropout      ,						dtype=self.dtype      ,						)
            ]

            lowerCAmelCase  						=       []

            for _ in range(self.num_layers ):
                  lowerCAmelCase  						=       FlaxTransformeraDModel(
                      in_channels=self.in_channels      ,						n_heads=self.num_attention_heads      ,						d_head=self.in_channels // self.num_attention_heads      ,						depth=1      ,						use_linear_projection=self.use_linear_projection      ,						use_memory_efficient_attention=self.use_memory_efficient_attention      ,						dtype=self.dtype      ,						)
                  attentions.append(lowercase )

                  lowerCAmelCase  						=       FlaxResnetBlockaD(
                      in_channels=self.in_channels      ,						out_channels=self.in_channels      ,						dropout_prob=self.dropout      ,						dtype=self.dtype      ,						)
                  resnets.append(lowercase )

            lowerCAmelCase  						=       resnets
            lowerCAmelCase  						=       attentions





      def __call__(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase=True )		->     Optional[int]:
            lowerCAmelCase  						=       self.resnets[0](lowercase      ,						lowercase )
            for attn, resnet in zip(self.attentions      ,						self.resnets[1:] ):
                  lowerCAmelCase  						=       attn(lowercase      ,						lowercase      ,						deterministic=lowercase )
                  lowerCAmelCase  						=       resnet(lowercase      ,						lowercase      ,						deterministic=lowercase )

            return hidden_states













def      _A       (		SCREAMING_SNAKE_CASE     :   list						):





  """simple docstring"""



  if not isinstance(SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE						):
    raise ValueError("Input series is not valid, valid series - [2, 4, 6]"						)
  if len(SCREAMING_SNAKE_CASE						) == 0:
    raise ValueError("Input list must be a non empty list"						)
  if len(SCREAMING_SNAKE_CASE						) == 1:
    return True
  a__	:					Union[str, Any]										=series[1] - series[0]
  for index in range(len(SCREAMING_SNAKE_CASE						) - 1						):
    if series[index + 1] - series[index] != common_diff:
      return False
  return True
def      _A       (		SCREAMING_SNAKE_CASE     :   list						):





  """simple docstring"""



  if not isinstance(SCREAMING_SNAKE_CASE       ,       SCREAMING_SNAKE_CASE						):
    raise ValueError("Input series is not valid, valid series - [2, 4, 6]"						)
  if len(SCREAMING_SNAKE_CASE						) == 0:
    raise ValueError("Input list must be a non empty list"						)
  a__	:					Any										=0
  for val in series:
    answer += val
  return answer / len(SCREAMING_SNAKE_CASE						)


if __name__ == "__main__":
     import doctest

     doctest.testmod()






