"""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   lowerCAmelCase_    (			nn.Module					):



				"""simple docstring"""
				_lowerCAmelCase     :    int			  =						42
				_lowerCAmelCase     :    Optional[Any]			  =						42
				_lowerCAmelCase     :    Optional[Any]			  =						0.0
				_lowerCAmelCase     :    List[str]			  =						1
				_lowerCAmelCase     :    Any			  =						1
				_lowerCAmelCase     :    List[str]			  =						True
				_lowerCAmelCase     :    Union[str, Any]			  =						False
				_lowerCAmelCase     :    List[Any]			  =						False
				_lowerCAmelCase     :    List[Any]			  =						False
				_lowerCAmelCase     :    List[str]			  =						jnp.floataa

				def 		snake_case (				self    ):






										"""simple docstring"""

										snake_case								=			[]
										snake_case								=			[]

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

																snake_case								=			FlaxResnetBlockaD(
																    in_channels=lowercase_		,    out_channels=self.out_channels		,    dropout_prob=self.dropout		,    dtype=self.dtype		,    )
																resnets.append(lowercase_    )

																snake_case								=			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_    )

										snake_case								=			resnets
										snake_case								=			attentions

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

				def __call__(				self		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase=True    ):






										"""simple docstring"""

										snake_case								=			()

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

										if self.add_downsample:
																snake_case								=			self.downsamplers_a(lowercase_    )
																output_states += (hidden_states,)

										return hidden_states, output_states





class   lowerCAmelCase_    (			nn.Module					):



				"""simple docstring"""
				_lowerCAmelCase     :    str			  =						42
				_lowerCAmelCase     :    str			  =						42
				_lowerCAmelCase     :    List[Any]			  =						0.0
				_lowerCAmelCase     :    Optional[Any]			  =						1
				_lowerCAmelCase     :    Optional[Any]			  =						True
				_lowerCAmelCase     :    List[str]			  =						jnp.floataa

				def 		snake_case (				self    ):






										"""simple docstring"""

										snake_case								=			[]

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

																snake_case								=			FlaxResnetBlockaD(
																    in_channels=lowercase_		,    out_channels=self.out_channels		,    dropout_prob=self.dropout		,    dtype=self.dtype		,    )
																resnets.append(lowercase_    )
										snake_case								=			resnets

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

				def __call__(				self		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase=True    ):






										"""simple docstring"""

										snake_case								=			()

										for resnet in self.resnets:
																snake_case								=			resnet(lowercase_		,    lowercase_		,    deterministic=lowercase_    )
																output_states += (hidden_states,)

										if self.add_downsample:
																snake_case								=			self.downsamplers_a(lowercase_    )
																output_states += (hidden_states,)

										return hidden_states, output_states





class   lowerCAmelCase_    (			nn.Module					):



				"""simple docstring"""
				_lowerCAmelCase     :    Any			  =						42
				_lowerCAmelCase     :    str			  =						42
				_lowerCAmelCase     :    int			  =						42
				_lowerCAmelCase     :    Optional[int]			  =						0.0
				_lowerCAmelCase     :    Union[str, Any]			  =						1
				_lowerCAmelCase     :    int			  =						1
				_lowerCAmelCase     :    Union[str, Any]			  =						True
				_lowerCAmelCase     :    Any			  =						False
				_lowerCAmelCase     :    List[str]			  =						False
				_lowerCAmelCase     :    Dict			  =						False
				_lowerCAmelCase     :    Any			  =						jnp.floataa

				def 		snake_case (				self    ):






										"""simple docstring"""

										snake_case								=			[]
										snake_case								=			[]

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

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

																snake_case								=			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_    )

										snake_case								=			resnets
										snake_case								=			attentions

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

				def __call__(				self		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase=True    ):






										"""simple docstring"""

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

																snake_case								=			resnet(lowercase_		,    lowercase_		,    deterministic=lowercase_    )
																snake_case								=			attn(lowercase_		,    lowercase_		,    deterministic=lowercase_    )

										if self.add_upsample:
																snake_case								=			self.upsamplers_a(lowercase_    )

										return hidden_states





class   lowerCAmelCase_    (			nn.Module					):



				"""simple docstring"""
				_lowerCAmelCase     :    Optional[Any]			  =						42
				_lowerCAmelCase     :    Dict			  =						42
				_lowerCAmelCase     :    Optional[Any]			  =						42
				_lowerCAmelCase     :    Tuple			  =						0.0
				_lowerCAmelCase     :    List[Any]			  =						1
				_lowerCAmelCase     :    Dict			  =						True
				_lowerCAmelCase     :    List[str]			  =						jnp.floataa

				def 		snake_case (				self    ):






										"""simple docstring"""

										snake_case								=			[]

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

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

										snake_case								=			resnets

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

				def __call__(				self		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase=True    ):






										"""simple docstring"""

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

																snake_case								=			resnet(lowercase_		,    lowercase_		,    deterministic=lowercase_    )

										if self.add_upsample:
																snake_case								=			self.upsamplers_a(lowercase_    )

										return hidden_states





class   lowerCAmelCase_    (			nn.Module					):



				"""simple docstring"""
				_lowerCAmelCase     :    str			  =						42
				_lowerCAmelCase     :    Tuple			  =						0.0
				_lowerCAmelCase     :    Any			  =						1
				_lowerCAmelCase     :    Optional[int]			  =						1
				_lowerCAmelCase     :    Optional[int]			  =						False
				_lowerCAmelCase     :    int			  =						False
				_lowerCAmelCase     :    Dict			  =						jnp.floataa

				def 		snake_case (				self    ):






										"""simple docstring"""

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

										snake_case								=			[]

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

																snake_case								=			FlaxResnetBlockaD(
																    in_channels=self.in_channels		,    out_channels=self.in_channels		,    dropout_prob=self.dropout		,    dtype=self.dtype		,    )
																resnets.append(lowercase_    )

										snake_case								=			resnets
										snake_case								=			attentions

				def __call__(				self		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase=True    ):






										"""simple docstring"""

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

										return hidden_states





"""simple docstring"""
def    lowerCAmelCase__    (			_UpperCamelCase       :				int ,			_UpperCamelCase       :				int					)					->				int:





						"""simple docstring"""






						return int((input_a, input_a).count(0					) == 0					)





def    lowerCAmelCase__    (			)					->				None:





						"""simple docstring"""






						assert and_gate(0 ,			0					) == 0
						assert and_gate(0 ,			1					) == 0
						assert and_gate(1 ,			0					) == 0
						assert and_gate(1 ,			1					) == 1


if __name__ == "__main__":
					test_and_gate()
					print(and_gate(1, 0))
					print(and_gate(0, 0))
					print(and_gate(0, 1))
					print(and_gate(1, 1))


