




'''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      SCREAMING_SNAKE_CASE    (						nn.Module				):
      __magic_name__  :       int
      __magic_name__  :       int
      __magic_name__  :       float   							=					0.0
      __magic_name__  :       int   							=					1
      __magic_name__  :       int   							=					1
      __magic_name__  :       bool   							=					True
      __magic_name__  :       bool   							=					False
      __magic_name__  :       bool   							=					False
      __magic_name__  :       bool   							=					False
      __magic_name__  :       jnp.dtype   							=					jnp.floataa






      def 							lowercase_						( self   :  Union[str, Any]       ):


           '''simple docstring'''

           a_     :							Dict     						=  []
           a_     :							int     						=  []

           for i in range(self.num_layers       ):
                a_     :							Union[str, Any]     						=  self.in_channels if i == 0 else self.out_channels

                a_     :							Any     						=  FlaxResnetBlockaD(
                    in_channels=lowercase__						,						out_channels=self.out_channels						,						dropout_prob=self.dropout						,						dtype=self.dtype						,						)
                resnets.append(lowercase__       )

                a_     :							Dict     						=  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__       )

           a_     :							Optional[int]     						=  resnets
           a_     :							Optional[Any]     						=  attentions

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






      def __call__( self   :  Dict						,						lowercase__   :  List[str]						,						lowercase__   :  Dict						,						lowercase__   :  Dict						,						lowercase__   :  Union[str, Any]=True       ):


           '''simple docstring'''

           a_     :							Optional[Any]     						=  ()

           for resnet, attn in zip(self.resnets						,						self.attentions       ):
                a_     :							Optional[Any]     						=  resnet(lowercase__						,						lowercase__						,						deterministic=lowercase__       )
                a_     :							List[Any]     						=  attn(lowercase__						,						lowercase__						,						deterministic=lowercase__       )
                output_states += (hidden_states,)

           if self.add_downsample:
                a_     :							Any     						=  self.downsamplers_a(lowercase__       )
                output_states += (hidden_states,)

           return hidden_states, output_states







class      SCREAMING_SNAKE_CASE    (						nn.Module				):
      __magic_name__  :       int
      __magic_name__  :       int
      __magic_name__  :       float   							=					0.0
      __magic_name__  :       int   							=					1
      __magic_name__  :       bool   							=					True
      __magic_name__  :       jnp.dtype   							=					jnp.floataa






      def 							lowercase_						( self   :  Tuple       ):


           '''simple docstring'''

           a_     :							Any     						=  []

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

                a_     :							Dict     						=  FlaxResnetBlockaD(
                    in_channels=lowercase__						,						out_channels=self.out_channels						,						dropout_prob=self.dropout						,						dtype=self.dtype						,						)
                resnets.append(lowercase__       )
           a_     :							Union[str, Any]     						=  resnets

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






      def __call__( self   :  Tuple						,						lowercase__   :  List[Any]						,						lowercase__   :  Optional[Any]						,						lowercase__   :  Any=True       ):


           '''simple docstring'''

           a_     :							Union[str, Any]     						=  ()

           for resnet in self.resnets:
                a_     :							List[Any]     						=  resnet(lowercase__						,						lowercase__						,						deterministic=lowercase__       )
                output_states += (hidden_states,)

           if self.add_downsample:
                a_     :							Dict     						=  self.downsamplers_a(lowercase__       )
                output_states += (hidden_states,)

           return hidden_states, output_states







class      SCREAMING_SNAKE_CASE    (						nn.Module				):
      __magic_name__  :       int
      __magic_name__  :       int
      __magic_name__  :       int
      __magic_name__  :       float   							=					0.0
      __magic_name__  :       int   							=					1
      __magic_name__  :       int   							=					1
      __magic_name__  :       bool   							=					True
      __magic_name__  :       bool   							=					False
      __magic_name__  :       bool   							=					False
      __magic_name__  :       bool   							=					False
      __magic_name__  :       jnp.dtype   							=					jnp.floataa






      def 							lowercase_						( self   :  Any       ):


           '''simple docstring'''

           a_     :							str     						=  []
           a_     :							List[str]     						=  []

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

                a_     :							List[Any]     						=  FlaxResnetBlockaD(
                    in_channels=resnet_in_channels + res_skip_channels						,						out_channels=self.out_channels						,						dropout_prob=self.dropout						,						dtype=self.dtype						,						)
                resnets.append(lowercase__       )

                a_     :							str     						=  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__       )

           a_     :							int     						=  resnets
           a_     :							Dict     						=  attentions

           if self.add_upsample:
                a_     :							List[Any]     						=  FlaxUpsampleaD(self.out_channels						,						dtype=self.dtype       )






      def __call__( self   :  str						,						lowercase__   :  Any						,						lowercase__   :  Dict						,						lowercase__   :  int						,						lowercase__   :  Optional[Any]						,						lowercase__   :  Dict=True       ):


           '''simple docstring'''

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

                a_     :							List[str]     						=  resnet(lowercase__						,						lowercase__						,						deterministic=lowercase__       )
                a_     :							List[str]     						=  attn(lowercase__						,						lowercase__						,						deterministic=lowercase__       )

           if self.add_upsample:
                a_     :							int     						=  self.upsamplers_a(lowercase__       )

           return hidden_states







class      SCREAMING_SNAKE_CASE    (						nn.Module				):
      __magic_name__  :       int
      __magic_name__  :       int
      __magic_name__  :       int
      __magic_name__  :       float   							=					0.0
      __magic_name__  :       int   							=					1
      __magic_name__  :       bool   							=					True
      __magic_name__  :       jnp.dtype   							=					jnp.floataa






      def 							lowercase_						( self   :  int       ):


           '''simple docstring'''

           a_     :							Optional[int]     						=  []

           for i in range(self.num_layers       ):
                a_     :							Union[str, Any]     						=  self.in_channels if (i == self.num_layers - 1) else self.out_channels
                a_     :							List[Any]     						=  self.prev_output_channel if i == 0 else self.out_channels

                a_     :							Union[str, Any]     						=  FlaxResnetBlockaD(
                    in_channels=resnet_in_channels + res_skip_channels						,						out_channels=self.out_channels						,						dropout_prob=self.dropout						,						dtype=self.dtype						,						)
                resnets.append(lowercase__       )

           a_     :							List[str]     						=  resnets

           if self.add_upsample:
                a_     :							Union[str, Any]     						=  FlaxUpsampleaD(self.out_channels						,						dtype=self.dtype       )






      def __call__( self   :  Optional[int]						,						lowercase__   :  Optional[Any]						,						lowercase__   :  Optional[int]						,						lowercase__   :  Optional[Any]						,						lowercase__   :  Any=True       ):


           '''simple docstring'''

           for resnet in self.resnets:
                # pop res hidden states
                a_     :							Tuple     						=  res_hidden_states_tuple[-1]
                a_     :							Optional[Any]     						=  res_hidden_states_tuple[:-1]
                a_     :							Union[str, Any]     						=  jnp.concatenate((hidden_states, res_hidden_states)						,						axis=-1       )

                a_     :							List[str]     						=  resnet(lowercase__						,						lowercase__						,						deterministic=lowercase__       )

           if self.add_upsample:
                a_     :							Any     						=  self.upsamplers_a(lowercase__       )

           return hidden_states







class      SCREAMING_SNAKE_CASE    (						nn.Module				):
      __magic_name__  :       int
      __magic_name__  :       float   							=					0.0
      __magic_name__  :       int   							=					1
      __magic_name__  :       int   							=					1
      __magic_name__  :       bool   							=					False
      __magic_name__  :       bool   							=					False
      __magic_name__  :       jnp.dtype   							=					jnp.floataa






      def 							lowercase_						( self   :  Optional[Any]       ):


           '''simple docstring'''

           a_     :							Optional[int]     						=  [
               FlaxResnetBlockaD(
                   in_channels=self.in_channels						,						out_channels=self.in_channels						,						dropout_prob=self.dropout						,						dtype=self.dtype						,						)
           ]

           a_     :							Optional[Any]     						=  []

           for _ in range(self.num_layers       ):
                a_     :							Tuple     						=  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__       )

                a_     :							Optional[int]     						=  FlaxResnetBlockaD(
                    in_channels=self.in_channels						,						out_channels=self.in_channels						,						dropout_prob=self.dropout						,						dtype=self.dtype						,						)
                resnets.append(lowercase__       )

           a_     :							Union[str, Any]     						=  resnets
           a_     :							str     						=  attentions






      def __call__( self   :  int						,						lowercase__   :  Tuple						,						lowercase__   :  Optional[Any]						,						lowercase__   :  List[Any]						,						lowercase__   :  Any=True       ):


           '''simple docstring'''

           a_     :							Dict     						=  self.resnets[0](lowercase__						,						lowercase__       )
           for attn, resnet in zip(self.attentions						,						self.resnets[1:]       ):
                a_     :							Dict     						=  attn(lowercase__						,						lowercase__						,						deterministic=lowercase__       )
                a_     :							Any     						=  resnet(lowercase__						,						lowercase__						,						deterministic=lowercase__       )

           return hidden_states






'''simple docstring'''


from unittest.mock import Mock, patch

from file_transfer.send_file import send_file



@patch("""socket.socket"""				)
@patch("""builtins.open"""				)
def  _SCREAMING_SNAKE_CASE     (      UpperCamelCase__    :					Dict ,    UpperCamelCase__    :					Tuple				):




     """simple docstring"""


     a_     :							Dict     						=  Mock()
     a_     :							List[str]     						=  conn, Mock()
     a_     :							Optional[int]     						=  iter([1, None]				)
     a_     :							List[str]     						=  lambda UpperCamelCase__				: next(UpperCamelCase__				)

     # ===== invoke =====
     send_file(filename="""mytext.txt""" ,    testing=UpperCamelCase__				)

     # ===== ensurance =====
     sock.assert_called_once()
     sock.return_value.bind.assert_called_once()
     sock.return_value.listen.assert_called_once()
     sock.return_value.accept.assert_called_once()
     conn.recv.assert_called_once()

     file.return_value.__enter__.assert_called_once()
     file.return_value.__enter__.return_value.read.assert_called()

     conn.send.assert_called_once()
     conn.close.assert_called_once()
     sock.return_value.shutdown.assert_called_once()
     sock.return_value.close.assert_called_once()
