






import numpy as np

UpperCamelCase								=		[
    ["a", "b", "c", "d", "e"],
    ["f", "g", "h", "i", "k"],
    ["l", "m", "n", "o", "p"],
    ["q", "r", "s", "t", "u"],
    ["v", "w", "x", "y", "z"],
]

class 				lowerCAmelCase_	:


				def __init__(					self      ):
											_lowercase							:   Any 							=   np.array(_lowerCAmelCase      )


				def 						__a					(					self ,						_lowerCAmelCase      ):
											_lowercase							,							_lowercase							:   List[str] 							=   np.where(letter == self.SQUARE      )
											_lowercase							:   Optional[int] 							=   np.concatenate([indexa + 1, indexa + 1]      )
											return indexes


				def 						__a					(					self ,						_lowerCAmelCase ,						_lowerCAmelCase      ):
											_lowercase							:   int 							=   self.SQUARE[indexa - 1, indexa - 1]
											return letter


				def 						__a					(					self ,						_lowerCAmelCase      ):
											_lowercase							:   int 							=   message.lower()
											_lowercase							:   Optional[Any] 							=   message.replace(' ' ,						''      )
											_lowercase							:   Optional[Any] 							=   message.replace('j' ,						'i'      )

											_lowercase							:   Optional[int] 							=   np.empty((2, len(_lowerCAmelCase      ))      )
											for letter_index in range(len(_lowerCAmelCase      )      ):
																		_lowercase							:   Any 							=   self.letter_to_numbers(message[letter_index]      )

																		_lowercase							:   Tuple 							=   numbers[0]
																		_lowercase							:   int 							=   numbers[1]

											_lowercase							:   int 							=   first_step.reshape(2 * len(_lowerCAmelCase      )      )
											_lowercase							:   Tuple 							=   ''
											for numbers_index in range(len(_lowerCAmelCase      )      ):
																		_lowercase							:   int 							=   int(second_step[numbers_index * 2]      )
																		_lowercase							:   List[Any] 							=   int(second_step[(numbers_index * 2) + 1]      )
																		_lowercase							:   Optional[int] 							=   self.numbers_to_letter(_lowerCAmelCase ,						_lowerCAmelCase      )
																		_lowercase							:   List[Any] 							=   encoded_message + letter

											return encoded_message


				def 						__a					(					self ,						_lowerCAmelCase      ):
											_lowercase							:   Tuple 							=   message.lower()
											message.replace(' ' ,						''      )
											_lowercase							:   Optional[Any] 							=   np.empty(2 * len(_lowerCAmelCase      )      )
											for letter_index in range(len(_lowerCAmelCase      )      ):
																		_lowercase							:   List[Any] 							=   self.letter_to_numbers(message[letter_index]      )
																		_lowercase							:   int 							=   numbers[0]
																		_lowercase							:   Union[str, Any] 							=   numbers[1]

											_lowercase							:   Optional[int] 							=   first_step.reshape((2, len(_lowerCAmelCase      ))      )
											_lowercase							:   Tuple 							=   ''
											for numbers_index in range(len(_lowerCAmelCase      )      ):
																		_lowercase							:   Tuple 							=   int(second_step[0, numbers_index]      )
																		_lowercase							:   Dict 							=   int(second_step[1, numbers_index]      )
																		_lowercase							:   List[Any] 							=   self.numbers_to_letter(_lowerCAmelCase ,						_lowerCAmelCase      )
																		_lowercase							:   Dict 							=   decoded_message + letter

											return decoded_message






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

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




class 			UpperCAmelCase_     (					nn.Module	):


  '''simple docstring'''







  a__       			=						42
  a__       			=						42
  a__       			=						0.0
  a__       			=						1
  a__       			=						1
  a__       			=						True
  a__       			=						False
  a__       			=						False
  a__       			=						False
  a__       			=						jnp.floataa
  def 				_lowercase				(					self     :					Optional[Any]       )     ->      Tuple:







    """simple docstring"""






    __magic_name__								=			[]
    __magic_name__								=			[]

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

      __magic_name__								=			FlaxResnetBlockaD(
          in_channels=UpperCamelCase__     ,				out_channels=self.out_channels     ,				dropout_prob=self.dropout     ,				dtype=self.dtype     ,				)
      resnets.append(UpperCamelCase__       )

      __magic_name__								=			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(UpperCamelCase__       )

    __magic_name__								=			resnets
    __magic_name__								=			attentions

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





  def __call__(					self     :					List[Any]     ,				UpperCamelCase__     :					Optional[int]     ,				UpperCamelCase__     :					Tuple     ,				UpperCamelCase__     :					Dict     ,				UpperCamelCase__     :					Optional[int]=True       )     ->      Any:







    """simple docstring"""






    __magic_name__								=			()

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

    if self.add_downsample:
      __magic_name__								=			self.downsamplers_a(UpperCamelCase__       )
      output_states += (hidden_states,)

    return hidden_states, output_states







class 			UpperCAmelCase_     (					nn.Module	):


  '''simple docstring'''







  a__       			=						42
  a__       			=						42
  a__       			=						0.0
  a__       			=						1
  a__       			=						True
  a__       			=						jnp.floataa
  def 				_lowercase				(					self     :					str       )     ->      Optional[Any]:







    """simple docstring"""






    __magic_name__								=			[]

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

      __magic_name__								=			FlaxResnetBlockaD(
          in_channels=UpperCamelCase__     ,				out_channels=self.out_channels     ,				dropout_prob=self.dropout     ,				dtype=self.dtype     ,				)
      resnets.append(UpperCamelCase__       )
    __magic_name__								=			resnets

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





  def __call__(					self     :					str     ,				UpperCamelCase__     :					Tuple     ,				UpperCamelCase__     :					Union[str, Any]     ,				UpperCamelCase__     :					int=True       )     ->      Dict:







    """simple docstring"""






    __magic_name__								=			()

    for resnet in self.resnets:
      __magic_name__								=			resnet(UpperCamelCase__     ,				UpperCamelCase__     ,				deterministic=UpperCamelCase__       )
      output_states += (hidden_states,)

    if self.add_downsample:
      __magic_name__								=			self.downsamplers_a(UpperCamelCase__       )
      output_states += (hidden_states,)

    return hidden_states, output_states







