





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

  @property
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        torch.manual_seed(0					)
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     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					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[Any]           =     self.dummy_uncond_unet
        SCREAMING_SNAKE_CASE_				:  List[str]           =     ScoreSdeVeScheduler()

        SCREAMING_SNAKE_CASE_				:  Any           =     ScoreSdeVePipeline(unet=lowerCamelCase_ ,					scheduler=lowerCamelCase_					)
        sde_ve.to(lowerCamelCase_					)
        sde_ve.set_progress_bar_config(disable=lowerCamelCase_					)

        SCREAMING_SNAKE_CASE_				:  Tuple           =     torch.manual_seed(0					)
        SCREAMING_SNAKE_CASE_				:  Tuple           =     sde_ve(num_inference_steps=2 ,					output_type='numpy' ,					generator=lowerCamelCase_					).images

        SCREAMING_SNAKE_CASE_				:  str           =     torch.manual_seed(0					)
        SCREAMING_SNAKE_CASE_				:  int           =     sde_ve(num_inference_steps=2 ,					output_type='numpy' ,					generator=lowerCamelCase_ ,					return_dict=lowerCamelCase_					)[
            0
        ]

        SCREAMING_SNAKE_CASE_				:  Dict           =     image[0, -3:, -3:, -1]
        SCREAMING_SNAKE_CASE_				:  str           =     image_from_tuple[0, -3:, -3:, -1]

        assert image.shape == (1, 32, 32, 3)
        SCREAMING_SNAKE_CASE_				:  Any           =     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  _A		(  unittest.TestCase):

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     """google/ncsnpp-church-256"""
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     UNetaDModel.from_pretrained(lowerCamelCase_					)

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     ScoreSdeVeScheduler.from_pretrained(lowerCamelCase_					)

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     ScoreSdeVePipeline(unet=lowerCamelCase_ ,					scheduler=lowerCamelCase_					)
        sde_ve.to(lowerCamelCase_					)
        sde_ve.set_progress_bar_config(disable=lowerCamelCase_					)

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     torch.manual_seed(0					)
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     sde_ve(num_inference_steps=10 ,					output_type='numpy' ,					generator=lowerCamelCase_					).images

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

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

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     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









def    A_  (							a					,   a  ):

      """simple docstring"""



      return int((input_a, input_a).count(0  ) != 0  )

def    A_  (							):

      """simple docstring"""



      assert nand_gate(0					,   0  ) == 1
      assert nand_gate(0					,   1  ) == 1
      assert nand_gate(1					,   0  ) == 1
      assert nand_gate(1					,   1  ) == 0


if __name__ == "__main__":
    print(nand_gate(0, 0))
    print(nand_gate(0, 1))
    print(nand_gate(1, 0))
    print(nand_gate(1, 1))






