





'''simple docstring'''




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

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


lowercase__    :      Optional[Any]						=    '''CompVis/stable-diffusion-v1-1'''
lowercase__    :      Optional[Any]						=    '''CompVis/stable-diffusion-v1-2'''
lowercase__    :      Dict						=    '''CompVis/stable-diffusion-v1-3'''
lowercase__    :      Optional[int]						=    '''CompVis/stable-diffusion-v1-4'''


class  SCREAMING_SNAKE_CASE    (a__							):


     def __init__(						self						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase = True						,	):

          '''simple docstring'''






          super()._init_()

          __A						: List[Any]      =       StableDiffusionPipeline.from_pretrained(_UpperCAmelCase)
          __A						: List[Any]      =       StableDiffusionPipeline.from_pretrained(_UpperCAmelCase)
          __A						: Optional[int]      =       StableDiffusionPipeline.from_pretrained(_UpperCAmelCase)
          __A						: int      =       StableDiffusionPipeline(
              vae=_UpperCAmelCase						,	text_encoder=_UpperCAmelCase						,	tokenizer=_UpperCAmelCase						,	unet=_UpperCAmelCase						,	scheduler=_UpperCAmelCase						,	safety_checker=_UpperCAmelCase						,	feature_extractor=_UpperCAmelCase						,	requires_safety_checker=_UpperCAmelCase						,	)

          self.register_modules(pipelinea=self.pipea						,	pipelinea=self.pipea						,	pipelinea=self.pipea						,	pipelinea=self.pipea)


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return {k: getattr(self						,	_UpperCAmelCase) for k in self.config.keys() if not k.startswith('_')}


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase = "auto"):

          '''simple docstring'''






          if slice_size == "auto":
               # half the attention head size is usually a good trade-off between
               # speed and memory
               __A						: List[str]      =       self.unet.config.attention_head_dim // 2
          self.unet.set_attention_slice(_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          self.enable_attention_slicing(_UpperCAmelCase)


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 50						,	_UpperCAmelCase = 7.5						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	_UpperCAmelCase = 0.0						,	_UpperCAmelCase = None						,	_UpperCAmelCase = None						,	_UpperCAmelCase = "pil"						,	_UpperCAmelCase = True						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          return self.pipea(
              prompt=_UpperCAmelCase						,	height=_UpperCAmelCase						,	width=_UpperCAmelCase						,	num_inference_steps=_UpperCAmelCase						,	guidance_scale=_UpperCAmelCase						,	negative_prompt=_UpperCAmelCase						,	num_images_per_prompt=_UpperCAmelCase						,	eta=_UpperCAmelCase						,	generator=_UpperCAmelCase						,	latents=_UpperCAmelCase						,	output_type=_UpperCAmelCase						,	return_dict=_UpperCAmelCase						,	callback=_UpperCAmelCase						,	callback_steps=_UpperCAmelCase						,	**_UpperCAmelCase						,	)


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 50						,	_UpperCAmelCase = 7.5						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	_UpperCAmelCase = 0.0						,	_UpperCAmelCase = None						,	_UpperCAmelCase = None						,	_UpperCAmelCase = "pil"						,	_UpperCAmelCase = True						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          return self.pipea(
              prompt=_UpperCAmelCase						,	height=_UpperCAmelCase						,	width=_UpperCAmelCase						,	num_inference_steps=_UpperCAmelCase						,	guidance_scale=_UpperCAmelCase						,	negative_prompt=_UpperCAmelCase						,	num_images_per_prompt=_UpperCAmelCase						,	eta=_UpperCAmelCase						,	generator=_UpperCAmelCase						,	latents=_UpperCAmelCase						,	output_type=_UpperCAmelCase						,	return_dict=_UpperCAmelCase						,	callback=_UpperCAmelCase						,	callback_steps=_UpperCAmelCase						,	**_UpperCAmelCase						,	)


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 50						,	_UpperCAmelCase = 7.5						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	_UpperCAmelCase = 0.0						,	_UpperCAmelCase = None						,	_UpperCAmelCase = None						,	_UpperCAmelCase = "pil"						,	_UpperCAmelCase = True						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          return self.pipea(
              prompt=_UpperCAmelCase						,	height=_UpperCAmelCase						,	width=_UpperCAmelCase						,	num_inference_steps=_UpperCAmelCase						,	guidance_scale=_UpperCAmelCase						,	negative_prompt=_UpperCAmelCase						,	num_images_per_prompt=_UpperCAmelCase						,	eta=_UpperCAmelCase						,	generator=_UpperCAmelCase						,	latents=_UpperCAmelCase						,	output_type=_UpperCAmelCase						,	return_dict=_UpperCAmelCase						,	callback=_UpperCAmelCase						,	callback_steps=_UpperCAmelCase						,	**_UpperCAmelCase						,	)


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 50						,	_UpperCAmelCase = 7.5						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	_UpperCAmelCase = 0.0						,	_UpperCAmelCase = None						,	_UpperCAmelCase = None						,	_UpperCAmelCase = "pil"						,	_UpperCAmelCase = True						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          return self.pipea(
              prompt=_UpperCAmelCase						,	height=_UpperCAmelCase						,	width=_UpperCAmelCase						,	num_inference_steps=_UpperCAmelCase						,	guidance_scale=_UpperCAmelCase						,	negative_prompt=_UpperCAmelCase						,	num_images_per_prompt=_UpperCAmelCase						,	eta=_UpperCAmelCase						,	generator=_UpperCAmelCase						,	latents=_UpperCAmelCase						,	output_type=_UpperCAmelCase						,	return_dict=_UpperCAmelCase						,	callback=_UpperCAmelCase						,	callback_steps=_UpperCAmelCase						,	**_UpperCAmelCase						,	)


     @torch.no_grad()
     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 512						,	_UpperCAmelCase = 50						,	_UpperCAmelCase = 7.5						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	_UpperCAmelCase = 0.0						,	_UpperCAmelCase = None						,	_UpperCAmelCase = None						,	_UpperCAmelCase = "pil"						,	_UpperCAmelCase = True						,	_UpperCAmelCase = None						,	_UpperCAmelCase = 1						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          __A						: Union[str, Any]      =       'cuda' if torch.cuda.is_available() else 'cpu'
          self.to(_UpperCAmelCase)

          # Checks if the height and width are divisible by 8 or not
          if height % 8 != 0 or width % 8 != 0:
               raise ValueError(F'`height` and `width` must be divisible by 8 but are {height} and {width}.')

          # Get first result from Stable Diffusion Checkpoint v1.1
          __A						: Union[str, Any]      =       self.textaimg_sda_a(
              prompt=_UpperCAmelCase						,	height=_UpperCAmelCase						,	width=_UpperCAmelCase						,	num_inference_steps=_UpperCAmelCase						,	guidance_scale=_UpperCAmelCase						,	negative_prompt=_UpperCAmelCase						,	num_images_per_prompt=_UpperCAmelCase						,	eta=_UpperCAmelCase						,	generator=_UpperCAmelCase						,	latents=_UpperCAmelCase						,	output_type=_UpperCAmelCase						,	return_dict=_UpperCAmelCase						,	callback=_UpperCAmelCase						,	callback_steps=_UpperCAmelCase						,	**_UpperCAmelCase						,	)

          # Get first result from Stable Diffusion Checkpoint v1.2
          __A						: Dict      =       self.textaimg_sda_a(
              prompt=_UpperCAmelCase						,	height=_UpperCAmelCase						,	width=_UpperCAmelCase						,	num_inference_steps=_UpperCAmelCase						,	guidance_scale=_UpperCAmelCase						,	negative_prompt=_UpperCAmelCase						,	num_images_per_prompt=_UpperCAmelCase						,	eta=_UpperCAmelCase						,	generator=_UpperCAmelCase						,	latents=_UpperCAmelCase						,	output_type=_UpperCAmelCase						,	return_dict=_UpperCAmelCase						,	callback=_UpperCAmelCase						,	callback_steps=_UpperCAmelCase						,	**_UpperCAmelCase						,	)

          # Get first result from Stable Diffusion Checkpoint v1.3
          __A						: Union[str, Any]      =       self.textaimg_sda_a(
              prompt=_UpperCAmelCase						,	height=_UpperCAmelCase						,	width=_UpperCAmelCase						,	num_inference_steps=_UpperCAmelCase						,	guidance_scale=_UpperCAmelCase						,	negative_prompt=_UpperCAmelCase						,	num_images_per_prompt=_UpperCAmelCase						,	eta=_UpperCAmelCase						,	generator=_UpperCAmelCase						,	latents=_UpperCAmelCase						,	output_type=_UpperCAmelCase						,	return_dict=_UpperCAmelCase						,	callback=_UpperCAmelCase						,	callback_steps=_UpperCAmelCase						,	**_UpperCAmelCase						,	)

          # Get first result from Stable Diffusion Checkpoint v1.4
          __A						: Tuple      =       self.textaimg_sda_a(
              prompt=_UpperCAmelCase						,	height=_UpperCAmelCase						,	width=_UpperCAmelCase						,	num_inference_steps=_UpperCAmelCase						,	guidance_scale=_UpperCAmelCase						,	negative_prompt=_UpperCAmelCase						,	num_images_per_prompt=_UpperCAmelCase						,	eta=_UpperCAmelCase						,	generator=_UpperCAmelCase						,	latents=_UpperCAmelCase						,	output_type=_UpperCAmelCase						,	return_dict=_UpperCAmelCase						,	callback=_UpperCAmelCase						,	callback_steps=_UpperCAmelCase						,	**_UpperCAmelCase						,	)

          # Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
          return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]])