class 			UpperCAmelCase_     (					nn.Module	):


  '''simple docstring'''







  a__       			=						42
  a__       			=						42
  a__       			=						42
  a__       			=						0.0
  a__       			=						1
  a__       			=						1
  a__       			=						True
  a__       			=						False
  a__       			=						False
  a__       			=						False
  a__       			=						jnp.floataa
  def 				_lowercase				(					self     :					Optional[Any]       )     ->      Any:







    """simple docstring"""






    __magic_name__								=			[]
    __magic_name__								=			[]

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

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

      __magic_name__								=			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(UpperCamelCase__       )

    __magic_name__								=			resnets
    __magic_name__								=			attentions

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





  def __call__(					self     :					Optional[int]     ,				UpperCamelCase__     :					Any     ,				UpperCamelCase__     :					Dict     ,				UpperCamelCase__     :					Optional[int]     ,				UpperCamelCase__     :					Optional[Any]     ,				UpperCamelCase__     :					Dict=True       )     ->      Union[str, Any]:







    """simple docstring"""






    for resnet, attn in zip(self.resnets     ,				self.attentions       ):
      # pop res hidden states
      __magic_name__								=			res_hidden_states_tuple[-1]
      __magic_name__								=			res_hidden_states_tuple[:-1]
      __magic_name__								=			jnp.concatenate((hidden_states, res_hidden_states)     ,				axis=-1       )

      __magic_name__								=			resnet(UpperCamelCase__     ,				UpperCamelCase__     ,				deterministic=UpperCamelCase__       )
      __magic_name__								=			attn(UpperCamelCase__     ,				UpperCamelCase__     ,				deterministic=UpperCamelCase__       )

    if self.add_upsample:
      __magic_name__								=			self.upsamplers_a(UpperCamelCase__       )

    return hidden_states







class 			UpperCAmelCase_     (					nn.Module	):


  '''simple docstring'''







  a__       			=						42
  a__       			=						42
  a__       			=						42
  a__       			=						0.0
  a__       			=						1
  a__       			=						True
  a__       			=						jnp.floataa
  def 				_lowercase				(					self     :					List[Any]       )     ->      str:







    """simple docstring"""






    __magic_name__								=			[]

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

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

    __magic_name__								=			resnets

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





  def __call__(					self     :					List[Any]     ,				UpperCamelCase__     :					str     ,				UpperCamelCase__     :					Union[str, Any]     ,				UpperCamelCase__     :					Optional[Any]     ,				UpperCamelCase__     :					str=True       )     ->      Dict:







    """simple docstring"""






    for resnet in self.resnets:
      # pop res hidden states
      __magic_name__								=			res_hidden_states_tuple[-1]
      __magic_name__								=			res_hidden_states_tuple[:-1]
      __magic_name__								=			jnp.concatenate((hidden_states, res_hidden_states)     ,				axis=-1       )

      __magic_name__								=			resnet(UpperCamelCase__     ,				UpperCamelCase__     ,				deterministic=UpperCamelCase__       )

    if self.add_upsample:
      __magic_name__								=			self.upsamplers_a(UpperCamelCase__       )

    return hidden_states







class 			UpperCAmelCase_     (					nn.Module	):


  '''simple docstring'''







  a__       			=						42
  a__       			=						0.0
  a__       			=						1
  a__       			=						1
  a__       			=						False
  a__       			=						False
  a__       			=						jnp.floataa
  def 				_lowercase				(					self     :					List[Any]       )     ->      Optional[Any]:







    """simple docstring"""






    __magic_name__								=			[
        FlaxResnetBlockaD(
            in_channels=self.in_channels     ,				out_channels=self.in_channels     ,				dropout_prob=self.dropout     ,				dtype=self.dtype     ,				)
    ]

    __magic_name__								=			[]

    for _ in range(self.num_layers       ):
      __magic_name__								=			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(UpperCamelCase__       )

      __magic_name__								=			FlaxResnetBlockaD(
          in_channels=self.in_channels     ,				out_channels=self.in_channels     ,				dropout_prob=self.dropout     ,				dtype=self.dtype     ,				)
      resnets.append(UpperCamelCase__       )

    __magic_name__								=			resnets
    __magic_name__								=			attentions





  def __call__(					self     :					Optional[int]     ,				UpperCamelCase__     :					Any     ,				UpperCamelCase__     :					Any     ,				UpperCamelCase__     :					List[Any]     ,				UpperCamelCase__     :					int=True       )     ->      str:







    """simple docstring"""






    __magic_name__								=			self.resnets[0](UpperCamelCase__     ,				UpperCamelCase__       )
    for attn, resnet in zip(self.attentions     ,				self.resnets[1:]       ):
      __magic_name__								=			attn(UpperCamelCase__     ,				UpperCamelCase__     ,				deterministic=UpperCamelCase__       )
      __magic_name__								=			resnet(UpperCamelCase__     ,				UpperCamelCase__     ,				deterministic=UpperCamelCase__       )

    return hidden_states

