


'''simple docstring'''




from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


_a      :      Union[str, Any]       				=      logging.get_logger(__name__)  # pylint: disable=invalid-name




class  _lowercase   (  __lowercase       ):
			_SCREAMING_SNAKE_CASE     :     Optional[Any]									=  ["safety_checker", "feature_extractor"]
			def __init__(	self					:			List[Any]					,      SCREAMING_SNAKE_CASE_					:			AutoencoderKL					,      SCREAMING_SNAKE_CASE_					:			CLIPTextModel					,      SCREAMING_SNAKE_CASE_					:			CLIPTokenizer					,      SCREAMING_SNAKE_CASE_					:			UNetaDConditionModel					,      SCREAMING_SNAKE_CASE_					:			Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]					,      SCREAMING_SNAKE_CASE_					:			StableDiffusionSafetyChecker					,      SCREAMING_SNAKE_CASE_					:			CLIPImageProcessor					,      SCREAMING_SNAKE_CASE_					:			bool = True					,      )   ->       List[str]:
								super().__init__()
								if hasattr(scheduler.config					,      'steps_offset'			) and scheduler.config.steps_offset != 1:
													__snake_case    			=	(
													    f'The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`'
													    f' should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure '
													    'to update the config accordingly as leaving `steps_offset` might led to incorrect results'
													    ' in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,'
													    ' it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`'
													    ' file'
													)
													deprecate('steps_offset!=1'					,      '1.0.0'					,      SCREAMING_SNAKE_CASE_					,      standard_warn=SCREAMING_SNAKE_CASE_			)
													__snake_case    			=	dict(scheduler.config			)
													__snake_case    			=	1
													__snake_case    			=	FrozenDict(SCREAMING_SNAKE_CASE_			)

								self.register_modules(
								    vae=SCREAMING_SNAKE_CASE_					,      text_encoder=SCREAMING_SNAKE_CASE_					,      tokenizer=SCREAMING_SNAKE_CASE_					,      unet=SCREAMING_SNAKE_CASE_					,      scheduler=SCREAMING_SNAKE_CASE_					,      safety_checker=SCREAMING_SNAKE_CASE_					,      feature_extractor=SCREAMING_SNAKE_CASE_					,      )
								self.register_to_config(requires_safety_checker=SCREAMING_SNAKE_CASE_			)
			@property
			def a     (	self					:			List[str]			)   ->       Dict[str, Any]:
								return {k: getattr(self					,      SCREAMING_SNAKE_CASE_			) for k in self.config.keys() if not k.startswith('_'			)}
			def a     (	self					:			Union[str, Any]					,      SCREAMING_SNAKE_CASE_					:			Optional[Union[str, int]] = "auto"			)   ->       Union[str, Any]:
								if slice_size == "auto":
													# half the attention head size is usually a good trade-off between
													# speed and memory
													__snake_case    			=	self.unet.config.attention_head_dim // 2
								self.unet.set_attention_slice(SCREAMING_SNAKE_CASE_			)
			def a     (	self					:			Dict			)   ->       List[str]:
								self.enable_attention_slicing(SCREAMING_SNAKE_CASE_			)
			@torch.no_grad()
			def a     (	self					:			List[str]					,      SCREAMING_SNAKE_CASE_					:			Union[str, List[str]]					,      SCREAMING_SNAKE_CASE_					:			Union[torch.FloatTensor, PIL.Image.Image]					,      SCREAMING_SNAKE_CASE_					:			Union[torch.FloatTensor, PIL.Image.Image]					,      SCREAMING_SNAKE_CASE_					:			float = 0.8					,      SCREAMING_SNAKE_CASE_					:			Optional[int] = 50					,      SCREAMING_SNAKE_CASE_					:			Optional[float] = 7.5					,      SCREAMING_SNAKE_CASE_					:			Optional[Union[str, List[str]]] = None					,      SCREAMING_SNAKE_CASE_					:			Optional[int] = 1					,      SCREAMING_SNAKE_CASE_					:			Optional[float] = 0.0					,      SCREAMING_SNAKE_CASE_					:			Optional[torch.Generator] = None					,      SCREAMING_SNAKE_CASE_					:			Optional[str] = "pil"					,      SCREAMING_SNAKE_CASE_					:			bool = True					,      SCREAMING_SNAKE_CASE_					:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,      SCREAMING_SNAKE_CASE_					:			int = 1					,      )   ->       Optional[int]:
								# For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
								return StableDiffusionInpaintPipelineLegacy(**self.components			)(
								    prompt=SCREAMING_SNAKE_CASE_					,      image=SCREAMING_SNAKE_CASE_					,      mask_image=SCREAMING_SNAKE_CASE_					,      strength=SCREAMING_SNAKE_CASE_					,      num_inference_steps=SCREAMING_SNAKE_CASE_					,      guidance_scale=SCREAMING_SNAKE_CASE_					,      negative_prompt=SCREAMING_SNAKE_CASE_					,      num_images_per_prompt=SCREAMING_SNAKE_CASE_					,      eta=SCREAMING_SNAKE_CASE_					,      generator=SCREAMING_SNAKE_CASE_					,      output_type=SCREAMING_SNAKE_CASE_					,      return_dict=SCREAMING_SNAKE_CASE_					,      callback=SCREAMING_SNAKE_CASE_					,      )
			@torch.no_grad()
			def a     (	self					:			Union[str, Any]					,      SCREAMING_SNAKE_CASE_					:			Union[str, List[str]]					,      SCREAMING_SNAKE_CASE_					:			Union[torch.FloatTensor, PIL.Image.Image]					,      SCREAMING_SNAKE_CASE_					:			float = 0.8					,      SCREAMING_SNAKE_CASE_					:			Optional[int] = 50					,      SCREAMING_SNAKE_CASE_					:			Optional[float] = 7.5					,      SCREAMING_SNAKE_CASE_					:			Optional[Union[str, List[str]]] = None					,      SCREAMING_SNAKE_CASE_					:			Optional[int] = 1					,      SCREAMING_SNAKE_CASE_					:			Optional[float] = 0.0					,      SCREAMING_SNAKE_CASE_					:			Optional[torch.Generator] = None					,      SCREAMING_SNAKE_CASE_					:			Optional[str] = "pil"					,      SCREAMING_SNAKE_CASE_					:			bool = True					,      SCREAMING_SNAKE_CASE_					:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,      SCREAMING_SNAKE_CASE_					:			int = 1					,      **SCREAMING_SNAKE_CASE_					:			Union[str, Any]					,      )   ->       str:
								# For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
								return StableDiffusionImgaImgPipeline(**self.components			)(
								    prompt=SCREAMING_SNAKE_CASE_					,      image=SCREAMING_SNAKE_CASE_					,      strength=SCREAMING_SNAKE_CASE_					,      num_inference_steps=SCREAMING_SNAKE_CASE_					,      guidance_scale=SCREAMING_SNAKE_CASE_					,      negative_prompt=SCREAMING_SNAKE_CASE_					,      num_images_per_prompt=SCREAMING_SNAKE_CASE_					,      eta=SCREAMING_SNAKE_CASE_					,      generator=SCREAMING_SNAKE_CASE_					,      output_type=SCREAMING_SNAKE_CASE_					,      return_dict=SCREAMING_SNAKE_CASE_					,      callback=SCREAMING_SNAKE_CASE_					,      callback_steps=SCREAMING_SNAKE_CASE_					,      )





			@torch.no_grad()
			def a     (	self					:			List[Any]					,      SCREAMING_SNAKE_CASE_					:			Union[str, List[str]]					,      SCREAMING_SNAKE_CASE_					:			int = 512					,      SCREAMING_SNAKE_CASE_					:			int = 512					,      SCREAMING_SNAKE_CASE_					:			int = 50					,      SCREAMING_SNAKE_CASE_					:			float = 7.5					,      SCREAMING_SNAKE_CASE_					:			Optional[Union[str, List[str]]] = None					,      SCREAMING_SNAKE_CASE_					:			Optional[int] = 1					,      SCREAMING_SNAKE_CASE_					:			float = 0.0					,      SCREAMING_SNAKE_CASE_					:			Optional[torch.Generator] = None					,      SCREAMING_SNAKE_CASE_					:			Optional[torch.FloatTensor] = None					,      SCREAMING_SNAKE_CASE_					:			Optional[str] = "pil"					,      SCREAMING_SNAKE_CASE_					:			bool = True					,      SCREAMING_SNAKE_CASE_					:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None					,      SCREAMING_SNAKE_CASE_					:			int = 1					,      )   ->       str:
								# For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
								return StableDiffusionPipeline(**self.components			)(
								    prompt=SCREAMING_SNAKE_CASE_					,      height=SCREAMING_SNAKE_CASE_					,      width=SCREAMING_SNAKE_CASE_					,      num_inference_steps=SCREAMING_SNAKE_CASE_					,      guidance_scale=SCREAMING_SNAKE_CASE_					,      negative_prompt=SCREAMING_SNAKE_CASE_					,      num_images_per_prompt=SCREAMING_SNAKE_CASE_					,      eta=SCREAMING_SNAKE_CASE_					,      generator=SCREAMING_SNAKE_CASE_					,      latents=SCREAMING_SNAKE_CASE_					,      output_type=SCREAMING_SNAKE_CASE_					,      return_dict=SCREAMING_SNAKE_CASE_					,      callback=SCREAMING_SNAKE_CASE_					,      callback_steps=SCREAMING_SNAKE_CASE_					,      )








