



'''simple docstring'''






import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()

@slow
@require_torch_gpu
class 							a__(      unittest.TestCase			):







    def     lowercase_ (   self				:						int			):
      # clean up the VRAM after each test
      super().tearDown()
      gc.collect()
      torch.cuda.empty_cache()







    def     lowercase_ (   self				:						Optional[int]			):
      a		:      Optional[Any]       =  StableDiffusionKDiffusionPipeline.from_pretrained('CompVis/stable-diffusion-v1-4'			)
      a		:      str       =  sd_pipe.to(__snake_case			)
      sd_pipe.set_progress_bar_config(disable=__snake_case			)

      sd_pipe.set_scheduler('sample_euler'			)

      a		:      Optional[Any]       =  'A painting of a squirrel eating a burger'
      a		:      Optional[int]       =  torch.manual_seed(0			)
      a		:      int       =  sd_pipe([prompt]		,    generator=__snake_case		,    guidance_scale=9.0		,    num_inference_steps=20		,    output_type='np'			)

      a		:      int       =  output.images

      a		:      Tuple       =  image[0, -3:, -3:, -1]

      assert image.shape == (1, 5_12, 5_12, 3)
      a		:      str       =  np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]			)

      assert np.abs(image_slice.flatten() - expected_slice			).max() < 1e-2







    def     lowercase_ (   self				:						List[Any]			):
      a		:      str       =  StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'			)
      a		:      List[str]       =  sd_pipe.to(__snake_case			)
      sd_pipe.set_progress_bar_config(disable=__snake_case			)

      sd_pipe.set_scheduler('sample_euler'			)

      a		:      Dict       =  'A painting of a squirrel eating a burger'
      a		:      Any       =  torch.manual_seed(0			)
      a		:      Optional[Any]       =  sd_pipe([prompt]		,    generator=__snake_case		,    guidance_scale=9.0		,    num_inference_steps=20		,    output_type='np'			)

      a		:      Dict       =  output.images

      a		:      Tuple       =  image[0, -3:, -3:, -1]

      assert image.shape == (1, 5_12, 5_12, 3)
      a		:      List[Any]       =  np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]			)

      assert np.abs(image_slice.flatten() - expected_slice			).max() < 5e-1







    def     lowercase_ (   self				:						Dict			):
      a		:      str       =  StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base'			)
      a		:      Union[str, Any]       =  sd_pipe.to(__snake_case			)
      sd_pipe.set_progress_bar_config(disable=__snake_case			)

      sd_pipe.set_scheduler('sample_dpmpp_2m'			)

      a		:      Optional[Any]       =  'A painting of a squirrel eating a burger'
      a		:      int       =  torch.manual_seed(0			)
      a		:      Any       =  sd_pipe(
          [prompt]		,    generator=__snake_case		,    guidance_scale=7.5		,    num_inference_steps=15		,    output_type='np'		,    use_karras_sigmas=__snake_case		,    )

      a		:      List[str]       =  output.images

      a		:      Any       =  image[0, -3:, -3:, -1]

      assert image.shape == (1, 5_12, 5_12, 3)
      a		:      List[Any]       =  np.array(
          [0.11381689, 0.12112921, 0.1389457, 0.12549606, 0.1244964, 0.10831517, 0.11562866, 0.10867816, 0.10499048]			)

      assert np.abs(image_slice.flatten() - expected_slice			).max() < 1e-2




'''simple docstring'''






from math import factorial, pi
def    lowerCamelCase__ (		_A				,    _A = 30       ):

  if not isinstance(_A				,    (int, float)       ):
    raise ValueError('maclaurin_sin() requires either an int or float for theta'       )

  if not isinstance(_A				,    _A       ) or accuracy <= 0:
    raise ValueError('maclaurin_sin() requires a positive int for accuracy'       )

  a		:      List[Any]       =  float(_A       )
  a		:      Optional[int]       =  theta // (2 * pi)
  theta -= 2 * div * pi
  return sum(
      (-1) ** r * theta ** (2 * r + 1) / factorial(2 * r + 1       ) for r in range(_A       )       )
def    lowerCamelCase__ (		_A				,    _A = 30       ):

  if not isinstance(_A				,    (int, float)       ):
    raise ValueError('maclaurin_cos() requires either an int or float for theta'       )

  if not isinstance(_A				,    _A       ) or accuracy <= 0:
    raise ValueError('maclaurin_cos() requires a positive int for accuracy'       )

  a		:      List[str]       =  float(_A       )
  a		:      List[str]       =  theta // (2 * pi)
  theta -= 2 * div * pi
  return sum((-1) ** r * theta ** (2 * r) / factorial(2 * r       ) for r in range(_A       )       )


if __name__ == "__main__":
     import doctest

     doctest.testmod()

     print(maclaurin_sin(1_0))
     print(maclaurin_sin(-1_0))
     print(maclaurin_sin(1_0, 1_5))
     print(maclaurin_sin(-1_0, 1_5))

     print(maclaurin_cos(5))
     print(maclaurin_cos(-5))
     print(maclaurin_cos(1_0, 1_5))
     print(maclaurin_cos(-1_0, 1_5))