


'''simple docstring'''

import unittest

import numpy as np
import torch

from diffusers import DDIMPipeline, DDIMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, slow, torch_device

from ..pipeline_params import UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS, UNCONDITIONAL_IMAGE_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()
class   __lowerCAmelCase						(lowercase_  ,     unittest.TestCase     ):





      '''simple docstring'''






      lowerCAmelCase__					:     Optional[int]  					=							DDIMPipeline
      lowerCAmelCase__					:     Tuple  					=							UNCONDITIONAL_IMAGE_GENERATION_PARAMS
      lowerCAmelCase__					:     int  					=							PipelineTesterMixin.required_optional_params - {
          """num_images_per_prompt""",
          """latents""",
          """callback""",
          """callback_steps""",
      }
      lowerCAmelCase__					:     Any  					=							UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS
      lowerCAmelCase__					:     int  					=							False



      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''')   ,						)
             lowercase__      			= DDIMScheduler()
             lowercase__      			= {'''unet''': unet, '''scheduler''': scheduler}
             return components



      def       UpperCamelCase__		(self    :    Dict   ,						UpperCamelCase    :    Any   ,						UpperCamelCase    :    str=0 ):

             '''simple docstring'''







             if str(UpperCamelCase ).startswith('''mps''' ):
                    lowercase__      			= torch.manual_seed(UpperCamelCase )
             else:
                    lowercase__      			= torch.Generator(device=UpperCamelCase ).manual_seed(UpperCamelCase )
             lowercase__      			= {
                 '''batch_size''': 1,
                 '''generator''': generator,
                 '''num_inference_steps''': 2,
                 '''output_type''': '''numpy''',
             }
             return inputs



      def       UpperCamelCase__		(self    :    Union[str, Any] ):

             '''simple docstring'''







             lowercase__      			= '''cpu'''

             lowercase__      			= self.get_dummy_components()
             lowercase__      			= self.pipeline_class(**UpperCamelCase )
             pipe.to(UpperCamelCase )
             pipe.set_progress_bar_config(disable=UpperCamelCase )

             lowercase__      			= self.get_dummy_inputs(UpperCamelCase )
             lowercase__      			= pipe(**UpperCamelCase ).images
             lowercase__      			= image[0, -3:, -3:, -1]

             self.assertEqual(image.shape   ,						(1, 32, 32, 3) )
             lowercase__      			= np.array(
                 [1.0_00E00, 5.7_17E-01, 4.7_17E-01, 1.0_00E00, 0.0_00E00, 1.0_00E00, 3.0_00E-04, 0.0_00E00, 9.0_00E-04] )
             lowercase__      			= np.abs(image_slice.flatten() - expected_slice ).max()
             self.assertLessEqual(UpperCamelCase   ,						1E-3 )



      def       UpperCamelCase__		(self    :    Dict ):

             '''simple docstring'''







             super().test_dict_tuple_outputs_equivalent(expected_max_difference=3E-3 )



      def       UpperCamelCase__		(self    :    int ):

             '''simple docstring'''







             super().test_save_load_local(expected_max_difference=3E-3 )



      def       UpperCamelCase__		(self    :    List[str] ):

             '''simple docstring'''







             super().test_save_load_optional_components(expected_max_difference=3E-3 )






      def       UpperCamelCase__		(self    :    List[Any] ):

             '''simple docstring'''







             super().test_inference_batch_single_identical(expected_max_diff=3E-3 )






@slow
@require_torch_gpu
class   __lowerCAmelCase						(unittest.TestCase     ):





      '''simple docstring'''






      def       UpperCamelCase__		(self    :    List[Any] ):

             '''simple docstring'''







             lowercase__      			= '''google/ddpm-cifar10-32'''

             lowercase__      			= UNetaDModel.from_pretrained(UpperCamelCase )
             lowercase__      			= DDIMScheduler()

             lowercase__      			= DDIMPipeline(unet=UpperCamelCase   ,						scheduler=UpperCamelCase )
             ddim.to(UpperCamelCase )
             ddim.set_progress_bar_config(disable=UpperCamelCase )

             lowercase__      			= torch.manual_seed(0 )
             lowercase__      			= ddim(generator=UpperCamelCase   ,						eta=0.0   ,						output_type='''numpy''' ).images

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

             assert image.shape == (1, 32, 32, 3)
             lowercase__      			= np.array([0.17_23, 0.16_17, 0.16_00, 0.16_26, 0.14_97, 0.15_13, 0.15_05, 0.14_42, 0.14_53] )

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






      def       UpperCamelCase__		(self    :    Optional[Any] ):

             '''simple docstring'''







             lowercase__      			= '''google/ddpm-ema-bedroom-256'''

             lowercase__      			= UNetaDModel.from_pretrained(UpperCamelCase )
             lowercase__      			= DDIMScheduler.from_pretrained(UpperCamelCase )

             lowercase__      			= DDIMPipeline(unet=UpperCamelCase   ,						scheduler=UpperCamelCase )
             ddpm.to(UpperCamelCase )
             ddpm.set_progress_bar_config(disable=UpperCamelCase )

             lowercase__      			= torch.manual_seed(0 )
             lowercase__      			= ddpm(generator=UpperCamelCase   ,						output_type='''numpy''' ).images

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

             assert image.shape == (1, 256, 256, 3)
             lowercase__      			= np.array([0.00_60, 0.02_01, 0.03_44, 0.00_24, 0.00_18, 0.00_02, 0.00_22, 0.00_00, 0.00_69] )

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








'''simple docstring'''






def 				UpperCamelCase_			(    A__					:   int					):
  '''simple docstring'''





  lowerCAmelCase_			:      Union[str, Any]			=   (1 + 24 * n) ** 0.5
  return ((1 + root) / 6) % 1 == 0







def 				UpperCamelCase_			(    A__					:   int = 50_00					):
  '''simple docstring'''





  lowerCAmelCase_			:      Optional[int]			=   [(i * (3 * i - 1)) // 2 for i in range(1							,    A__					)]
  for i, pentagonal_i in enumerate(A__					):
    for j in range(A__							,    len(A__					)					):
      lowerCAmelCase_			:      int			=   pentagonal_nums[j]
      lowerCAmelCase_			:      Union[str, Any]			=   pentagonal_i + pentagonal_j
      lowerCAmelCase_			:      List[Any]			=   pentagonal_j - pentagonal_i
      if is_pentagonal(A__					) and is_pentagonal(A__					):
        return b

  return -1


if __name__ == "__main__":
  print(F'''{solution() = }''')