'''simple docstring'''




import warnings
from collections.abc import Callable
from typing import Any

import numpy
from matplotlib import pyplot

_a      :      Optional[int]       				=      0.25 + 0.0J
_a      :      Dict       				=      -0.4 + 0.6J
_a      :      List[str]       				=      -0.1 + 0.651J
_a      :      Optional[int]       				=      -2.0
_a      :      List[str]       				=      56
_a      :      Tuple       				=      2.0
_a      :      List[str]       				=      666





def      _a		(lowercase__ :      complex       ,      lowercase__ :      numpy.ndarray	) -> numpy.ndarray:






     """simple docstring"""
     return numpy.exp(lowercase__	) + c_parameter





def      _a		(lowercase__ :      complex       ,      lowercase__ :      numpy.ndarray	) -> numpy.ndarray:






     """simple docstring"""
     return z_values * z_values + c_parameter





def      _a		(lowercase__ :      float       ,      lowercase__ :      int	) -> numpy.ndarray:






     """simple docstring"""
     __snake_case    			=	numpy.linspace(-window_size       ,      lowercase__       ,      lowercase__	)
     __snake_case    			=	x.reshape((nb_pixels, 1)	)
     __snake_case    			=	numpy.linspace(-window_size       ,      lowercase__       ,      lowercase__	)
     __snake_case    			=	y.reshape((1, nb_pixels)	)
     return x + 1.0J * y





