


import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
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    __lowercase  (       _a      ,     _a      ,     unittest.TestCase							):

							"""simple docstring"""


							SCREAMING_SNAKE_CASE   :					Optional[Any]        =						IFSuperResolutionPipeline
							SCREAMING_SNAKE_CASE   :					Dict        =						TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
							SCREAMING_SNAKE_CASE   :					str        =						TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
							SCREAMING_SNAKE_CASE   :					Optional[Any]        =						PipelineTesterMixin.required_optional_params - {'latents'}





							def 		__magic_name__			(    self	)->	Union[str, Any]:
											return self._get_superresolution_dummy_components()





							def 		__magic_name__			(    self				, A_				, A_=0	)->	Union[str, Any]:
											if str(A_	).startswith('mps'	):
															_SCREAMING_SNAKE_CASE      = torch.manual_seed(A_	)
											else:
															_SCREAMING_SNAKE_CASE      = torch.Generator(device=A_	).manual_seed(A_	)

											_SCREAMING_SNAKE_CASE      = floats_tensor((1, 3, 32, 32)				, rng=random.Random(A_	)	).to(A_	)

											_SCREAMING_SNAKE_CASE      = {
											    'prompt': 'A painting of a squirrel eating a burger',
											    'image': 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 		__magic_name__			(    self	)->	List[Any]:
											self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3	)





							def 		__magic_name__			(    self	)->	List[str]:
											self._test_save_load_optional_components()





							@unittest.skipIf(torch_device != 'cuda'				, reason='float16 requires CUDA'	)
							def 		__magic_name__			(    self	)->	Tuple:
											# 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 		__magic_name__			(    self	)->	List[str]:
											self._test_attention_slicing_forward_pass(expected_max_diff=1e-2	)





							def 		__magic_name__			(    self	)->	Tuple:
											self._test_save_load_local()





							def 		__magic_name__			(    self	)->	Tuple:
											self._test_inference_batch_single_identical(
											    expected_max_diff=1e-2				, )








from __future__ import annotations

from collections import Counter


def 				SCREAMING_SNAKE_CASE (     UpperCAmelCase__							):

				"""simple docstring"""






				_SCREAMING_SNAKE_CASE      = [True] * n
				_SCREAMING_SNAKE_CASE      = False
				_SCREAMING_SNAKE_CASE      = False
				_SCREAMING_SNAKE_CASE      = True

				for i in range(3   ,int(n**0.5 + 1							)   ,2							):
								_SCREAMING_SNAKE_CASE      = i * 2
								while index < n:
												_SCREAMING_SNAKE_CASE      = False
												_SCREAMING_SNAKE_CASE      = index + i

				_SCREAMING_SNAKE_CASE      = [2]

				for i in range(3   ,UpperCAmelCase__   ,2							):
								if is_prime[i]:
												primes.append(UpperCAmelCase__							)

				return primes


def 				SCREAMING_SNAKE_CASE (     UpperCAmelCase__							):

				"""simple docstring"""






				_SCREAMING_SNAKE_CASE      = str(UpperCAmelCase__							)
				_SCREAMING_SNAKE_CASE      = []
				_SCREAMING_SNAKE_CASE      = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

				for duplicate in Counter(UpperCAmelCase__							) - Counter(set(UpperCAmelCase__							)							):
								_SCREAMING_SNAKE_CASE      = [int(number_str.replace(UpperCAmelCase__   ,UpperCAmelCase__							)							) for digit in digits]
								replacements.append(UpperCAmelCase__							)

				return replacements


def 				SCREAMING_SNAKE_CASE (     UpperCAmelCase__ = 8							):

				"""simple docstring"""






				_SCREAMING_SNAKE_CASE      = set()

				# Filter primes with less than 3 replaceable digits
				_SCREAMING_SNAKE_CASE      = {
				    x for x in set(prime_sieve(100_0000							)							) if len(str(UpperCAmelCase__							)							) - len(set(str(UpperCAmelCase__							)							)							) >= 3
				}

				for prime in primes:
								if prime in numbers_checked:
												continue

								_SCREAMING_SNAKE_CASE      = digit_replacements(UpperCAmelCase__							)

								for family in replacements:
												numbers_checked.update(UpperCAmelCase__							)
												_SCREAMING_SNAKE_CASE      = primes.intersection(UpperCAmelCase__							)

												if len(UpperCAmelCase__							) != family_length:
																continue

												return min(UpperCAmelCase__							)

				return -1


if __name__ == "__main__":
							print(solution())
