





from __future__ import annotations

import matplotlib.pyplot as plt  # type: ignore
import numpy

# initial triangle of Koch snowflake
UpperCAmelCase_  							=				numpy.array([0, 0])
UpperCAmelCase_  							=				numpy.array([0.5, 0.866_0254])
UpperCAmelCase_  							=				numpy.array([1, 0])
UpperCAmelCase_  							=				[VECTOR_1, VECTOR_2, VECTOR_3, VECTOR_1]




def 	lowerCAmelCase_					(						__UpperCAmelCase:    list[numpy.ndarray]	,     __UpperCAmelCase:    int   )   ->			list[numpy.ndarray]:
    UpperCamelCase__							:       Optional[Any]      =   initial_vectors
    for _ in range(__UpperCAmelCase   ):
        UpperCamelCase__							:       Optional[int]      =   iteration_step(__UpperCAmelCase   )
    return vectors




def 	lowerCAmelCase_					(						__UpperCAmelCase:    list[numpy.ndarray]   )   ->			list[numpy.ndarray]:
    UpperCamelCase__							:       Tuple      =   []
    for i, start_vector in enumerate(vectors[:-1]   ):
        UpperCamelCase__							:       int      =   vectors[i + 1]
        new_vectors.append(__UpperCAmelCase   )
        UpperCamelCase__							:       Any      =   end_vector - start_vector
        new_vectors.append(start_vector + difference_vector / 3   )
        new_vectors.append(
            start_vector + difference_vector / 3 + rotate(difference_vector / 3	,     60   )   )
        new_vectors.append(start_vector + difference_vector * 2 / 3   )
    new_vectors.append(vectors[-1]   )
    return new_vectors




def 	lowerCAmelCase_					(						__UpperCAmelCase:    numpy.ndarray	,     __UpperCAmelCase:    float   )   ->			numpy.ndarray:
    UpperCamelCase__							:       Optional[int]      =   numpy.radians(__UpperCAmelCase   )
    UpperCamelCase__     ,UpperCamelCase__							:       Dict      =   numpy.cos(__UpperCAmelCase   ), numpy.sin(__UpperCAmelCase   )
    UpperCamelCase__							:       Any      =   numpy.array(((c, -s), (s, c))   )
    return numpy.dot(__UpperCAmelCase	,     __UpperCAmelCase   )




def 	lowerCAmelCase_					(						__UpperCAmelCase:    list[numpy.ndarray]   )   ->			None:
    UpperCamelCase__							:       Tuple      =   plt.gca()
    axes.set_aspect('''equal'''   )

    # matplotlib.pyplot.plot takes a list of all x-coordinates and a list of all
    # y-coordinates as inputs, which are constructed from the vector-list using
    # zip()
    UpperCamelCase__     ,UpperCamelCase__							:       str      =   zip(*__UpperCAmelCase   )
    plt.plot(__UpperCAmelCase	,     __UpperCAmelCase   )
    plt.show()


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  UpperCAmelCase_  							=				iterate(INITIAL_VECTORS, 5)
  plot(processed_vectors)








import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


UpperCAmelCase_  							=				False






class 					lowercase__ (			unittest.TestCase       ):

   '''simple docstring'''


   pass






@nightly
@require_torch_gpu
class 					lowercase__ (			unittest.TestCase       ):

   '''simple docstring'''


   def    UpperCamelCase__						(					self							)				->   Optional[Any]:






       """simple docstring"""
       # clean up the VRAM after each test
       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()




   def    UpperCamelCase__						(					self							)				->   List[Any]:






       """simple docstring"""
       UpperCamelCase__							:       Dict      =   VersatileDiffusionTextToImagePipeline.from_pretrained('''shi-labs/versatile-diffusion'''							)
       # remove text_unet
       pipe.remove_unused_weights()
       pipe.to(__magic_name__							)
       pipe.set_progress_bar_config(disable=__magic_name__							)

       UpperCamelCase__							:       int      =   '''A painting of a squirrel eating a burger '''
       UpperCamelCase__							:       str      =   torch.manual_seed(0							)
       UpperCamelCase__							:       int      =   pipe(
           prompt=__magic_name__,	generator=__magic_name__,	guidance_scale=7.5,	num_inference_steps=2,	output_type='''numpy'''							).images

       with tempfile.TemporaryDirectory() as tmpdirname:
           pipe.save_pretrained(__magic_name__							)
           UpperCamelCase__							:       Union[str, Any]      =   VersatileDiffusionTextToImagePipeline.from_pretrained(__magic_name__							)
       pipe.to(__magic_name__							)
       pipe.set_progress_bar_config(disable=__magic_name__							)

       UpperCamelCase__							:       Optional[Any]      =   generator.manual_seed(0							)
       UpperCamelCase__							:       str      =   pipe(
           prompt=__magic_name__,	generator=__magic_name__,	guidance_scale=7.5,	num_inference_steps=2,	output_type='''numpy'''							).images

       assert np.abs(image - new_image							).sum() < 1E-5, "Models don't have the same forward pass"




   def    UpperCamelCase__						(					self							)				->   Any:






       """simple docstring"""
       UpperCamelCase__							:       str      =   VersatileDiffusionTextToImagePipeline.from_pretrained(
           '''shi-labs/versatile-diffusion''',	torch_dtype=torch.floataa							)
       pipe.to(__magic_name__							)
       pipe.set_progress_bar_config(disable=__magic_name__							)

       UpperCamelCase__							:       Optional[int]      =   '''A painting of a squirrel eating a burger '''
       UpperCamelCase__							:       str      =   torch.manual_seed(0							)
       UpperCamelCase__							:       Optional[int]      =   pipe(
           prompt=__magic_name__,	generator=__magic_name__,	guidance_scale=7.5,	num_inference_steps=50,	output_type='''numpy'''							).images

       UpperCamelCase__							:       int      =   image[0, 253:256, 253:256, -1]

       assert image.shape == (1, 512, 512, 3)
       UpperCamelCase__							:       int      =   np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]							)

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

