

import os
import string
import sys


_UpperCamelCase 			=		1 << 8

_UpperCamelCase 			=		{
    "tab": ord("\t"),
    "newline": ord("\r"),
    "esc": 27,
    "up": 65 + ARROW_KEY_FLAG,
    "down": 66 + ARROW_KEY_FLAG,
    "right": 67 + ARROW_KEY_FLAG,
    "left": 68 + ARROW_KEY_FLAG,
    "mod_int": 91,
    "undefined": sys.maxsize,
    "interrupt": 3,
    "insert": 50,
    "delete": 51,
    "pg_up": 53,
    "pg_down": 54,
}

_UpperCamelCase 			=		KEYMAP["up"]
_UpperCamelCase 			=		KEYMAP["left"]

if sys.platform == "win32":
 _UpperCamelCase 			=		[]
 _UpperCamelCase 			=		{
     B"\xe0H": KEYMAP["up"] - ARROW_KEY_FLAG,
     B"\x00H": KEYMAP["up"] - ARROW_KEY_FLAG,
     B"\xe0P": KEYMAP["down"] - ARROW_KEY_FLAG,
     B"\x00P": KEYMAP["down"] - ARROW_KEY_FLAG,
     B"\xe0M": KEYMAP["right"] - ARROW_KEY_FLAG,
     B"\x00M": KEYMAP["right"] - ARROW_KEY_FLAG,
     B"\xe0K": KEYMAP["left"] - ARROW_KEY_FLAG,
     B"\x00K": KEYMAP["left"] - ARROW_KEY_FLAG,
 }

for i in range(10):
 _UpperCamelCase 			=		ord(str(i))







def 		_lowercase (     ):
      if os.name == "nt":
            import msvcrt

            __lowerCAmelCase					:						Tuple					=					'''mbcs'''
            # Flush the keyboard buffer
            while msvcrt.kbhit():
                  msvcrt.getch()
            if len(lowercase__						) == 0:
                  # Read the keystroke
                  __lowerCAmelCase					:						str					=					msvcrt.getch()

                  # If it is a prefix char, get second part
                  if ch in (b"\x00", b"\xe0"):
                        __lowerCAmelCase					:						List[str]					=					ch + msvcrt.getch()
                        # Translate actual Win chars to bullet char types
                        try:
                              __lowerCAmelCase					:						Union[str, Any]					=					chr(WIN_KEYMAP[cha]						)
                              WIN_CH_BUFFER.append(chr(KEYMAP['''mod_int''']						)						)
                              WIN_CH_BUFFER.append(lowercase__						)
                              if ord(lowercase__						) in (
                                  KEYMAP["insert"] - 1 << 9,
                                  KEYMAP["delete"] - 1 << 9,
                                  KEYMAP["pg_up"] - 1 << 9,
                                  KEYMAP["pg_down"] - 1 << 9,
                              ):
                                    WIN_CH_BUFFER.append(chr(1_2_6						)						)
                              __lowerCAmelCase					:						str					=					chr(KEYMAP['''esc''']						)
                        except KeyError:
                              __lowerCAmelCase					:						List[str]					=					cha[1]
                  else:
                        __lowerCAmelCase					:						Union[str, Any]					=					ch.decode(lowercase__						)
            else:
                  __lowerCAmelCase					:						Optional[Any]					=					WIN_CH_BUFFER.pop(0						)
      elif os.name == "posix":
            import termios
            import tty

            __lowerCAmelCase					:						Optional[int]					=					sys.stdin.fileno()
            __lowerCAmelCase					:						Tuple					=					termios.tcgetattr(lowercase__						)
            try:
                  tty.setraw(lowercase__						)
                  __lowerCAmelCase					:						int					=					sys.stdin.read(1						)
            finally:
                  termios.tcsetattr(lowercase__   ,	termios.TCSADRAIN   ,	lowercase__						)
      return ch







def 		_lowercase (     ):
      __lowerCAmelCase					:						Tuple					=					get_raw_chars()
      if ord(lowercase__						) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
            return char

      elif ord(lowercase__						) == KEYMAP["esc"]:
            __lowerCAmelCase					:						Tuple					=					get_raw_chars()
            if ord(lowercase__						) == KEYMAP["mod_int"]:
                  __lowerCAmelCase					:						int					=					get_raw_chars()
                  if ord(lowercase__						) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(lowercase__						) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
                        return chr(ord(lowercase__						) + ARROW_KEY_FLAG						)
                  else:
                        return KEYMAP["undefined"]
            else:
                  return get_raw_chars()

      else:
            if char in string.printable:
                  return char
            else:
                  return KEYMAP["undefined"]





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   __lowercase      (unittest.TestCase ):
 @property
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       torch.manual_seed(0					)
       __lowerCAmelCase					:						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					)					->int:



       '''simple docstring'''





       __lowerCAmelCase					:						List[str]					=					self.dummy_uncond_unet
       __lowerCAmelCase					:						Any					=					PNDMScheduler()

       __lowerCAmelCase					:						Dict					=					PNDMPipeline(unet=A_      ,							scheduler=A_					)
       pndm.to(A_					)
       pndm.set_progress_bar_config(disable=A_					)

       __lowerCAmelCase					:						Optional[Any]					=					torch.manual_seed(0					)
       __lowerCAmelCase					:						Any					=					pndm(generator=A_      ,							num_inference_steps=20      ,							output_type='''numpy'''					).images

       __lowerCAmelCase					:						Optional[Any]					=					torch.manual_seed(0					)
       __lowerCAmelCase					:						List[Any]					=					pndm(generator=A_      ,							num_inference_steps=20      ,							output_type='''numpy'''      ,							return_dict=A_					)[0]

       __lowerCAmelCase					:						Tuple					=					image[0, -3:, -3:, -1]
       __lowerCAmelCase					:						Optional[Any]					=					image_from_tuple[0, -3:, -3:, -1]

       assert image.shape == (1, 32, 32, 3)
       __lowerCAmelCase					:						int					=					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   __lowercase      (unittest.TestCase ):
 def 	UpperCamelCase__  (							self					)					->Optional[Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						Optional[int]					=					'''google/ddpm-cifar10-32'''

       __lowerCAmelCase					:						Union[str, Any]					=					UNetaDModel.from_pretrained(A_					)
       __lowerCAmelCase					:						int					=					PNDMScheduler()

       __lowerCAmelCase					:						Any					=					PNDMPipeline(unet=A_      ,							scheduler=A_					)
       pndm.to(A_					)
       pndm.set_progress_bar_config(disable=A_					)
       __lowerCAmelCase					:						Tuple					=					torch.manual_seed(0					)
       __lowerCAmelCase					:						Any					=					pndm(generator=A_      ,							output_type='''numpy'''					).images

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

       assert image.shape == (1, 32, 32, 3)
       __lowerCAmelCase					:						List[Any]					=					np.array([0.1_564, 0.14_645, 0.1_406, 0.14_715, 0.12_425, 0.14_045, 0.13_115, 0.12_175, 0.125]					)

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


