






import math
import unittest





def        _snake_case   (_snake_case				:       int)					->	bool:
   assert isinstance(_snake_case      ,    _snake_case) 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(_snake_case) + 1)      ,    6):
      if number % i == 0 or number % (i + 2) == 0:
         return False
   return True






class 					SCREAMING_SNAKE_CASE_  (       unittest.TestCase ):
       """simple docstring"""


       def 				UpperCamelCase__						(				self	: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	:Dict):



          """simple docstring"""

          with self.assertRaises(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()










import unittest

import numpy as np
import torch

from diffusers import ScoreSdeVePipeline, ScoreSdeVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()






class 					SCREAMING_SNAKE_CASE_  (       unittest.TestCase ):
       """simple docstring"""


       @property
       def 				UpperCamelCase__						(				self	:Optional[int]):



          """simple docstring"""

          torch.manual_seed(0)
          _lowercase              =UNetaDModel(
              block_out_channels=(32, 64),      layers_per_block=2,      sample_size=32,      in_channels=3,      out_channels=3,      down_block_types=('DownBlock2D', 'AttnDownBlock2D'),      up_block_types=('AttnUpBlock2D', 'UpBlock2D'),      )
          return model





       def 				UpperCamelCase__						(				self	:str):



          """simple docstring"""

          _lowercase              =self.dummy_uncond_unet
          _lowercase              =ScoreSdeVeScheduler()

          _lowercase              =ScoreSdeVePipeline(unet=snake_case,      scheduler=snake_case)
          sde_ve.to(snake_case)
          sde_ve.set_progress_bar_config(disable=snake_case)

          _lowercase              =torch.manual_seed(0)
          _lowercase              =sde_ve(num_inference_steps=2,      output_type='numpy',      generator=snake_case).images

          _lowercase              =torch.manual_seed(0)
          _lowercase              =sde_ve(num_inference_steps=2,      output_type='numpy',      generator=snake_case,      return_dict=snake_case)[
              0
          ]

          _lowercase              =image[0, -3:, -3:, -1]
          _lowercase              =image_from_tuple[0, -3:, -3:, -1]

          assert image.shape == (1, 32, 32, 3)
          _lowercase              =np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0])

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






@slow
@require_torch
class 					SCREAMING_SNAKE_CASE_  (       unittest.TestCase ):
       """simple docstring"""


       def 				UpperCamelCase__						(				self	:int):



          """simple docstring"""

          _lowercase              ='google/ncsnpp-church-256'
          _lowercase              =UNetaDModel.from_pretrained(snake_case)

          _lowercase              =ScoreSdeVeScheduler.from_pretrained(snake_case)

          _lowercase              =ScoreSdeVePipeline(unet=snake_case,      scheduler=snake_case)
          sde_ve.to(snake_case)
          sde_ve.set_progress_bar_config(disable=snake_case)

          _lowercase              =torch.manual_seed(0)
          _lowercase              =sde_ve(num_inference_steps=10,      output_type='numpy',      generator=snake_case).images

          _lowercase              =image[0, -3:, -3:, -1]

          assert image.shape == (1, 256, 256, 3)

          _lowercase              =np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0])

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


