





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


   @property
   def  SCREAMING_SNAKE_CASE_							(					self    :       Union[str, Any] )->     str:





     """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  SCREAMING_SNAKE_CASE_							(					self    :       Dict )->     Dict:





     """simple docstring"""







     lowercase__			    =						self.dummy_uncond_unet
     lowercase__			    =						PNDMScheduler()

     lowercase__			    =						PNDMPipeline(unet=a    ,  scheduler=a )
     pndm.to(a )
     pndm.set_progress_bar_config(disable=a )

     lowercase__			    =						torch.manual_seed(0 )
     lowercase__			    =						pndm(generator=a    ,  num_inference_steps=20    ,  output_type='numpy' ).images

     lowercase__			    =						torch.manual_seed(0 )
     lowercase__			    =						pndm(generator=a    ,  num_inference_steps=20    ,  output_type='numpy'    ,  return_dict=a )[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([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        SCREAMING_SNAKE_CASE     (unittest.TestCase   ):


   def  SCREAMING_SNAKE_CASE_							(					self    :       Tuple )->     Optional[Any]:





     """simple docstring"""







     lowercase__			    =						'google/ddpm-cifar10-32'

     lowercase__			    =						UNetaDModel.from_pretrained(a )
     lowercase__			    =						PNDMScheduler()

     lowercase__			    =						PNDMPipeline(unet=a    ,  scheduler=a )
     pndm.to(a )
     pndm.set_progress_bar_config(disable=a )
     lowercase__			    =						torch.manual_seed(0 )
     lowercase__			    =						pndm(generator=a    ,  output_type='numpy' ).images

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

     assert image.shape == (1, 32, 32, 3)
     lowercase__			    =						np.array([0.1564, 0.14645, 0.1406, 0.14715, 0.12425, 0.14045, 0.13115, 0.12175, 0.125] )

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









def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	)       ->     bool:
  if not isinstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	):
    raise ValueError('Input series is not valid, valid series - [2, 4, 6]'	)
  if len(_SCREAMING_SNAKE_CASE	) == 0:
    raise ValueError('Input list must be a non empty list'	)
  if len(_SCREAMING_SNAKE_CASE	) == 1:
    return True
  lowercase__			    =						series[1] - series[0]
  for index in range(len(_SCREAMING_SNAKE_CASE	) - 1	):
    if series[index + 1] - series[index] != common_diff:
      return False
  return True




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	)       ->     float:
  if not isinstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	):
    raise ValueError('Input series is not valid, valid series - [2, 4, 6]'	)
  if len(_SCREAMING_SNAKE_CASE	) == 0:
    raise ValueError('Input list must be a non empty list'	)
  lowercase__			    =						0
  for val in series:
    answer += val
  return answer / len(_SCREAMING_SNAKE_CASE	)


if __name__ == "__main__":
      import doctest

      doctest.testmod()


