

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






					"""simple docstring"""



					@property
					def  __lowerCAmelCase				( self    :       Any	):
						lowerCAmelCase__			:		Optional[Any]						       =			1
						lowerCAmelCase__			:		Tuple						       =			3
						lowerCAmelCase__			:		List[str]						       =			(3_2, 3_2)

						lowerCAmelCase__			:		Dict						       =			floats_tensor((batch_size, num_channels) + sizes     ,rng=random.Random(0	)	).to(lowercase_	)
						return image







					@property
					def  __lowerCAmelCase				( self    :       str	):
						torch.manual_seed(0	)
						lowerCAmelCase__			:		List[Any]						       =			UNetaDModel(
						    block_out_channels=(3_2, 6_4)     ,layers_per_block=2     ,sample_size=3_2     ,in_channels=6     ,out_channels=3     ,down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')     ,up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')     ,)
						return model







					@property
					def  __lowerCAmelCase				( self    :       str	):
						torch.manual_seed(0	)
						lowerCAmelCase__			:		Union[str, Any]						       =			VQModel(
						    block_out_channels=[3_2, 6_4]     ,in_channels=3     ,out_channels=3     ,down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']     ,up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']     ,latent_channels=3     ,)
						return model







					def  __lowerCAmelCase				( self    :       List[Any]	):
						lowerCAmelCase__			:		str						       =			'''cpu'''
						lowerCAmelCase__			:		List[str]						       =			self.dummy_uncond_unet
						lowerCAmelCase__			:		List[Any]						       =			DDIMScheduler()
						lowerCAmelCase__			:		List[str]						       =			self.dummy_vq_model

						lowerCAmelCase__			:		Tuple						       =			LDMSuperResolutionPipeline(unet=lowercase_     ,vqvae=lowercase_     ,scheduler=lowercase_	)
						ldm.to(lowercase_	)
						ldm.set_progress_bar_config(disable=lowercase_	)

						lowerCAmelCase__			:		Dict						       =			self.dummy_image.to(lowercase_	)

						lowerCAmelCase__			:		str						       =			torch.Generator(device=lowercase_	).manual_seed(0	)
						lowerCAmelCase__			:		List[str]						       =			ldm(image=lowercase_     ,generator=lowercase_     ,num_inference_steps=2     ,output_type='''numpy'''	).images

						lowerCAmelCase__			:		int						       =			image[0, -3:, -3:, -1]

						assert image.shape == (1, 6_4, 6_4, 3)
						lowerCAmelCase__			:		Dict						       =			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  __lowerCAmelCase				( self    :       str	):
						lowerCAmelCase__			:		Optional[Any]						       =			self.dummy_uncond_unet
						lowerCAmelCase__			:		Union[str, Any]						       =			DDIMScheduler()
						lowerCAmelCase__			:		List[str]						       =			self.dummy_vq_model

						# put models in fp16
						lowerCAmelCase__			:		List[Any]						       =			unet.half()
						lowerCAmelCase__			:		List[str]						       =			vqvae.half()

						lowerCAmelCase__			:		str						       =			LDMSuperResolutionPipeline(unet=lowercase_     ,vqvae=lowercase_     ,scheduler=lowercase_	)
						ldm.to(lowercase_	)
						ldm.set_progress_bar_config(disable=lowercase_	)

						lowerCAmelCase__			:		Dict						       =			self.dummy_image.to(lowercase_	)

						lowerCAmelCase__			:		str						       =			ldm(lowercase_     ,num_inference_steps=2     ,output_type='''numpy'''	).images

						assert image.shape == (1, 6_4, 6_4, 3)







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






					"""simple docstring"""



					def  __lowerCAmelCase				( self    :       Dict	):
						lowerCAmelCase__			:		int						       =			load_image(
						    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
						    '''/vq_diffusion/teddy_bear_pool.png'''	)
						lowerCAmelCase__			:		List[str]						       =			init_image.resize((6_4, 6_4)     ,resample=PIL_INTERPOLATION['''lanczos''']	)

						lowerCAmelCase__			:		Any						       =			LDMSuperResolutionPipeline.from_pretrained('''duongna/ldm-super-resolution'''     ,device_map='''auto'''	)
						ldm.set_progress_bar_config(disable=lowercase_	)

						lowerCAmelCase__			:		int						       =			torch.manual_seed(0	)
						lowerCAmelCase__			:		Optional[int]						       =			ldm(image=lowercase_     ,generator=lowercase_     ,num_inference_steps=2_0     ,output_type='''numpy'''	).images

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

						assert image.shape == (1, 2_5_6, 2_5_6, 3)
						lowerCAmelCase__			:		Dict						       =			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"""





class        SCREAMING_SNAKE_CASE      :






					"""simple docstring"""



					def __init__( self    :       List[Any]	):
						lowerCAmelCase__			:		List[str]						       =			[0, 1]







					def  __lowerCAmelCase				( self    :       str     ,lowercase_    :       int	):
						if (difference := index - (len(self.sequence	) - 2)) >= 1:
							for _ in range(lowercase_	):
								self.sequence.append(self.sequence[-1] + self.sequence[-2]	)
						return self.sequence[:index]

def 						__SCREAMING_SNAKE_CASE						(   ):
	print(
	    '''Fibonacci Series Using Dynamic Programming\n'''		,  '''Enter the index of the Fibonacci number you want to calculate '''		,  '''in the prompt below. (To exit enter exit or Ctrl-C)\n'''		,  sep=''''''		,  )
	lowerCAmelCase__			:		Optional[int]						       =			Fibonacci()

	while True:
		lowerCAmelCase__			:		str						       =			input('''>> '''				)
		if prompt in {"exit", "quit"}:
			break

		try:
			lowerCAmelCase__			:		int						       =			int(A_				)
		except ValueError:
			print('''Enter a number or \'exit\''''				)
			continue

		print(fibonacci.get(A_				)				)


if __name__ == "__main__":
							main()