'''simple docstring'''




from __future__ import annotations

from numpy import array, cos, cross, floataa, radians, sin
from numpy.typing import NDArray






def        _lowerCAmelCase			(  __snake_case  : float ,							__snake_case  : float ,							__snake_case  : bool = False			)     ->     list[float]:
     if radian_mode:
          return [magnitude * cos(__snake_case			), magnitude * sin(__snake_case			)]
     return [magnitude * cos(radians(__snake_case			)			), magnitude * sin(radians(__snake_case			)			)]






def        _lowerCAmelCase			(  __snake_case  : NDArray[floataa] ,							__snake_case  : NDArray[floataa] ,							__snake_case  : float = 10**-1			)     ->     bool:
     __A						: NDArray[floataa]      =       cross(__snake_case ,							__snake_case			)
     __A						: float      =       sum(__snake_case			)
     return abs(__snake_case			) < eps


if __name__ == "__main__":
  # Test to check if it works
  lowercase__    :      List[Any]						=    array(
      [
          polar_force(718.4, 1_80 - 30),
          polar_force(879.54, 45),
          polar_force(1_00, -90),
      ]
  )

  lowercase__    :      NDArray[floataa]						=    array([[0, 0], [0, 0], [0, 0]])

  assert in_static_equilibrium(forces, location)

  # Problem 1 in image_data/2D_problems.jpg
  lowercase__    :      Dict						=    array(
      [
          polar_force(30 * 9.81, 15),
          polar_force(2_15, 1_80 - 45),
          polar_force(2_64, 90 - 30),
      ]
  )

  lowercase__    :      Any						=    array([[0, 0], [0, 0], [0, 0]])

  assert in_static_equilibrium(forces, location)

  # Problem in image_data/2D_problems_1.jpg
  lowercase__    :      Optional[int]						=    array([[0, -20_00], [0, -12_00], [0, 1_56_00], [0, -1_24_00]])

  lowercase__    :      Optional[int]						=    array([[0, 0], [6, 0], [10, 0], [12, 0]])

  assert in_static_equilibrium(forces, location)

  import doctest

  doctest.testmod()