






import unittest

import numpy as np
import torch

from diffusers import PNDMPipeline, PNDMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()




class     _lowerCAmelCase(	unittest.TestCase ):





       """simple docstring"""







       @property
       def       _a   ( self							):
         torch.manual_seed(0							)
         UpperCamelCase_: Dict   				=    UNetaDModel(
             block_out_channels=(3_2, 6_4)  ,      layers_per_block=2  ,      sample_size=3_2  ,      in_channels=3  ,      out_channels=3  ,      down_block_types=('DownBlock2D', 'AttnDownBlock2D')  ,      up_block_types=('AttnUpBlock2D', 'UpBlock2D')  ,      )
         return model





       def       _a   ( self							):
         UpperCamelCase_: Tuple   				=    self.dummy_uncond_unet
         UpperCamelCase_: int   				=    PNDMScheduler()

         UpperCamelCase_: Any   				=    PNDMPipeline(unet=a_  ,      scheduler=a_							)
         pndm.to(a_							)
         pndm.set_progress_bar_config(disable=a_							)

         UpperCamelCase_: Union[str, Any]   				=    torch.manual_seed(0							)
         UpperCamelCase_: Dict   				=    pndm(generator=a_  ,      num_inference_steps=2_0  ,      output_type='numpy'							).images

         UpperCamelCase_: Optional[int]   				=    torch.manual_seed(0							)
         UpperCamelCase_: Dict   				=    pndm(generator=a_  ,      num_inference_steps=2_0  ,      output_type='numpy'  ,      return_dict=a_							)[0]

         UpperCamelCase_: str   				=    image[0, -3:, -3:, -1]
         UpperCamelCase_: List[Any]   				=    image_from_tuple[0, -3:, -3:, -1]

         assert image.shape == (1, 3_2, 3_2, 3)
         UpperCamelCase_: List[Any]   				=    np.array([1.0, 1.0, 0.0, 1.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     _lowerCAmelCase(	unittest.TestCase ):





       """simple docstring"""







       def       _a   ( self							):
         UpperCamelCase_: List[Any]   				=    'google/ddpm-cifar10-32'

         UpperCamelCase_: List[str]   				=    UNetaDModel.from_pretrained(a_							)
         UpperCamelCase_: Tuple   				=    PNDMScheduler()

         UpperCamelCase_: List[str]   				=    PNDMPipeline(unet=a_  ,      scheduler=a_							)
         pndm.to(a_							)
         pndm.set_progress_bar_config(disable=a_							)
         UpperCamelCase_: Union[str, Any]   				=    torch.manual_seed(0							)
         UpperCamelCase_: Any   				=    pndm(generator=a_  ,      output_type='numpy'							).images

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

         assert image.shape == (1, 3_2, 3_2, 3)
         UpperCamelCase_: int   				=    np.array([0.1_5_6_4, 0.1_4_6_4_5, 0.1_4_0_6, 0.1_4_7_1_5, 0.1_2_4_2_5, 0.1_4_0_4_5, 0.1_3_1_1_5, 0.1_2_1_7_5, 0.1_2_5]							)

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











def   snake_case (UpperCAmelCase__     ,   UpperCAmelCase__  )	->    int:
  while b:
    UpperCamelCase_				,UpperCamelCase_: int   				=    b, a % b
  return a

def   snake_case (UpperCAmelCase__     ,   UpperCAmelCase__  )	->    int:
  return a if b == 0 else euclidean_gcd_recursive(UpperCAmelCase__     ,   a % b  )

def   snake_case ()	->    int:
  print(F'''euclidean_gcd(3, 5) = {euclidean_gcd(3     ,   5  )}'''  )
  print(F'''euclidean_gcd(5, 3) = {euclidean_gcd(5     ,   3  )}'''  )
  print(F'''euclidean_gcd(1, 3) = {euclidean_gcd(1     ,   3  )}'''  )
  print(F'''euclidean_gcd(3, 6) = {euclidean_gcd(3     ,   6  )}'''  )
  print(F'''euclidean_gcd(6, 3) = {euclidean_gcd(6     ,   3  )}'''  )

  print(F'''euclidean_gcd_recursive(3, 5) = {euclidean_gcd_recursive(3     ,   5  )}'''  )
  print(F'''euclidean_gcd_recursive(5, 3) = {euclidean_gcd_recursive(5     ,   3  )}'''  )
  print(F'''euclidean_gcd_recursive(1, 3) = {euclidean_gcd_recursive(1     ,   3  )}'''  )
  print(F'''euclidean_gcd_recursive(3, 6) = {euclidean_gcd_recursive(3     ,   6  )}'''  )
  print(F'''euclidean_gcd_recursive(6, 3) = {euclidean_gcd_recursive(6     ,   3  )}'''  )


if __name__ == "__main__":
   main()