





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  _SCREAMING_SNAKE_CASE(       unittest.TestCase  ):




       def    _UpperCamelCase					(						self							)      ->				Union[str, Any]:





             """simple docstring"""






             super().tearDown()
             gc.collect()
             torch.cuda.empty_cache()




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[str]		    =  StableDiffusionKDiffusionPipeline.from_pretrained('''CompVis/stable-diffusion-v1-4'''							)
             __SCREAMING_SNAKE_CASE       :List[str]		    =  sd_pipe.to(__lowerCamelCase							)
             sd_pipe.set_progress_bar_config(disable=__lowerCamelCase							)

             sd_pipe.set_scheduler('''sample_euler'''							)

             __SCREAMING_SNAKE_CASE       :int		    =  '''A painting of a squirrel eating a burger'''
             __SCREAMING_SNAKE_CASE       :List[str]		    =  torch.manual_seed(0							)
             __SCREAMING_SNAKE_CASE       :Tuple		    =  sd_pipe([prompt]		,generator=__lowerCamelCase		,guidance_scale=9.0		,num_inference_steps=20		,output_type='''np'''							)

             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  output.images

             __SCREAMING_SNAKE_CASE       :List[str]		    =  image[0, -3:, -3:, -1]

             assert image.shape == (1, 5_12, 5_12, 3)
             __SCREAMING_SNAKE_CASE       :List[str]		    =  np.array([0.0_4_4_7, 0.0_4_9_2, 0.0_4_6_8, 0.0_4_0_8, 0.0_3_8_3, 0.0_4_0_8, 0.0_3_5_4, 0.0_3_8_0, 0.0_3_3_9]							)

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




       def    _UpperCamelCase					(						self							)      ->				List[str]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :int		    =  StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''							)
             __SCREAMING_SNAKE_CASE       :List[str]		    =  sd_pipe.to(__lowerCamelCase							)
             sd_pipe.set_progress_bar_config(disable=__lowerCamelCase							)

             sd_pipe.set_scheduler('''sample_euler'''							)

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

             __SCREAMING_SNAKE_CASE       :int		    =  output.images

             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  image[0, -3:, -3:, -1]

             assert image.shape == (1, 5_12, 5_12, 3)
             __SCREAMING_SNAKE_CASE       :Tuple		    =  np.array([0.1_2_3_7, 0.1_3_2_0, 0.1_4_3_8, 0.1_3_5_9, 0.1_3_9_0, 0.1_1_3_2, 0.1_2_7_7, 0.1_1_7_5, 0.1_1_1_2]							)

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




       def    _UpperCamelCase					(						self							)      ->				Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Tuple		    =  StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''							)
             __SCREAMING_SNAKE_CASE       :Tuple		    =  sd_pipe.to(__lowerCamelCase							)
             sd_pipe.set_progress_bar_config(disable=__lowerCamelCase							)

             sd_pipe.set_scheduler('''sample_dpmpp_2m'''							)

             __SCREAMING_SNAKE_CASE       :str		    =  '''A painting of a squirrel eating a burger'''
             __SCREAMING_SNAKE_CASE       :List[str]		    =  torch.manual_seed(0							)
             __SCREAMING_SNAKE_CASE       :Dict		    =  sd_pipe(
                 [prompt]		,generator=__lowerCamelCase		,guidance_scale=7.5		,num_inference_steps=15		,output_type='''np'''		,use_karras_sigmas=__lowerCamelCase		,)

             __SCREAMING_SNAKE_CASE       :Tuple		    =  output.images

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

             assert image.shape == (1, 5_12, 5_12, 3)
             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  np.array(
                 [0.1_1_3_8_1_6_8_9, 0.1_2_1_1_2_9_2_1, 0.1_3_8_9_4_5_7, 0.1_2_5_4_9_6_0_6, 0.1_2_4_4_9_6_4, 0.1_0_8_3_1_5_1_7, 0.1_1_5_6_2_8_6_6, 0.1_0_8_6_7_8_1_6, 0.1_0_4_9_9_0_4_8]							)

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






"""simple docstring"""
import math
import unittest



def 					__lowerCamelCase       (							a_					:		int							)      ->				bool:
      assert isinstance(a_			,       a_							) and (
          number >= 0
      ), "'number' must been an int and positive"

      if 1 < number < 4:
            # 2 and 3 are primes
            return True
      elif number < 2 or number % 2 == 0 or number % 3 == 0:
            # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
            return False

      # All primes number are in format of 6k +/- 1
      for i in range(5			,       int(math.sqrt(a_							) + 1							)			,       6							):
            if number % i == 0 or number % (i + 2) == 0:
                  return False
      return True






class  _SCREAMING_SNAKE_CASE(       unittest.TestCase  ):




       def    _UpperCamelCase					(						self							)      ->				Union[str, Any]:





             """simple docstring"""






             self.assertTrue(is_prime(2							)							)
             self.assertTrue(is_prime(3							)							)
             self.assertTrue(is_prime(5							)							)
             self.assertTrue(is_prime(7							)							)
             self.assertTrue(is_prime(11							)							)
             self.assertTrue(is_prime(13							)							)
             self.assertTrue(is_prime(17							)							)
             self.assertTrue(is_prime(19							)							)
             self.assertTrue(is_prime(23							)							)
             self.assertTrue(is_prime(29							)							)




       def    _UpperCamelCase					(						self							)      ->				Tuple:





             """simple docstring"""






             with self.assertRaises(SCREAMING_SNAKE_CASE__							):
                   is_prime(-19							)
             self.assertFalse(
                 is_prime(0							)		,'''Zero doesn\'t have any positive factors, primes must have exactly two.'''		,)
             self.assertFalse(
                 is_prime(1							)		,'''One only has 1 positive factor, primes must have exactly two.'''		,)
             self.assertFalse(is_prime(2 * 2							)							)
             self.assertFalse(is_prime(2 * 3							)							)
             self.assertFalse(is_prime(3 * 3							)							)
             self.assertFalse(is_prime(3 * 5							)							)
             self.assertFalse(is_prime(3 * 5 * 7							)							)


if __name__ == "__main__":
  unittest.main()