





from __future__ import annotations

from itertools import permutations
from random import randint
from timeit import repeat


def 	UpperCamelCase__(       )->tuple[list[int], int]:
       A__											=						[randint(-10_00 ,     10_00  ) for i in range(10  )]
       A__											=						randint(-50_00 ,     50_00  )
       return (arr, r)


a__:      Optional[Any]									=		make_dataset()


def 	UpperCamelCase__(       UpperCamelCase__			:       list[int] ,     UpperCamelCase__			:       int  )->tuple[int, ...]:
       for triplet in permutations(UpperCamelCase__ ,     3  ):
              if sum(UpperCamelCase__  ) == target:
                     return tuple(sorted(UpperCamelCase__  )  )
       return (0, 0, 0)


def 	UpperCamelCase__(       UpperCamelCase__			:       list[int] ,     UpperCamelCase__			:       int  )->tuple[int, int, int]:
       arr.sort()
       A__											=						len(UpperCamelCase__  )
       for i in range(n - 1  ):
              A__					,	A__											=						i + 1, n - 1
              while left < right:
                     if arr[i] + arr[left] + arr[right] == target:
                            return (arr[i], arr[left], arr[right])
                     elif arr[i] + arr[left] + arr[right] < target:
                            left += 1
                     elif arr[i] + arr[left] + arr[right] > target:
                            right -= 1
       return (0, 0, 0)


def 	UpperCamelCase__(       )->tuple[float, float]:
       A__											=						'''
from __main__ import dataset, triplet_sum1, triplet_sum2
'''
       A__											=						'''
triplet_sum1(*dataset)
'''
       A__											=						'''
triplet_sum2(*dataset)
'''
       A__											=						repeat(setup=UpperCamelCase__ ,     stmt=UpperCamelCase__ ,     repeat=5 ,     number=1_00_00  )
       A__											=						repeat(setup=UpperCamelCase__ ,     stmt=UpperCamelCase__ ,     repeat=5 ,     number=1_00_00  )
       return (min(UpperCamelCase__  ), min(UpperCamelCase__  ))


if __name__ == "__main__":
       from doctest import testmod

       testmod()
       a__:      int									=		solution_times()
       print(F"The time for naive implementation is {times[0]}.")
       print(F"The time for optimized implementation is {times[1]}.")












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


a__:      List[str]									=		False




class     SCREAMING_SNAKE_CASE__ (						unittest.TestCase      ):
 pass




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



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



 def 				UpperCamelCase			(							self ):
        A__											=						VersatileDiffusionTextToImagePipeline.from_pretrained('''shi-labs/versatile-diffusion''' )
        # remove text_unet
        pipe.remove_unused_weights()
        pipe.to(__lowerCamelCase )
        pipe.set_progress_bar_config(disable=__lowerCamelCase )

        A__											=						'''A painting of a squirrel eating a burger '''
        A__											=						torch.manual_seed(0 )
        A__											=						pipe(
            prompt=__lowerCamelCase,generator=__lowerCamelCase,guidance_scale=7.5,num_inference_steps=2,output_type='''numpy''' ).images

        with tempfile.TemporaryDirectory() as tmpdirname:
               pipe.save_pretrained(__lowerCamelCase )
               A__											=						VersatileDiffusionTextToImagePipeline.from_pretrained(__lowerCamelCase )
        pipe.to(__lowerCamelCase )
        pipe.set_progress_bar_config(disable=__lowerCamelCase )

        A__											=						generator.manual_seed(0 )
        A__											=						pipe(
            prompt=__lowerCamelCase,generator=__lowerCamelCase,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 ):
        A__											=						VersatileDiffusionTextToImagePipeline.from_pretrained(
            '''shi-labs/versatile-diffusion''',torch_dtype=torch.floataa )
        pipe.to(__lowerCamelCase )
        pipe.set_progress_bar_config(disable=__lowerCamelCase )

        A__											=						'''A painting of a squirrel eating a burger '''
        A__											=						torch.manual_seed(0 )
        A__											=						pipe(
            prompt=__lowerCamelCase,generator=__lowerCamelCase,guidance_scale=7.5,num_inference_steps=50,output_type='''numpy''' ).images

        A__											=						image[0, 253:256, 253:256, -1]

        assert image.shape == (1, 512, 512, 3)
        A__											=						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