def      _a		(lowercase__ :      Callable[[Any, numpy.ndarray], numpy.ndarray]       ,      lowercase__ :      Any       ,      lowercase__ :      int       ,      lowercase__ :      numpy.ndarray       ,      lowercase__ :      float | None = None       ,      ) -> numpy.ndarray:






     """simple docstring"""
     __snake_case    			=	z_a.astype('complex64'	)
     for _ in range(lowercase__	):
          __snake_case    			=	eval_function(lowercase__       ,      lowercase__	)
          if infinity is not None:
               numpy.nan_to_num(lowercase__       ,      copy=lowercase__       ,      nan=lowercase__	)
               __snake_case    			=	infinity
     return z_n





def      _a		(lowercase__ :      str       ,      lowercase__ :      Any       ,      lowercase__ :      float       ,      lowercase__ :      numpy.ndarray       ,      ) -> None:






     """simple docstring"""
     __snake_case    			=	(abs(lowercase__	)).transpose()
     __snake_case    			=	abs_z_final[::-1, :]
     pyplot.matshow(abs_z_final < escape_radius	)
     pyplot.title(f'Julia set of ${function_label}$, $c={function_params}$'	)
     pyplot.show()





def      _a		() -> None:






     """simple docstring"""
     warnings.filterwarnings(
         'ignore'       ,      category=lowercase__       ,      message='overflow encountered in multiply'	)
     warnings.filterwarnings(
         'ignore'       ,      category=lowercase__       ,      message='invalid value encountered in multiply'       ,      )
     warnings.filterwarnings(
         'ignore'       ,      category=lowercase__       ,      message='overflow encountered in absolute'	)
     warnings.filterwarnings(
         'ignore'       ,      category=lowercase__       ,      message='overflow encountered in exp'	)


if __name__ == "__main__":
       _a      :      List[Any]       				=      prepare_grid(window_size, nb_pixels)

       ignore_overflow_warnings()  # See file header for explanations

       _a      :      Optional[Any]       				=      24
       _a      :      Optional[int]       				=      2 * abs(c_cauliflower) + 1
       _a      :      List[str]       				=      iterate_function(
           eval_quadratic_polynomial,
           c_cauliflower,
           nb_iterations,
           z_a,
           infinity=1.1 * escape_radius,
       )
       show_results("z^2+c", c_cauliflower, escape_radius, z_final)

       _a      :      str       				=      64
       _a      :      Tuple       				=      2 * abs(c_polynomial_a) + 1
       _a      :      List[Any]       				=      iterate_function(
           eval_quadratic_polynomial,
           c_polynomial_a,
           nb_iterations,
           z_a,
           infinity=1.1 * escape_radius,
       )
       show_results("z^2+c", c_polynomial_a, escape_radius, z_final)

       _a      :      List[Any]       				=      161
       _a      :      Tuple       				=      2 * abs(c_polynomial_a) + 1
       _a      :      int       				=      iterate_function(
           eval_quadratic_polynomial,
           c_polynomial_a,
           nb_iterations,
           z_a,
           infinity=1.1 * escape_radius,
       )
       show_results("z^2+c", c_polynomial_a, escape_radius, z_final)

       _a      :      str       				=      12
       _a      :      Optional[Any]       				=      10_000.0
       _a      :      Dict       				=      iterate_function(
           eval_exponential,
           c_exponential,
           nb_iterations,
           z_a + 2,
           infinity=1.0e1_0,
       )
       show_results("e^z+c", c_exponential, escape_radius, z_final)




