

'''simple docstring'''
import random
import unittest

import numpy as np
import torch

from diffusers import DDIMScheduler, LDMSuperResolutionPipeline, UNetaDModel, VQModel
from diffusers.utils import PIL_INTERPOLATION, floats_tensor, load_image, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch


enable_full_determinism()
class  _snake_case						(unittest.TestCase):






			@property
			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	int      =   1
				UpperCAmelCase_			:	List[str]      =   3
				UpperCAmelCase_			:	List[Any]      =   (32, 32)

				UpperCAmelCase_			:	Tuple      =   floats_tensor((batch_size, num_channels) + sizes       ,rng=random.Random(0			)			).to(_snake_case			)
				return image






			@property
			def 						UpperCamelCase__				(   self			):
				torch.manual_seed(0			)
				UpperCAmelCase_			:	Optional[int]      =   UNetaDModel(
				    block_out_channels=(32, 64)       ,layers_per_block=2       ,sample_size=32       ,in_channels=6       ,out_channels=3       ,down_block_types=("DownBlock2D", "AttnDownBlock2D")       ,up_block_types=("AttnUpBlock2D", "UpBlock2D")       ,)
				return model






			@property
			def 						UpperCamelCase__				(   self			):
				torch.manual_seed(0			)
				UpperCAmelCase_			:	Dict      =   VQModel(
				    block_out_channels=[32, 64]       ,in_channels=3       ,out_channels=3       ,down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]       ,up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]       ,latent_channels=3       ,)
				return model






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	int      =   "cpu"
				UpperCAmelCase_			:	Optional[int]      =   self.dummy_uncond_unet
				UpperCAmelCase_			:	Any      =   DDIMScheduler()
				UpperCAmelCase_			:	List[Any]      =   self.dummy_vq_model

				UpperCAmelCase_			:	str      =   LDMSuperResolutionPipeline(unet=_snake_case       ,vqvae=_snake_case       ,scheduler=_snake_case			)
				ldm.to(_snake_case			)
				ldm.set_progress_bar_config(disable=_snake_case			)

				UpperCAmelCase_			:	Dict      =   self.dummy_image.to(_snake_case			)

				UpperCAmelCase_			:	List[str]      =   torch.Generator(device=_snake_case			).manual_seed(0			)
				UpperCAmelCase_			:	Optional[Any]      =   ldm(image=_snake_case       ,generator=_snake_case       ,num_inference_steps=2       ,output_type="numpy"			).images

				UpperCAmelCase_			:	Dict      =   image[0, -3:, -3:, -1]

				assert image.shape == (1, 64, 64, 3)
				UpperCAmelCase_			:	int      =   np.array([0.8678, 0.8245, 0.6381, 0.6830, 0.4385, 0.5599, 0.4641, 0.6201, 0.5150]			)

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






			@unittest.skipIf(torch_device != "cuda"       ,"This test requires a GPU"			)
			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	Optional[Any]      =   self.dummy_uncond_unet
				UpperCAmelCase_			:	List[str]      =   DDIMScheduler()
				UpperCAmelCase_			:	Union[str, Any]      =   self.dummy_vq_model

				# put models in fp16
				UpperCAmelCase_			:	Any      =   unet.half()
				UpperCAmelCase_			:	int      =   vqvae.half()

				UpperCAmelCase_			:	Dict      =   LDMSuperResolutionPipeline(unet=_snake_case       ,vqvae=_snake_case       ,scheduler=_snake_case			)
				ldm.to(_snake_case			)
				ldm.set_progress_bar_config(disable=_snake_case			)

				UpperCAmelCase_			:	Optional[int]      =   self.dummy_image.to(_snake_case			)

				UpperCAmelCase_			:	Optional[Any]      =   ldm(_snake_case       ,num_inference_steps=2       ,output_type="numpy"			).images

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




@slow
@require_torch
class  _snake_case						(unittest.TestCase):






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	str      =   load_image(
				    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
				    "/vq_diffusion/teddy_bear_pool.png"			)
				UpperCAmelCase_			:	Dict      =   init_image.resize((64, 64)       ,resample=PIL_INTERPOLATION["lanczos"]			)

				UpperCAmelCase_			:	Optional[int]      =   LDMSuperResolutionPipeline.from_pretrained("duongna/ldm-super-resolution"       ,device_map="auto"			)
				ldm.set_progress_bar_config(disable=_snake_case			)

				UpperCAmelCase_			:	Any      =   torch.manual_seed(0			)
				UpperCAmelCase_			:	str      =   ldm(image=_snake_case       ,generator=_snake_case       ,num_inference_steps=20       ,output_type="numpy"			).images

				UpperCAmelCase_			:	str      =   image[0, -3:, -3:, -1]

				assert image.shape == (1, 2_56, 2_56, 3)
				UpperCAmelCase_			:	List[str]      =   np.array([0.7644, 0.7679, 0.7642, 0.7633, 0.7666, 0.7560, 0.7425, 0.7257, 0.6907]			)

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







'''simple docstring'''
from __future__ import annotations


def       a__    (  _SCREAMING_SNAKE_CASE					:    int							)			-> set[int]:


	"""simple docstring"""





	UpperCAmelCase_			:	Dict      =   {1}
	UpperCAmelCase_			:	int      =   [1]
	for _ in range(2     ,							depth + 1							):
		UpperCAmelCase_			:	Dict      =   [*previous_coefficients, 0]
		UpperCAmelCase_			:	Tuple      =   [0, *previous_coefficients]
		UpperCAmelCase_			:	Dict      =   []
		for x, y in zip(_SCREAMING_SNAKE_CASE     ,							_SCREAMING_SNAKE_CASE							):
			coefficients.add(x + y							)
			previous_coefficients.append(x + y							)
	return coefficients


def       a__    (  _SCREAMING_SNAKE_CASE					:    set[int]							)			-> set[int]:


	"""simple docstring"""





	UpperCAmelCase_			:	List[Any]      =   set()
	for number in unique_coefficients:
		UpperCAmelCase_			:	Tuple      =   2
		UpperCAmelCase_			:	Tuple      =   number
		while divisor**2 <= copy_number:
			UpperCAmelCase_			:	List[Any]      =   0
			while copy_number % divisor == 0:
				copy_number //= divisor
				multiplicity += 1
			if multiplicity >= 2:
				non_squarefrees.add(_SCREAMING_SNAKE_CASE							)
				break
			divisor += 1

	return unique_coefficients.difference(_SCREAMING_SNAKE_CASE							)


def       a__    (  _SCREAMING_SNAKE_CASE					:    int = 51							)			-> int:


	"""simple docstring"""





	UpperCAmelCase_			:	Optional[Any]      =   get_pascal_triangle_unique_coefficients(_SCREAMING_SNAKE_CASE							)
	UpperCAmelCase_			:	Union[str, Any]      =   get_squarefrees(_SCREAMING_SNAKE_CASE							)
	return sum(_SCREAMING_SNAKE_CASE							)


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




