

'''simple docstring'''





import colorsys

from PIL import Image  # type: ignore







def   _UpperCamelCase	(		__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase	)       ->			float:
					lowerCamelCase_  				=      x
					lowerCamelCase_  				=      y
					for step in range(__UpperCamelCase	):  # noqa: B007
										lowerCamelCase_  				=      a * a - b * b + x
										lowerCamelCase_  				=      2 * a * b + y
										lowerCamelCase_  				=      a_new

										# divergence happens for all complex number with an absolute value
										# greater than 4
										if a * a + b * b > 4:
															break
					return step / (max_step - 1)







def   _UpperCamelCase	(		__UpperCamelCase	)       ->			tuple:
					if distance == 1:
										return (0, 0, 0)
					else:
										return (2_55, 2_55, 2_55)







def   _UpperCamelCase	(		__UpperCamelCase	)       ->			tuple:
					if distance == 1:
										return (0, 0, 0)
					else:
										return tuple(round(i * 2_55	) for i in colorsys.hsv_to_rgb(__UpperCamelCase    ,1    ,1	)	)







def   _UpperCamelCase	(		__UpperCamelCase = 8_00    ,__UpperCamelCase = 6_00    ,__UpperCamelCase = -0.6    ,__UpperCamelCase = 0    ,__UpperCamelCase = 3.2    ,__UpperCamelCase = 50    ,__UpperCamelCase = True    ,)       ->			Image.Image:
					lowerCamelCase_  				=      Image.new('RGB'    ,(image_width, image_height)	)
					lowerCamelCase_  				=      img.load()

					# loop through the image-coordinates
					for image_x in range(__UpperCamelCase	):
										for image_y in range(__UpperCamelCase	):
															# determine the figure-coordinates based on the image-coordinates
															lowerCamelCase_  				=      figure_width / image_width * image_height
															lowerCamelCase_  				=      figure_center_x + (image_x / image_width - 0.5) * figure_width
															lowerCamelCase_  				=      figure_center_y + (image_y / image_height - 0.5) * figure_height

															lowerCamelCase_  				=      get_distance(__UpperCamelCase    ,__UpperCamelCase    ,__UpperCamelCase	)

															# color the corresponding pixel based on the selected coloring-function
															if use_distance_color_coding:
																				lowerCamelCase_  				=      get_color_coded_rgb(__UpperCamelCase	)
															else:
																				lowerCamelCase_  				=      get_black_and_white_rgb(__UpperCamelCase	)

					return img


if __name__ == "__main__":
				import doctest

				doctest.testmod()

				# colored version, full figure
				A_	= get_image()

				# uncomment for colored version, different section, zoomed in
				# img = get_image(figure_center_x = -0.6, figure_center_y = -0.4,
				# figure_width = 0.8)

				# uncomment for black and white version, full figure
				# img = get_image(use_distance_color_coding = False)

				# uncomment to save the image
				# img.save("mandelbrot.png")

				img.show()











'''simple docstring'''
import flax.linen as nn
import jax
import jax.numpy as jnp


class 							_UpperCAmelCase    (		nn.Module      ):
    __lowerCamelCase: int
    __lowerCamelCase: jnp.dtype									=     jnp.floataa




    def 					lowerCAmelCase__					(      self	:							Optional[Any]      ):






       '''simple docstring'''






       lowercase_						:     List[Any]							     =  nn.Conv(
           self.out_channels	,  kernel_size=(3, 3)	,  strides=(1, 1)	,  padding=((1, 1), (1, 1))	,  dtype=self.dtype	,  )





    def __call__(      self	:							List[str]	,  a	:							Optional[int]      ):






       '''simple docstring'''






       lowercase_     ,		lowercase_     ,		lowercase_     ,		lowercase_						:     Optional[Any]							     =  hidden_states.shape
       lowercase_						:     Tuple							     =  jax.image.resize(
           a	,  shape=(batch, height * 2, width * 2, channels)	,  method="nearest"	,  )
       lowercase_						:     List[Any]							     =  self.conv(a      )
       return hidden_states


class 							_UpperCAmelCase    (		nn.Module      ):
    __lowerCamelCase: int
    __lowerCamelCase: jnp.dtype									=     jnp.floataa




    def 					lowerCAmelCase__					(      self	:							Optional[Any]      ):






       '''simple docstring'''






       lowercase_						:     Any							     =  nn.Conv(
           self.out_channels	,  kernel_size=(3, 3)	,  strides=(2, 2)	,  padding=((1, 1), (1, 1))	,  dtype=self.dtype	,  )





    def __call__(      self	:							Any	,  a	:							int      ):






       '''simple docstring'''






       lowercase_						:     Any							     =  self.conv(a      )
       return hidden_states


class 							_UpperCAmelCase    (		nn.Module      ):
    __lowerCamelCase: int
    __lowerCamelCase: int									=     None
    __lowerCamelCase: float									=     0.0
    __lowerCamelCase: bool									=     None
    __lowerCamelCase: jnp.dtype									=     jnp.floataa




    def 					lowerCAmelCase__					(      self	:							Optional[int]      ):






       '''simple docstring'''






       lowercase_						:     Union[str, Any]							     =  self.in_channels if self.out_channels is None else self.out_channels

       lowercase_						:     Optional[int]							     =  nn.GroupNorm(num_groups=3_2	,  epsilon=1e-5      )
       lowercase_						:     Tuple							     =  nn.Conv(
           a	,  kernel_size=(3, 3)	,  strides=(1, 1)	,  padding=((1, 1), (1, 1))	,  dtype=self.dtype	,  )

       lowercase_						:     List[str]							     =  nn.Dense(a	,  dtype=self.dtype      )

       lowercase_						:     Optional[int]							     =  nn.GroupNorm(num_groups=3_2	,  epsilon=1e-5      )
       lowercase_						:     Any							     =  nn.Dropout(self.dropout_prob      )
       lowercase_						:     Dict							     =  nn.Conv(
           a	,  kernel_size=(3, 3)	,  strides=(1, 1)	,  padding=((1, 1), (1, 1))	,  dtype=self.dtype	,  )

       lowercase_						:     Tuple							     =  self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

       lowercase_						:     Optional[Any]							     =  None
       if use_nin_shortcut:
          lowercase_						:     Union[str, Any]							     =  nn.Conv(
              a	,  kernel_size=(1, 1)	,  strides=(1, 1)	,  padding="VALID"	,  dtype=self.dtype	,  )





    def __call__(      self	:							List[str]	,  a	:							str	,  a	:							Dict	,  a	:							List[str]=True      ):






       '''simple docstring'''






       lowercase_						:     Dict							     =  hidden_states
       lowercase_						:     int							     =  self.norma(a      )
       lowercase_						:     List[Any]							     =  nn.swish(a      )
       lowercase_						:     Dict							     =  self.conva(a      )

       lowercase_						:     Optional[int]							     =  self.time_emb_proj(nn.swish(a      )      )
       lowercase_						:     Tuple							     =  jnp.expand_dims(jnp.expand_dims(a	,  1      )	,  1      )
       lowercase_						:     List[str]							     =  hidden_states + temb

       lowercase_						:     Optional[Any]							     =  self.norma(a      )
       lowercase_						:     Any							     =  nn.swish(a      )
       lowercase_						:     List[str]							     =  self.dropout(a	,  a      )
       lowercase_						:     int							     =  self.conva(a      )

       if self.conv_shortcut is not None:
          lowercase_						:     List[str]							     =  self.conv_shortcut(a      )

       return hidden_states + residual




