



import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin
@skip_mps
class 				_snake_case			(					_snake_case    ,	_snake_case    ,	unittest.TestCase):
				UpperCamelCase__				:					Optional[Any]     		=IFImgaImgSuperResolutionPipeline
				UpperCamelCase__				:					int     		=TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
				UpperCamelCase__				:					List[str]     		=TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({"""original_image"""})
				UpperCamelCase__				:					str     		=PipelineTesterMixin.required_optional_params - {"""latents"""}




				def 							A__      (						self					:						Tuple						):
							return self._get_superresolution_dummy_components()




				def 							A__      (						self					:						Optional[int],					__lowercase					:						Any,					__lowercase					:						Union[str, Any]=0						):
							if str(lowerCAmelCase__						).startswith("mps"						):
										lowercase__					  =				torch.manual_seed(lowerCAmelCase__						)
							else:
										lowercase__					  =				torch.Generator(device=lowerCAmelCase__						).manual_seed(lowerCAmelCase__						)

							lowercase__					  =				floats_tensor((1, 3, 32, 32),					rng=random.Random(lowerCAmelCase__						)						).to(lowerCAmelCase__						)
							lowercase__					  =				floats_tensor((1, 3, 16, 16),					rng=random.Random(lowerCAmelCase__						)						).to(lowerCAmelCase__						)

							lowercase__					  =				{
							    "prompt": "A painting of a squirrel eating a burger",
							    "image": image,
							    "original_image": original_image,
							    "generator": generator,
							    "num_inference_steps": 2,
							    "output_type": "numpy",
							}

							return inputs




				@unittest.skipIf(
				    torch_device != "cuda" or not is_xformers_available(),					reason="XFormers attention is only available with CUDA and `xformers` installed",					)
				def 							A__      (						self					:						Optional[Any]						):
							self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3						)




				def 							A__      (						self					:						str						):
							self._test_save_load_optional_components()




				@unittest.skipIf(torch_device != "cuda",					reason="float16 requires CUDA"						)
				def 							A__      (						self					:						str						):
							# Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
							super().test_save_load_floataa(expected_max_diff=1e-1						)




				def 							A__      (						self					:						Any						):
							self._test_attention_slicing_forward_pass(expected_max_diff=1e-2						)




				def 							A__      (						self					:						Any						):
							self._test_save_load_local()




				def 							A__      (						self					:						Any						):
							self._test_inference_batch_single_identical(
							    expected_max_diff=1e-2,					)









def __lowerCAmelCase (     SCREAMING_SNAKE_CASE_  ):
			if upper_limit < 0:
						raise ValueError("Limit for the Catalan sequence must be ≥ 0"  )

			lowercase__					  =				[0] * (upper_limit + 1)

			# Base case: C(0) = C(1) = 1
			lowercase__					  =				1
			if upper_limit > 0:
						lowercase__					  =				1

			# Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i
			for i in range(2						,  upper_limit + 1  ):
						for j in range(SCREAMING_SNAKE_CASE_  ):
									catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1]

			return catalan_list


if __name__ == "__main__":
							print("""\n********* Catalan Numbers Using Dynamic Programming ************\n""")
							print("""\n*** Enter -1 at any time to quit ***""")
							print("""\nEnter the upper limit (≥ 0) for the Catalan number sequence: """, end="""""")
							try:
														while True:
																					lowercase_								=     int(input().strip())
																					if N < 0:
																												print("""\n********* Goodbye!! ************""")
																												break
																					else:
																												print(F'The Catalan numbers from 0 through {N} are:')
																												print(catalan_numbers(N))
																												print("""Try another upper limit for the sequence: """, end="""""")
							except (NameError, ValueError):
														print("""\n********* Invalid input, goodbye! ************\n""")

							import doctest

							doctest.testmod()




